|
| 1 | +// Verify ubsan doesn't emit checks for ignorelisted types |
| 2 | +// RUN: echo "[{unsigned-integer-overflow,signed-integer-overflow}]" > %t-int.ignorelist |
| 3 | +// RUN: echo "type:int" >> %t-int.ignorelist |
| 4 | +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-int.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=INT |
| 5 | + |
| 6 | +// RUN: echo "type:int" > %t-nosection.ignorelist |
| 7 | +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-nosection.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=INT |
| 8 | + |
| 9 | +// RUN: echo "type:int=allow" > %t-allow-same-as-no-category.ignorelist |
| 10 | +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-allow-same-as-no-category.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=INT |
| 11 | + |
| 12 | +// RUN: echo "[{unsigned-integer-overflow,signed-integer-overflow}]" > %t-myty.ignorelist |
| 13 | +// RUN: echo "type:*" >> %t-myty.ignorelist |
| 14 | +// RUN: echo "type:myty=skip" >> %t-myty.ignorelist |
| 15 | +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-myty.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=MYTY |
| 16 | + |
| 17 | +// RUN: echo "[{implicit-signed-integer-truncation,implicit-unsigned-integer-truncation}]" > %t-trunc.ignorelist |
| 18 | +// RUN: echo "type:char" >> %t-trunc.ignorelist |
| 19 | +// RUN: echo "type:unsigned char" >> %t-trunc.ignorelist |
| 20 | +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=implicit-signed-integer-truncation,implicit-unsigned-integer-truncation -fsanitize-ignorelist=%t-trunc.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=TRUNC |
| 21 | + |
1 | 22 | // Verify ubsan vptr does not check down-casts on ignorelisted types.
|
2 | 23 | // RUN: echo "type:_ZTI3Foo" > %t-type.ignorelist
|
3 |
| -// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=vptr -fsanitize-recover=vptr -emit-llvm %s -o - | FileCheck %s --check-prefix=DEFAULT |
4 |
| -// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=vptr -fsanitize-recover=vptr -fsanitize-ignorelist=%t-type.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=TYPE |
| 24 | +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=vptr -fsanitize-recover=vptr -emit-llvm %s -o - | FileCheck %s --check-prefix=VPTR |
| 25 | +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=vptr -fsanitize-recover=vptr -fsanitize-ignorelist=%t-type.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=VPTR-TYPE |
5 | 26 |
|
6 | 27 | class Bar {
|
7 |
| -public: |
8 |
| - virtual ~Bar() {} |
| 28 | + public: |
| 29 | + virtual ~Bar() {} |
9 | 30 | };
|
10 | 31 | class Foo : public Bar {};
|
11 | 32 |
|
12 | 33 | Bar bar;
|
13 | 34 |
|
14 |
| -// DEFAULT: @_Z7checkmev |
15 |
| -// TYPE: @_Z7checkmev |
| 35 | +// VPTR: @_Z7checkmev |
| 36 | +// VPTR-TYPE: @_Z7checkmev |
16 | 37 | void checkme() {
|
17 |
| -// DEFAULT: call void @__ubsan_handle_dynamic_type_cache_miss({{.*}} (ptr @bar to |
18 |
| -// TYPE-NOT: @__ubsan_handle_dynamic_type_cache_miss |
| 38 | + // VPTR: call void @__ubsan_handle_dynamic_type_cache_miss({{.*}} (ptr @bar to |
| 39 | + // VPTR-TYPE-NOT: @__ubsan_handle_dynamic_type_cache_miss |
19 | 40 | Foo* foo = static_cast<Foo*>(&bar); // down-casting
|
20 |
| -// DEFAULT: ret void |
21 |
| -// TYPE: ret void |
| 41 | + // VPTR: ret void |
| 42 | + // VPTR-TYPE: ret void |
22 | 43 | return;
|
23 | 44 | }
|
| 45 | + |
| 46 | +// INT-LABEL: ignore_int |
| 47 | +void ignore_int(int A, int B, unsigned C, unsigned D, long E) { |
| 48 | + // INT: llvm.uadd.with.overflow.i32 |
| 49 | + (void)(C+D); |
| 50 | + // INT-NOT: llvm.sadd.with.overflow.i32 |
| 51 | + (void)(A+B); |
| 52 | + // INT: llvm.sadd.with.overflow.i64 |
| 53 | + (void)(++E); |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +typedef unsigned long myty; |
| 58 | +typedef myty derivative; |
| 59 | +// INT-LABEL: ignore_all_except_myty |
| 60 | +// MYTY-LABEL: ignore_all_except_myty |
| 61 | +void ignore_all_except_myty(myty A, myty B, int C, unsigned D, derivative E) { |
| 62 | + // MYTY-NOT: llvm.sadd.with.overflow.i32 |
| 63 | + (void)(++C); |
| 64 | + |
| 65 | + // MYTY-NOT: llvm.uadd.with.overflow.i32 |
| 66 | + (void)(D+D); |
| 67 | + |
| 68 | + // MYTY-NOT: llvm.umul.with.overflow.i64 |
| 69 | + (void)(E*2); |
| 70 | + |
| 71 | + // MYTY: llvm.uadd.with.overflow.i64 |
| 72 | + (void)(A+B); |
| 73 | +} |
| 74 | + |
| 75 | +// INT-LABEL: truncation |
| 76 | +// MYTY-LABEL: truncation |
| 77 | +// TRUNC-LABEL: truncation |
| 78 | +void truncation(char A, int B, unsigned char C, short D) { |
| 79 | + // TRUNC-NOT: %handler.implicit_conversion |
| 80 | + A = B; |
| 81 | + // TRUNC-NOT: %handler.implicit_conversion |
| 82 | + A = C; |
| 83 | + // TRUNC-NOT: %handler.implicit_conversion |
| 84 | + C = B; |
| 85 | + |
| 86 | + // TRUNC: %handler.implicit_conversion |
| 87 | + D = B; |
| 88 | + |
| 89 | + (void)A; |
| 90 | + (void)D; |
| 91 | +} |
0 commit comments