[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / check-for-sanitizer-feature.cpp
blob861b571f0efaa0eb44f53953f10e1a7df7da1a3a
1 // RUN: rm -rf %t.1 %t.2
2 // RUN: mkdir %t.1 %t.2
4 // Build and use an ASan-enabled module.
5 // RUN: %clang_cc1 -fsanitize=address -fmodules -fmodules-cache-path=%t.1 \
6 // RUN: -fmodule-map-file=%S/Inputs/check-for-sanitizer-feature/map \
7 // RUN: -I %S/Inputs/check-for-sanitizer-feature -verify %s
8 // RUN: ls %t.1 | count 2
10 // Force a module rebuild by disabling ASan.
11 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t.1 \
12 // RUN: -fmodule-map-file=%S/Inputs/check-for-sanitizer-feature/map \
13 // RUN: -I %S/Inputs/check-for-sanitizer-feature -verify %s
14 // RUN: ls %t.1 | count 3
16 // Enable ASan again: check that there is no import failure, and no rebuild.
17 // RUN: %clang_cc1 -fsanitize=address -fmodules -fmodules-cache-path=%t.1 \
18 // RUN: -fmodule-map-file=%S/Inputs/check-for-sanitizer-feature/map \
19 // RUN: -I %S/Inputs/check-for-sanitizer-feature -verify %s
20 // RUN: ls %t.1 | count 3
22 // Some sanitizers can not affect AST generation when enabled. Check that
23 // module rebuilds don't occur when these sanitizers are enabled.
25 // First, build without any sanitization.
26 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t.2 \
27 // RUN: -fmodule-map-file=%S/Inputs/check-for-sanitizer-feature/map \
28 // RUN: -I %S/Inputs/check-for-sanitizer-feature -verify %s
29 // RUN: ls %t.2 | count 2
31 // Next, build with sanitization, and check that a new module isn't built.
32 // RUN: %clang_cc1 -fsanitize=cfi-vcall,float-divide-by-zero,unsigned-integer-overflow,nullability-arg,null -fmodules \
33 // RUN: -fmodules-cache-path=%t.2 \
34 // RUN: -fmodule-map-file=%S/Inputs/check-for-sanitizer-feature/map \
35 // RUN: -I %S/Inputs/check-for-sanitizer-feature -verify %s
36 // RUN: ls %t.2 | count 2
38 // Finally, test that including enabled sanitizers in the module hash isn't
39 // required to ensure correctness of module imports.
41 // Emit a PCH with ASan enabled.
42 // RUN: %clang_cc1 -x c -fsanitize=address %S/Inputs/check-for-sanitizer-feature/check.h -emit-pch -o %t.asan_pch
44 // Import the PCH without ASan enabled (we expect an error).
45 // RUN: not %clang_cc1 -x c -include-pch %t.asan_pch %s -verify 2>&1 | FileCheck %s --check-prefix=PCH_MISMATCH
46 // PCH_MISMATCH: AST file '{{.*}}.asan_pch' was compiled with the target feature '-fsanitize=address' but the current translation unit is not
48 // Emit a PCH with UBSan enabled.
49 // RUN: %clang_cc1 -x c -fsanitize=null %S/Inputs/check-for-sanitizer-feature/check.h -emit-pch -o %t.ubsan_pch
51 // Import the PCH without UBSan enabled (should work just fine).
52 // RUN: %clang_cc1 -x c -include-pch %t.ubsan_pch %s -I %S/Inputs/check-for-sanitizer-feature -verify
54 #include "check.h"
56 #if __has_feature(address_sanitizer)
57 #if HAS_ASAN != 1
58 #error Module doesn't have the address_sanitizer feature, but main program does.
59 #endif
60 #else
61 #if HAS_ASAN != 0
62 #error Module has the address_sanitizer feature, but main program doesn't.
63 #endif
64 #endif
66 // expected-no-diagnostics