Author: Florian Mayer
Date: 2025-06-26T10:08:04-07:00
New Revision: 9a44f55c00f783f9c39a8c43500c01cf2cc743f4

URL: 
https://github.com/llvm/llvm-project/commit/9a44f55c00f783f9c39a8c43500c01cf2cc743f4
DIFF: 
https://github.com/llvm/llvm-project/commit/9a44f55c00f783f9c39a8c43500c01cf2cc743f4.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/Basic/Sanitizers.cpp
    clang/test/Driver/fsanitize.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Sanitizers.cpp b/clang/lib/Basic/Sanitizers.cpp
index cff289e8554d1..774b94cedb130 100644
--- a/clang/lib/Basic/Sanitizers.cpp
+++ b/clang/lib/Basic/Sanitizers.cpp
@@ -95,9 +95,8 @@ bool clang::parseSanitizerWeightedValue(StringRef Value, bool 
AllowGroups,
     return false;
   auto [N, W] = Value.split('=');
   double A;
-  if (W.getAsDouble(A))
+  if (W.getAsDouble(A) || A < 0.0 || A > 1.0)
     return false;
-  A = std::clamp(A, 0.0, 1.0);
   // AllowGroups is already taken into account for ParsedKind,
   // hence we unconditionally expandSanitizerGroups.
   Cutoffs.set(expandSanitizerGroups(ParsedKind), A);

diff  --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 2aeb9fbaaa16c..fbe1fd72c84c6 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -1299,3 +1299,11 @@
 // No-op: -fsanitize-skip-hot-cutoff= without parameters is unusual but valid
 // RUN: %clang -Werror --target=x86_64-linux-gnu -fsanitize-skip-hot-cutoff= 
%s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SKIP-HOT-CUTOFF12
 // CHECK-SKIP-HOT-CUTOFF12-NOT: "-fsanitize-skip-hot-cutoff"
+
+// Invalid: out of range cutoff
+// 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
+// CHECK-SKIP-HOT-CUTOFF13: unsupported argument 'undefined=1.1' to option 
'-fsanitize-skip-hot-cutoff='
+
+// Invalid: out of range cutoff
+// 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
+// CHECK-SKIP-HOT-CUTOFF14: unsupported argument 'undefined=-0.1' to option 
'-fsanitize-skip-hot-cutoff='


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to