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 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK 3 4 //. 5 // CHECK: @__start_sanmd_covered2 = extern_weak hidden global ptr 6 // CHECK: @__stop_sanmd_covered2 = extern_weak hidden global ptr 7 // CHECK: @__start_sanmd_atomics2 = extern_weak hidden global ptr 8 // CHECK: @__stop_sanmd_atomics2 = extern_weak hidden global ptr 9 // CHECK: @llvm.used = appending global [4 x ptr] [ptr @__sanitizer_metadata_covered2.module_ctor, ptr @__sanitizer_metadata_covered2.module_dtor, ptr @__sanitizer_metadata_atomics2.module_ctor, ptr @__sanitizer_metadata_atomics2.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_covered2.module_ctor, ptr @__sanitizer_metadata_covered2.module_ctor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics2.module_ctor, ptr @__sanitizer_metadata_atomics2.module_ctor }] 11 // CHECK: @llvm.global_dtors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered2.module_dtor, ptr @__sanitizer_metadata_covered2.module_dtor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics2.module_dtor, ptr @__sanitizer_metadata_atomics2.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 [[META2:![0-9]+]] { 16 // CHECK-NEXT: entry: 17 // CHECK-NEXT: ret void 18 // 19 __attribute__((noinline, not_tail_called)) void escape(const volatile void *p) { 20 static const volatile void *sink; 21 sink = p; 22 } 23 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 noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !pcsections [[META4:![0-9]+]] { 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 [[META11:![0-9]+]] 31 // CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]]) 32 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA12:![0-9]+]] 33 // CHECK-NEXT: ret i32 [[TMP0]] 34 // 35 int normal_function(int *x, int *y) { 36 __atomic_store_n(x, 1, __ATOMIC_RELAXED); 37 escape(&x); 38 return *y; 39 } 40 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 noundef readonly captures(none) [[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 [[TBAA12]] 50 // CHECK-NEXT: ret i32 [[TMP0]] 51 // 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; 56 } 57 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 noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] !pcsections [[META14:![0-9]+]] { 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 [[META11]] 65 // CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]]) 66 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA12]] 67 // CHECK-NEXT: ret i32 [[TMP0]] 68 // 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; 73 } 74 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 noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR3]] !pcsections [[META14]] { 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 [[META11]] 82 // CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]]) 83 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA12]] 84 // CHECK-NEXT: ret i32 [[TMP0]] 85 // 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; 90 } 91 //. 92 // CHECK: attributes #[[ATTR0]] = { 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 #[[ATTR1]] = { 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 #[[ATTR2]] = { 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 #[[ATTR3]] = { 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 #[[ATTR4:[0-9]+]] = { nounwind "target-features"="+cx8,+mmx,+sse,+sse2,+x87" } 97 //. 98 // CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} 99 // CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} 100 // CHECK: [[META2]] = !{!"sanmd_covered2!C", [[META3:![0-9]+]]} 101 // CHECK: [[META3]] = !{i64 0} 102 // CHECK: [[META4]] = !{!"sanmd_covered2!C", [[META5:![0-9]+]]} 103 // CHECK: [[META5]] = !{i64 3} 104 // CHECK: [[TBAA6]] = !{[[META7:![0-9]+]], [[META7]], i64 0} 105 // CHECK: [[META7]] = !{!"p1 int", [[META8:![0-9]+]], i64 0} 106 // CHECK: [[META8]] = !{!"any pointer", [[META9:![0-9]+]], i64 0} 107 // CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0} 108 // CHECK: [[META10]] = !{!"Simple C/C++ TBAA"} 109 // CHECK: [[META11]] = !{!"sanmd_atomics2!C"} 110 // CHECK: [[TBAA12]] = !{[[META13:![0-9]+]], [[META13]], i64 0} 111 // CHECK: [[META13]] = !{!"int", [[META9]], i64 0} 112 // CHECK: [[META14]] = !{!"sanmd_covered2!C", [[META15:![0-9]+]]} 113 // CHECK: [[META15]] = !{i64 2} 114 //. 115