Skip to content

Commit 8eadd8b

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
2 parents 70965ef + bca3191 commit 8eadd8b

File tree

6 files changed

+263
-156
lines changed

6 files changed

+263
-156
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,8 @@ Sanitizers
12481248
by the compiler (for example,
12491249
``-fno-sanitize-merge=bool,enum,array-bounds,local-bounds``).
12501250

1251+
- ``-fsanitize=vptr`` is not included into ``-fsanitize=undefined``.
1252+
12511253
Python Binding Changes
12521254
----------------------
12531255
- Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``.

clang/docs/UndefinedBehaviorSanitizer.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,6 @@ Available checks are:
210210
(see ``-fsanitize=implicit-integer-conversion``).
211211
- ``-fsanitize=vla-bound``: A variable-length array whose bound
212212
does not evaluate to a positive value.
213-
- ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
214-
the wrong dynamic type, or that its lifetime has not begun or has ended.
215-
Incompatible with ``-fno-rtti``. Link must be performed by ``clang++``, not
216-
``clang``, to make sure C++-specific parts of the runtime library and C++
217-
standard libraries are present.
218213

219214
You can also use the following check groups:
220215
- ``-fsanitize=undefined``: All of the checks listed above other than
@@ -249,6 +244,11 @@ You can also use the following check groups:
249244
``nullability-assign``, and ``nullability-return``. While violating
250245
nullability does not have undefined behavior, it is often unintentional,
251246
so UBSan offers to catch it.
247+
- ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
248+
the wrong dynamic type, or that its lifetime has not begun or has ended.
249+
Incompatible with ``-fno-rtti``. Link must be performed by ``clang++``, not
250+
``clang``, to make sure C++-specific parts of the runtime library and C++
251+
standard libraries are present.
252252

253253
Volatile
254254
--------

clang/include/clang/Basic/Sanitizers.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ SANITIZER_GROUP("undefined", Undefined,
152152
FloatCastOverflow |
153153
IntegerDivideByZero | NonnullAttribute | Null | ObjectSize |
154154
PointerOverflow | Return | ReturnsNonnullAttribute | Shift |
155-
SignedIntegerOverflow | Unreachable | VLABound | Function |
156-
Vptr)
155+
SignedIntegerOverflow | Unreachable | VLABound | Function)
157156

158157
// -fsanitize=undefined-trap is an alias for -fsanitize=undefined.
159158
SANITIZER_GROUP("undefined-trap", UndefinedTrap, Undefined)

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static const SanitizerMask NeedsUbsanRt =
2929
SanitizerKind::Undefined | SanitizerKind::Integer |
3030
SanitizerKind::LocalBounds | SanitizerKind::ImplicitConversion |
3131
SanitizerKind::Nullability | SanitizerKind::CFI |
32-
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast;
32+
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast |
33+
SanitizerKind::Vptr;
3334
static const SanitizerMask NeedsUbsanCxxRt =
3435
SanitizerKind::Vptr | SanitizerKind::CFI;
3536
static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
@@ -52,23 +53,25 @@ static const SanitizerMask SupportsCoverage =
5253
SanitizerKind::FuzzerNoLink | SanitizerKind::FloatDivideByZero |
5354
SanitizerKind::SafeStack | SanitizerKind::ShadowCallStack |
5455
SanitizerKind::Thread | SanitizerKind::ObjCCast | SanitizerKind::KCFI |
55-
SanitizerKind::NumericalStability;
56+
SanitizerKind::NumericalStability | SanitizerKind::Vptr;
5657
static const SanitizerMask RecoverableByDefault =
5758
SanitizerKind::Undefined | SanitizerKind::Integer |
5859
SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
59-
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast;
60+
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast |
61+
SanitizerKind::Vptr;
6062
static const SanitizerMask Unrecoverable =
6163
SanitizerKind::Unreachable | SanitizerKind::Return;
6264
static const SanitizerMask AlwaysRecoverable = SanitizerKind::KernelAddress |
6365
SanitizerKind::KernelHWAddress |
6466
SanitizerKind::KCFI;
6567
static const SanitizerMask NeedsLTO = SanitizerKind::CFI;
6668
static const SanitizerMask TrappingSupported =
67-
(SanitizerKind::Undefined & ~SanitizerKind::Vptr) | SanitizerKind::Integer |
69+
SanitizerKind::Undefined | SanitizerKind::Integer |
6870
SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
6971
SanitizerKind::LocalBounds | SanitizerKind::CFI |
7072
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast;
71-
static const SanitizerMask MergeDefault = SanitizerKind::Undefined;
73+
static const SanitizerMask MergeDefault =
74+
SanitizerKind::Undefined | SanitizerKind::Vptr;
7275
static const SanitizerMask TrappingDefault =
7376
SanitizerKind::CFI | SanitizerKind::LocalBounds;
7477
static const SanitizerMask CFIClasses =
@@ -188,8 +191,8 @@ static void addDefaultIgnorelists(const Driver &D, SanitizerMask Kinds,
188191
{"dfsan_abilist.txt", SanitizerKind::DataFlow},
189192
{"cfi_ignorelist.txt", SanitizerKind::CFI},
190193
{"ubsan_ignorelist.txt",
191-
SanitizerKind::Undefined | SanitizerKind::Integer |
192-
SanitizerKind::Nullability |
194+
SanitizerKind::Undefined | SanitizerKind::Vptr |
195+
SanitizerKind::Integer | SanitizerKind::Nullability |
193196
SanitizerKind::FloatDivideByZero}};
194197

195198
for (auto BL : Ignorelists) {

clang/test/Driver/fsanitize.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
// CHECK-UNDEFINED-MERGE5: "-fsanitize-merge=alignment,null"
6464

6565
// RUN: %clang --target=x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED
66-
// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
66+
// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
6767

6868
// RUN: %clang --target=x86_64-apple-darwin10 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
6969
// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
@@ -78,7 +78,7 @@
7878
// CHECK-UNDEFINED-WIN64-MINGW: "--dependent-lib={{[^"]*}}libclang_rt.ubsan_standalone{{(-x86_64)?}}.a"
7979
// CHECK-UNDEFINED-WIN-CXX: "--dependent-lib={{[^"]*}}ubsan_standalone_cxx{{[^"]*}}.lib"
8080
// CHECK-UNDEFINED-MSVC-SAME: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}}
81-
// CHECK-UNDEFINED-WIN64-MINGW-SAME: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute|function|vptr),?){19}"}}
81+
// CHECK-UNDEFINED-WIN64-MINGW-SAME: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}}
8282

8383
// RUN: %clang --target=i386-pc-win32 -fsanitize-coverage=bb %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COVERAGE-WIN32
8484
// CHECK-COVERAGE-WIN32: "--dependent-lib={{[^"]*}}ubsan_standalone{{(-i386)?}}.lib"
@@ -148,10 +148,11 @@
148148
// RUN: %clang -fsanitize=shift -fno-sanitize=shift-base %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FSANITIZE-SHIFT-PARTIAL
149149
// CHECK-FSANITIZE-SHIFT-PARTIAL: "-fsanitize=shift-exponent"
150150

151-
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-trap=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-TRAP-UNDEF
152-
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-TRAP-UNDEF
151+
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-trap=vptr %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-TRAP-UNDEF
153152
// CHECK-VPTR-TRAP-UNDEF: error: invalid argument '-fsanitize=vptr' not allowed with '-fsanitize-trap=undefined'
154153

154+
// RUN: %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-undefined-trap-on-error %s -###
155+
155156
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=vptr -fno-rtti %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-NO-RTTI
156157
// CHECK-VPTR-NO-RTTI: '-fsanitize=vptr' not allowed with '-fno-rtti'
157158

@@ -406,7 +407,7 @@
406407
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fno-sanitize-recover=undefined -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-RECOVER-UBSAN
407408
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fno-sanitize-recover=all -fsanitize-recover=thread -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-RECOVER-UBSAN
408409
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover=all -fno-sanitize-recover=undefined -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-RECOVER-UBSAN
409-
// CHECK-RECOVER-UBSAN: "-fsanitize-recover={{((signed-integer-overflow|integer-divide-by-zero|function|shift-base|shift-exponent|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
410+
// CHECK-RECOVER-UBSAN: "-fsanitize-recover={{((signed-integer-overflow|integer-divide-by-zero|function|shift-base|shift-exponent|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){16}"}}
410411
// CHECK-NO-RECOVER-UBSAN-NOT: sanitize-recover
411412

412413
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fno-sanitize-recover=all -fsanitize-recover=object-size,shift-base -### 2>&1 | FileCheck %s --check-prefix=CHECK-PARTIAL-RECOVER
@@ -619,7 +620,7 @@
619620
// CHECK-ASAN-IOS: -fsanitize=address
620621

621622
// RUN: %clang --target=i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-OPENBSD
622-
// CHECK-UBSAN-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
623+
// CHECK-UBSAN-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
623624

624625
// RUN: not %clang --target=i386-pc-openbsd -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-OPENBSD
625626
// CHECK-ASAN-OPENBSD: unsupported option '-fsanitize=address' for target 'i386-pc-openbsd'
@@ -1061,7 +1062,7 @@
10611062
// CHECK-UBSAN-FUNCTION-TARGET-DAG: error: unsupported option '-fsanitize=function' for target 'x86_64-sie-ps5'
10621063
// CHECK-UBSAN-FUNCTION-MEXECUTE-ONLY-DAG: error: invalid argument '-fsanitize=function' not allowed with '-mexecute-only'
10631064
// CHECK-UBSAN-FUNCTION-MPURE-CODE-DAG: error: invalid argument '-fsanitize=function' not allowed with '-mpure-code'
1064-
// CHECK-UBSAN-UNDEFINED-VPTR: "-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound|vptr),?){18}"}}
1065+
// CHECK-UBSAN-UNDEFINED-VPTR: "-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound),?){17}"}}
10651066

10661067
// * Test BareMetal toolchain sanitizer support *
10671068

0 commit comments

Comments
 (0)