1 // RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \ 2 // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \ 3 // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s 4 5 // RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \ 6 // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \ 7 // RUN: -fsanitize=memtag-globals -emit-llvm -o - %s | \ 8 // RUN: FileCheck %s --check-prefix=IGNORELIST 9 10 int global; 11 int __attribute__((no_sanitize("memtag"))) attributed_global; 12 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global; 13 int ignorelisted_global; 14 15 void func() { 16 static int static_var = 0; 17 const char *literal = "Hello, world!"; 18 } 19 20 // CHECK: @{{.*}}extra_global{{.*}} = 21 // CHECK-NOT: no_sanitize_memtag 22 // CHECK: @{{.*}}global{{.*}} = 23 // CHECK-NOT: no_sanitize_memtag 24 // CHECK: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag 25 // CHECK: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag 26 // CHECK: @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag 27 // CHECK: @{{.*}}static_var{{.*}} = 28 // CHECK-NOT: no_sanitize_memtag 29 // CHECK: @{{.*}} = {{.*}} c"Hello, world!\00" 30 // CHECK-NOT: no_sanitize_memtag 31 32 // CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[DISABLE_INSTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]} 33 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false} 34 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5} 35 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, i1 false} 36 // CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}memtag-globals.cpp", i32 10, i32 5} 37 // CHECK: ![[ATTR_GLOBAL]] = !{{{.*attributed_global.*}}, null, null, i1 false, i1 true} 38 // CHECK: ![[DISABLE_INSTR_GLOBAL]] = !{{{.*disable_instrumentation_global.*}}, null, null, i1 false, i1 true} 39 // CHECK: ![[IGNORELISTED_GLOBAL]] = !{{{.*ignorelisted_global.*}}, null, null, i1 false, i1 true} 40 // CHECK: ![[STATIC_VAR]] = !{{{.*}} ![[STATIC_LOC:[0-9]+]], !"static_var", i1 false, i1 false} 41 // CHECK: ![[STATIC_LOC]] = !{!"{{.*}}memtag-globals.cpp", i32 16, i32 14} 42 // CHECK: ![[LITERAL]] = !{{{.*}} ![[LITERAL_LOC:[0-9]+]], !"<string literal>", i1 false, i1 false} 43 // CHECK: ![[LITERAL_LOC]] = !{!"{{.*}}memtag-globals.cpp", i32 17, i32 25} 44 45 // IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} global 46 // IGNORELIST-NOT: no_sanitize_memtag 47 // IGNORELIST: @{{.*}}global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag 48 // IGNORELIST: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag 49 // IGNORELIST: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag 50 // IGNORELIST: @{{.*}}ignorelisted_globa{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag 51 // IGNORELIST: @{{.*}}static_var{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag 52 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}, no_sanitize_memtag 53 54 // IGNORELIST: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[DISABLE_INSTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]} 55 // IGNORELIST: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false} 56 // IGNORELIST: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5} 57 // IGNORELIST: ![[GLOBAL]] = !{{{.*}} null, null, i1 false, i1 true} 58 // IGNORELIST: ![[ATTR_GLOBAL]] = !{{{.*attributed_global.*}}, null, null, i1 false, i1 true} 59 // IGNORELIST: ![[DISABLE_INSTR_GLOBAL]] = !{{{.*disable_instrumentation_global.*}}, null, null, i1 false, i1 true} 60 // IGNORELIST: ![[IGNORELISTED_GLOBAL]] = !{{{.*ignorelisted_global.*}}, null, null, i1 false, i1 true} 61 // IGNORELIST: ![[STATIC_VAR]] = !{{{.*}} null, null, i1 false, i1 true} 62 // IGNORELIST: ![[LITERAL]] = !{{{.*}} null, null, i1 false, i1 true} 63