diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2015-05-15 18:33:32 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2015-05-15 18:33:32 +0000 |
commit | 915df9968b6524d1858884ae5694812b6831a1ac (patch) | |
tree | b7e541fa454fbea85db502afff25cb5d2533bd43 /clang/test | |
parent | 25e2500ac866365beaf747e2b0c926b9db4f721b (diff) | |
download | bcm5719-llvm-915df9968b6524d1858884ae5694812b6831a1ac.tar.gz bcm5719-llvm-915df9968b6524d1858884ae5694812b6831a1ac.zip |
Implement no_sanitize attribute.
Differential Revision: http://reviews.llvm.org/D9631
llvm-svn: 237463
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGen/address-safety-attr.cpp | 59 | ||||
-rw-r--r-- | clang/test/CodeGen/sanitize-thread-attr.cpp | 6 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/cfi-vcall.cpp | 22 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/no-sanitize.m | 8 | ||||
-rw-r--r-- | clang/test/SemaCXX/attr-no-sanitize.cpp | 29 |
5 files changed, 111 insertions, 13 deletions
diff --git a/clang/test/CodeGen/address-safety-attr.cpp b/clang/test/CodeGen/address-safety-attr.cpp index d23b3ff0e48..402d6bad909 100644 --- a/clang/test/CodeGen/address-safety-attr.cpp +++ b/clang/test/CodeGen/address-safety-attr.cpp @@ -3,14 +3,14 @@ int DefinedInDifferentFile(int *a); // RUN: echo "struct S { S(){} ~S(){} };" >> %t.extra-source.cpp // RUN: echo "S glob_array[5];" >> %t.extra-source.cpp -// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -include %t.extra-source.cpp | FileCheck -check-prefix=WITHOUT %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -include %t.extra-source.cpp -fsanitize=address | FileCheck -check-prefix=ASAN %s +// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin -emit-llvm -o - %s -include %t.extra-source.cpp | FileCheck -check-prefix=WITHOUT %s +// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin -emit-llvm -o - %s -include %t.extra-source.cpp -fsanitize=address | FileCheck -check-prefix=ASAN %s // RUN: echo "fun:*BlacklistedFunction*" > %t.func.blacklist -// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -include %t.extra-source.cpp -fsanitize=address -fsanitize-blacklist=%t.func.blacklist | FileCheck -check-prefix=BLFUNC %s +// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin -emit-llvm -o - %s -include %t.extra-source.cpp -fsanitize=address -fsanitize-blacklist=%t.func.blacklist | FileCheck -check-prefix=BLFUNC %s // RUN: echo "src:%s" > %t.file.blacklist -// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -include %t.extra-source.cpp -fsanitize=address -fsanitize-blacklist=%t.file.blacklist | FileCheck -check-prefix=BLFILE %s +// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin -emit-llvm -o - %s -include %t.extra-source.cpp -fsanitize=address -fsanitize-blacklist=%t.file.blacklist | FileCheck -check-prefix=BLFILE %s // FIXME: %t.file.blacklist is like "src:x:\path\to\clang\test\CodeGen\address-safety-attr.cpp" // REQUIRES: shell @@ -52,6 +52,36 @@ __attribute__((no_sanitize_address)) int NoAddressSafety2(int *a); int NoAddressSafety2(int *a) { return *a; } +// WITHOUT: NoAddressSafety3{{.*}}) [[NOATTR]] +// BLFILE: NoAddressSafety3{{.*}}) [[NOATTR]] +// BLFUNC: NoAddressSafety3{{.*}}) [[NOATTR]] +// ASAN: NoAddressSafety3{{.*}}) [[NOATTR]] +[[gnu::no_sanitize_address]] +int NoAddressSafety3(int *a) { return *a; } + +// WITHOUT: NoAddressSafety4{{.*}}) [[NOATTR]] +// BLFILE: NoAddressSafety4{{.*}}) [[NOATTR]] +// BLFUNC: NoAddressSafety4{{.*}}) [[NOATTR]] +// ASAN: NoAddressSafety4{{.*}}) [[NOATTR]] +[[gnu::no_sanitize_address]] +int NoAddressSafety4(int *a); +int NoAddressSafety4(int *a) { return *a; } + +// WITHOUT: NoAddressSafety5{{.*}}) [[NOATTR]] +// BLFILE: NoAddressSafety5{{.*}}) [[NOATTR]] +// BLFUNC: NoAddressSafety5{{.*}}) [[NOATTR]] +// ASAN: NoAddressSafety5{{.*}}) [[NOATTR]] +__attribute__((no_sanitize("address"))) +int NoAddressSafety5(int *a) { return *a; } + +// WITHOUT: NoAddressSafety6{{.*}}) [[NOATTR]] +// BLFILE: NoAddressSafety6{{.*}}) [[NOATTR]] +// BLFUNC: NoAddressSafety6{{.*}}) [[NOATTR]] +// ASAN: NoAddressSafety6{{.*}}) [[NOATTR]] +__attribute__((no_sanitize("address"))) +int NoAddressSafety6(int *a); +int NoAddressSafety6(int *a) { return *a; } + // WITHOUT: AddressSafetyOk{{.*}}) [[NOATTR]] // BLFILE: AddressSafetyOk{{.*}}) [[NOATTR]] // BLFUNC: AddressSafetyOk{{.*}}) [[WITH]] @@ -86,16 +116,25 @@ int GENERATE_NAME(Function)(int *a) { return *a; } template<int i> int TemplateAddressSafetyOk() { return i; } -// WITHOUT: TemplateNoAddressSafety{{.*}}) [[NOATTR]] -// BLFILE: TemplateNoAddressSafety{{.*}}) [[NOATTR]] -// BLFUNC: TemplateNoAddressSafety{{.*}}) [[NOATTR]] -// ASAN: TemplateNoAddressSafety{{.*}}) [[NOATTR]] +// WITHOUT: TemplateNoAddressSafety1{{.*}}) [[NOATTR]] +// BLFILE: TemplateNoAddressSafety1{{.*}}) [[NOATTR]] +// BLFUNC: TemplateNoAddressSafety1{{.*}}) [[NOATTR]] +// ASAN: TemplateNoAddressSafety1{{.*}}) [[NOATTR]] template<int i> __attribute__((no_sanitize_address)) -int TemplateNoAddressSafety() { return i; } +int TemplateNoAddressSafety1() { return i; } + +// WITHOUT: TemplateNoAddressSafety2{{.*}}) [[NOATTR]] +// BLFILE: TemplateNoAddressSafety2{{.*}}) [[NOATTR]] +// BLFUNC: TemplateNoAddressSafety2{{.*}}) [[NOATTR]] +// ASAN: TemplateNoAddressSafety2{{.*}}) [[NOATTR]] +template<int i> +__attribute__((no_sanitize("address"))) +int TemplateNoAddressSafety2() { return i; } int force_instance = TemplateAddressSafetyOk<42>() - + TemplateNoAddressSafety<42>(); + + TemplateNoAddressSafety1<42>() + + TemplateNoAddressSafety2<42>(); // Check that __cxx_global_var_init* get the sanitize_address attribute. int global1 = 0; diff --git a/clang/test/CodeGen/sanitize-thread-attr.cpp b/clang/test/CodeGen/sanitize-thread-attr.cpp index dae48e092cd..46cab4dbf92 100644 --- a/clang/test/CodeGen/sanitize-thread-attr.cpp +++ b/clang/test/CodeGen/sanitize-thread-attr.cpp @@ -22,6 +22,12 @@ __attribute__((no_sanitize_thread)) int NoTSAN2(int *a); int NoTSAN2(int *a) { return *a; } +// WITHOUT: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]] +// BL: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]] +// TSAN: NoTSAN3{{.*}}) [[NOATTR:#[0-9]+]] +__attribute__((no_sanitize("thread"))) +int NoTSAN3(int *a) { return *a; } + // WITHOUT: TSANOk{{.*}}) [[NOATTR]] // BL: TSANOk{{.*}}) [[NOATTR]] // TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]] diff --git a/clang/test/CodeGenCXX/cfi-vcall.cpp b/clang/test/CodeGenCXX/cfi-vcall.cpp index bfbbceaa1a3..b0f79d9ec0e 100644 --- a/clang/test/CodeGenCXX/cfi-vcall.cpp +++ b/clang/test/CodeGenCXX/cfi-vcall.cpp @@ -47,16 +47,32 @@ void af(A *a) { a->f(); } -// CHECK: define internal void @_Z2dfPN12_GLOBAL__N_11DE -void df(D *d) { +// CHECK: define internal void @_Z3df1PN12_GLOBAL__N_11DE +void df1(D *d) { // CHECK: {{%[^ ]*}} = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"[{{.*}}cfi-vcall.cpp]N12_GLOBAL__N_11DE") d->f(); } +// CHECK: define internal void @_Z3df2PN12_GLOBAL__N_11DE +__attribute__((no_sanitize("cfi"))) +void df2(D *d) { + // CHECK-NOT: call i1 @llvm.bitset.test + d->f(); +} + +// CHECK: define internal void @_Z3df3PN12_GLOBAL__N_11DE +__attribute__((no_sanitize("address"))) __attribute__((no_sanitize("cfi-vcall"))) +void df3(D *d) { + // CHECK-NOT: call i1 @llvm.bitset.test + d->f(); +} + D d; void foo() { - df(&d); + df1(&d); + df2(&d); + df3(&d); } // CHECK-DAG: !{!"1A", [3 x i8*]* @_ZTV1A, i64 16} diff --git a/clang/test/CodeGenObjC/no-sanitize.m b/clang/test/CodeGenObjC/no-sanitize.m new file mode 100644 index 00000000000..39f8575670d --- /dev/null +++ b/clang/test/CodeGenObjC/no-sanitize.m @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -emit-llvm -fsanitize=address -o - | FileCheck %s + +@interface I0 @end +@implementation I0 +// CHECK-NOT: sanitize_address +- (void) im0: (int) a0 __attribute__((no_sanitize("address"))) { +} +@end diff --git a/clang/test/SemaCXX/attr-no-sanitize.cpp b/clang/test/SemaCXX/attr-no-sanitize.cpp new file mode 100644 index 00000000000..120fa64587d --- /dev/null +++ b/clang/test/SemaCXX/attr-no-sanitize.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// RUN: not %clang_cc1 -std=c++11 -ast-dump %s 2>&1 | FileCheck --check-prefix=DUMP %s +// RUN: not %clang_cc1 -std=c++11 -ast-print %s 2>&1 | FileCheck --check-prefix=PRINT %s + +int v1 __attribute__((no_sanitize("address"))); // expected-error{{'no_sanitize' attribute only applies to functions and methods}} + +int f1() __attribute__((no_sanitize)); // expected-error{{'no_sanitize' attribute takes at least 1 argument}} + +int f2() __attribute__((no_sanitize(1))); // expected-error{{'no_sanitize' attribute requires a string}} + +// DUMP-LABEL: FunctionDecl {{.*}} f3 +// DUMP: NoSanitizeAttr {{.*}} address +// PRINT: int f3() __attribute__((no_sanitize("address"))) +int f3() __attribute__((no_sanitize("address"))); + +// DUMP-LABEL: FunctionDecl {{.*}} f4 +// DUMP: NoSanitizeAttr {{.*}} thread +// PRINT: int f4() {{\[\[}}clang::no_sanitize("thread")]] +[[clang::no_sanitize("thread")]] int f4(); + +// DUMP-LABEL: FunctionDecl {{.*}} f5 +// DUMP: NoSanitizeAttr {{.*}} address thread +// PRINT: int f5() __attribute__((no_sanitize("address", "thread"))) +int f5() __attribute__((no_sanitize("address", "thread"))); + +// DUMP-LABEL: FunctionDecl {{.*}} f6 +// DUMP: NoSanitizeAttr {{.*}} unknown +// PRINT: int f6() __attribute__((no_sanitize("unknown"))) +int f6() __attribute__((no_sanitize("unknown"))); // expected-warning{{unknown sanitizer 'unknown' ignored}} |