brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.9 KiB · be52ea9 Raw
91 lines · cpp
1// RUN: echo "int extra_global;" > %t.extra-source.cpp2// RUN: echo "global:*ignorelisted_global*" > %t.ignorelist3// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=address -fsanitize-ignorelist=%t.ignorelist -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,GLOBS,ASAN4// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=kernel-address -fsanitize-ignorelist=%t.ignorelist -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,GLOBS,KASAN5// The ignorelist file uses regexps, so Windows path backslashes.6// RUN: echo "src:%s" | sed -e 's/\\/\\\\/g' > %t.ignorelist-src7// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=address -fsanitize-ignorelist=%t.ignorelist-src -emit-llvm -o - %s | FileCheck %s --check-prefix=IGNORELIST-SRC8// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=kernel-address -fsanitize-ignorelist=%t.ignorelist-src -emit-llvm -o - %s | FileCheck %s --check-prefix=IGNORELIST-SRC9 10int global;11int dyn_init_global = global;12int __attribute__((no_sanitize("address"))) attributed_global;13int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;14int ignorelisted_global;15extern int __attribute__((no_sanitize("address"))) external_global;16 17int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section18extern "C" {19int __special_global; // KASAN - ignore globals with __-prefix20}21 22void func() {23  static int static_var = 0;24  const char *literal = "Hello, world!";25  external_global = 1;26}27 28// GLOBS:     @{{.*}}extra_global{{.*}} ={{.*}} global29// GLOBS-NOT: no_sanitize_address30// GLOBS:     @{{.*}}global{{.*}} ={{.*}} global31// GLOBS-NOT: no_sanitize_address32// GLOBS:     @{{.*}}dyn_init_global{{.*}} ={{.*}} global {{.*}}, sanitize_address_dyninit33// GLOBS-NOT: no_sanitize_address34 35// GLOBS:     @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address36// GLOBS:     @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address37// GLOBS:     @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address38 39// ASAN:     @{{.*}}sectioned_global{{.*}} ={{.*}} global { i32, [28 x i8] }{{.*}}, align 3240// ASAN-NOT: no_sanitize_address41// ASAN:     @{{.*}}__special_global{{.*}} ={{.*}} global { i32, [28 x i8] }{{.*}}, align 3242// ASAN-NOT: no_sanitize_address43 44/// Note: No attribute is added by the IR pass, but the type didn't change, so45/// that checks our assertions that the globals didn't get instrumented.46// KASAN:    @{{.*}}sectioned_global{{.*}} ={{.*}} global i32 {{.*}}47// KASAN:    @{{.*}}__special_global{{.*}} ={{.*}} global i32 {{.*}}48 49// GLOBS:     @{{[^ ]*}}static_var{{[^ ]*}} ={{.*}} global {{.*}}50// GLOBS-NOT: no_sanitize_address51// GLOBS:     @{{.*}} = {{.*}}c"Hello, world!\00"52// GLOBS-NOT: no_sanitize_address53 54// GLOBS: @{{.*}}external_global{{.*}} ={{.*}} no_sanitize_address55 56/// Without -fasynchronous-unwind-tables, ctor and dtor get the uwtable attribute.57// CHECK-LABEL: define internal void @asan.module_ctor() #[[#ATTR:]] {58// ASAN-NEXT: call void @__asan_init59// ASAN-NEXT: call void @__asan_version_mismatch_check60// KASAN-NOT: call void @__asan_init61// KASAN-NOT: call void @__asan_version_mismatch_check62// ASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 7)63// KASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 5)64// CHECK-NEXT: ret void65 66// CHECK:      define internal void @asan.module_dtor() #[[#ATTR]] {67// CHECK-NEXT: call void @__asan_unregister_globals68// CHECK-NEXT: ret void69 70// CHECK: attributes #[[#ATTR]] = { nounwind71 72/// If -fasynchronous-unwind-tables, set the module flag "uwtable". ctor/dtor73/// will thus get the uwtable attribute.74// RUN: %clang_cc1 -emit-llvm -fsanitize=address -funwind-tables=2 -o - %s | FileCheck %s --check-prefixes=UWTABLE75// UWTABLE: define internal void @asan.module_dtor() #[[#ATTR:]] {76// UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable77// UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 2}78 79// IGNORELIST-SRC:     @{{.*}}extra_global{{.*}} ={{.*}} global80// IGNORELIST-SRC-NOT: no_sanitize_address81// IGNORELIST-SRC:     @{{.*}}global{{.*}} ={{.*}} global {{.*}} no_sanitize_address82// IGNORELIST-SRC:     @{{.*}}dyn_init_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address83// IGNORELIST-SRC:     @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address84// IGNORELIST-SRC:     @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address85// IGNORELIST-SRC:     @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address86// IGNORELIST-SRC:     @{{.*}}sectioned_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address87// IGNORELIST-SRC:     @{{.*}}__special_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address88// IGNORELIST-SRC:     @{{.*}}static_var{{.*}} ={{.*}} global {{.*}} no_sanitize_address89// IGNORELIST-SRC:     @{{.*}} ={{.*}} c"Hello, world!\00"{{.*}} no_sanitize_address90// IGNORELIST-SRC:     @{{.*}}external_global{{.*}} ={{.*}} no_sanitize_address91