[clang] [ubsan] Connect -fsanitize-skip-hot-cutoff to LowerAllowCheckPass<cutoffs> (PR #124857)

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 29 16:05:08 PST 2025


================
@@ -795,12 +795,30 @@ static void addSanitizers(const Triple &TargetTriple,
     PB.registerOptimizerLastEPCallback(SanitizersCallback);
   }
 
-  if (LowerAllowCheckPass::IsRequested()) {
+  // SanitizeSkipHotCutoffs: doubles with range [0, 1]
+  // Opts.cutoffs: ints with range [0, 1000000]
+  std::optional<std::vector<int>> scaledCutoffs =
+      CodeGenOpts.SanitizeSkipHotCutoffs.getAllScaled(1000000);
+
+  // TODO: remove IsRequested()
+  if (LowerAllowCheckPass::IsRequested() || scaledCutoffs.has_value()) {
     // We want to call it after inline, which is about OptimizerEarlyEPCallback.
     PB.registerOptimizerEarlyEPCallback([&](ModulePassManager &MPM,
                                             OptimizationLevel Level,
                                             ThinOrFullLTOPhase Phase) {
       LowerAllowCheckPass::Options Opts;
+
+      // TODO: after removing IsRequested(), the if case will be unconditional
+      if (scaledCutoffs.has_value()) {
+        // Copy from std::vector<int> to std::vector<unsigned int>
+        Opts.cutoffs = {scaledCutoffs.value().begin(),
+                        scaledCutoffs.value().end()};
+      } else {
+        for (unsigned int i = 0; i < SanitizerKind::SO_Count; ++i) {
+          Opts.cutoffs.push_back(0);
----------------
vitalybuka wrote:

we should be able to handle idx > size() in the pass anyway.
we don't want to crash on IR with large constant.

https://github.com/llvm/llvm-project/pull/124857


More information about the cfe-commits mailing list