Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / sanitize-metadata-nosanitize.c
blob488714fe6078e51fe0fec149e0989f015f33ce8a
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --check-globals --version 2
2 // RUN: %clang_cc1 -O -fexperimental-sanitize-metadata=covered -fexperimental-sanitize-metadata=atomics -fexperimental-sanitize-metadata=uar -triple x86_64-gnu-linux -x c -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK
4 //.
5 // CHECK: @__start_sanmd_covered = extern_weak hidden global ptr
6 // CHECK: @__stop_sanmd_covered = extern_weak hidden global ptr
7 // CHECK: @__start_sanmd_atomics = extern_weak hidden global ptr
8 // CHECK: @__stop_sanmd_atomics = extern_weak hidden global ptr
9 // CHECK: @llvm.used = appending global [4 x ptr] [ptr @__sanitizer_metadata_covered.module_ctor, ptr @__sanitizer_metadata_covered.module_dtor, ptr @__sanitizer_metadata_atomics.module_ctor, ptr @__sanitizer_metadata_atomics.module_dtor], section "llvm.metadata"
10 // CHECK: @llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered.module_ctor, ptr @__sanitizer_metadata_covered.module_ctor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics.module_ctor, ptr @__sanitizer_metadata_atomics.module_ctor }]
11 // CHECK: @llvm.global_dtors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered.module_dtor, ptr @__sanitizer_metadata_covered.module_dtor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics.module_dtor, ptr @__sanitizer_metadata_atomics.module_dtor }]
12 //.
13 // CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none)
14 // CHECK-LABEL: define dso_local void @escape
15 // CHECK-SAME: (ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !pcsections !2 {
16 // CHECK-NEXT: entry:
17 // CHECK-NEXT: ret void
19 __attribute__((noinline, not_tail_called)) void escape(const volatile void *p) {
20 static const volatile void *sink;
21 sink = p;
24 // CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
25 // CHECK-LABEL: define dso_local i32 @normal_function
26 // CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !pcsections !4 {
27 // CHECK-NEXT: entry:
28 // CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
29 // CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6:![0-9]+]]
30 // CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections !10
31 // CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]])
32 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11:![0-9]+]]
33 // CHECK-NEXT: ret i32 [[TMP0]]
35 int normal_function(int *x, int *y) {
36 __atomic_store_n(x, 1, __ATOMIC_RELAXED);
37 escape(&x);
38 return *y;
41 // CHECK: Function Attrs: disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
42 // CHECK-LABEL: define dso_local i32 @test_disable_sanitize_instrumentation
43 // CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] {
44 // CHECK-NEXT: entry:
45 // CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
46 // CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6]]
47 // CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4
48 // CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]])
49 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11]]
50 // CHECK-NEXT: ret i32 [[TMP0]]
52 __attribute__((disable_sanitizer_instrumentation)) int test_disable_sanitize_instrumentation(int *x, int *y) {
53 __atomic_store_n(x, 1, __ATOMIC_RELAXED);
54 escape(&x);
55 return *y;
58 // CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
59 // CHECK-LABEL: define dso_local i32 @test_no_sanitize_thread
60 // CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] !pcsections !13 {
61 // CHECK-NEXT: entry:
62 // CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
63 // CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6]]
64 // CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections !10
65 // CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]])
66 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11]]
67 // CHECK-NEXT: ret i32 [[TMP0]]
69 __attribute__((no_sanitize("thread"))) int test_no_sanitize_thread(int *x, int *y) {
70 __atomic_store_n(x, 1, __ATOMIC_RELAXED);
71 escape(&x);
72 return *y;
75 // CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
76 // CHECK-LABEL: define dso_local i32 @test_no_sanitize_all
77 // CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR3]] !pcsections !13 {
78 // CHECK-NEXT: entry:
79 // CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
80 // CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6]]
81 // CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections !10
82 // CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]])
83 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11]]
84 // CHECK-NEXT: ret i32 [[TMP0]]
86 __attribute__((no_sanitize("all"))) int test_no_sanitize_all(int *x, int *y) {
87 __atomic_store_n(x, 1, __ATOMIC_RELAXED);
88 escape(&x);
89 return *y;
91 //.
92 // CHECK: attributes #0 = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
93 // CHECK: attributes #1 = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
94 // CHECK: attributes #2 = { disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
95 // CHECK: attributes #3 = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "no_sanitize_thread" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
96 // CHECK: attributes #4 = { nounwind }
97 //.
98 // CHECK: !2 = !{!"sanmd_covered!C", !3}
99 // CHECK: !3 = !{i64 0}
100 // CHECK: !4 = !{!"sanmd_covered!C", !5}
101 // CHECK: !5 = !{i64 3}
102 // CHECK: !6 = !{!7, !7, i64 0}
103 // CHECK: !7 = !{!"any pointer", !8, i64 0}
104 // CHECK: !8 = !{!"omnipotent char", !9, i64 0}
105 // CHECK: !9 = !{!"Simple C/C++ TBAA"}
106 // CHECK: !10 = !{!"sanmd_atomics!C"}
107 // CHECK: !11 = !{!12, !12, i64 0}
108 // CHECK: !12 = !{!"int", !8, i64 0}
109 // CHECK: !13 = !{!"sanmd_covered!C", !14}
110 // CHECK: !14 = !{i64 2}