Files
TheRock/compiler/amd-llvm/clang/test/Analysis/ctu/reusable-pch.c
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

50 lines
2.1 KiB
C

// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// DEFINE: %{ctu_analysis} = %clang_analyze_cc1 \
// DEFINE: -analyzer-checker=core \
// DEFINE: -analyzer-config experimental-enable-naive-ctu-analysis=true \
// DEFINE: -analyzer-config ctu-dir=%t \
// DEFINE: -verify
// Step 1: Build PCH and defmap.
// RUN: %clang_cc1 -x c -emit-pch -fvalidate-ast-input-files-content -o %t/other.c.ast %t/other.c
// RUN: %clang_extdef_map %t/other.c -- -c -x c > %t/externalDefMap.tmp.txt
// RUN: sed -e 's| .*other\.c| other.c.ast|' %t/externalDefMap.tmp.txt > %t/externalDefMap.txt
// Step 2a: Run CTU using the PCH - the division by zero is found via inlining.
// RUN: %{ctu_analysis} %t/main.c
// Step 2b: Run with content validation - no difference.
// RUN: %{ctu_analysis} %t/main.c -fvalidate-ast-input-files-content
// Step 3: Advance mtime of the source from which PCH was built.
// RUN: %python -c "import os, sys, time; os.utime(sys.argv[1], (time.time() + 120, time.time() + 120))" %t/other.c
// Step 4a: Run CTU using the "stale" PCH, and it should still load it and find the division by zero bug.
// RUN: %{ctu_analysis} -fvalidate-ast-input-files-content %t/main.c
// Step 4b: Run without content validation: CTU import failure
// RUN: not %{ctu_analysis} %t/main.c 2>&1 | FileCheck %s
//--- main.c
// Without CTU, always_zero() has an unknown return value so no bug is found.
// With CTU, always_zero() is inlined and its return value (0) is known,
// exposing the division by zero.
// CHECK: fatal error: file '{{.*}}other.c' has been modified since the precompiled file '{{.*}}other.c.ast' was built
// CHECK: note: mtime changed from expected
// CHECK: note: earlier input file validation has covered only user files
// CHECK: import of an external symbol for CTU failed: Failed to load external AST source.
int always_zero(void);
void f(void) {
int x = always_zero();
(void)(1 / x); // expected-warning{{Division by zero}}
}
//--- other.c
int always_zero(void) { return 0; }