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

Thurston Dang via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 29 10:56:05 PST 2025


================
@@ -795,12 +795,29 @@ static void addSanitizers(const Triple &TargetTriple,
     PB.registerOptimizerLastEPCallback(SanitizersCallback);
   }
 
-  if (LowerAllowCheckPass::IsRequested()) {
+  bool lowerAllowCheck = LowerAllowCheckPass::IsRequested();
+  // Is there a non-zero cutoff?
+  static constexpr double SanitizerMaskCutoffsEps = 0.000000001f;
+  for (unsigned int i = 0; i < SanitizerKind::SO_Count; ++i) {
+    lowerAllowCheck |= (CodeGenOpts.SanitizeSkipHotCutoffs[i].value_or(0) >
+                        SanitizerMaskCutoffsEps);
+  }
+
+  if (lowerAllowCheck) {
     // We want to call it after inline, which is about OptimizerEarlyEPCallback.
     PB.registerOptimizerEarlyEPCallback([&](ModulePassManager &MPM,
                                             OptimizationLevel Level,
                                             ThinOrFullLTOPhase Phase) {
       LowerAllowCheckPass::Options Opts;
+
+      // SanitizeSkipHotCutoffs: doubles with range [0, 1]
+      // Opts.cutoffs: ints with range [0, 1000000]
+      static_assert(static_cast<int>(SanitizerMaskCutoffsEps * 1000000) == 0);
+      for (unsigned int i = 0; i < SanitizerKind::SO_Count; ++i) {
+        Opts.cutoffs.push_back(
+            CodeGenOpts.SanitizeSkipHotCutoffs[i].value_or(0) * 1000000);
----------------
thurstond wrote:

Done

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


More information about the cfe-commits mailing list