Skip to content

Commit 9a44f55

Browse files
authored
[sanitizers] do not accept out of bounds -fsanitize-skip-hot-cutoff (#145806)
If the user gives an out of bounds value, it is best to fail and let the user decide what to do.
1 parent 32aa80c commit 9a44f55

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/Basic/Sanitizers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ bool clang::parseSanitizerWeightedValue(StringRef Value, bool AllowGroups,
9595
return false;
9696
auto [N, W] = Value.split('=');
9797
double A;
98-
if (W.getAsDouble(A))
98+
if (W.getAsDouble(A) || A < 0.0 || A > 1.0)
9999
return false;
100-
A = std::clamp(A, 0.0, 1.0);
101100
// AllowGroups is already taken into account for ParsedKind,
102101
// hence we unconditionally expandSanitizerGroups.
103102
Cutoffs.set(expandSanitizerGroups(ParsedKind), A);

clang/test/Driver/fsanitize.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,3 +1299,11 @@
12991299
// No-op: -fsanitize-skip-hot-cutoff= without parameters is unusual but valid
13001300
// RUN: %clang -Werror --target=x86_64-linux-gnu -fsanitize-skip-hot-cutoff= %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SKIP-HOT-CUTOFF12
13011301
// CHECK-SKIP-HOT-CUTOFF12-NOT: "-fsanitize-skip-hot-cutoff"
1302+
1303+
// Invalid: out of range cutoff
1304+
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize-skip-hot-cutoff=undefined=1.1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SKIP-HOT-CUTOFF13
1305+
// CHECK-SKIP-HOT-CUTOFF13: unsupported argument 'undefined=1.1' to option '-fsanitize-skip-hot-cutoff='
1306+
1307+
// Invalid: out of range cutoff
1308+
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize-skip-hot-cutoff=undefined=-0.1 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SKIP-HOT-CUTOFF14
1309+
// CHECK-SKIP-HOT-CUTOFF14: unsupported argument 'undefined=-0.1' to option '-fsanitize-skip-hot-cutoff='

0 commit comments

Comments
 (0)