[llvm] [hwasan] Invalidate DominatorTreeAnalysis after each function is sanitized (PR #66935)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 01:38:20 PDT 2023


================
@@ -430,8 +430,16 @@ PreservedAnalyses HWAddressSanitizerPass::run(Module &M,
 
   HWAddressSanitizer HWASan(M, Options.CompileKernel, Options.Recover, SSI);
   auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
-  for (Function &F : M)
+  for (Function &F : M) {
     HWASan.sanitizeFunction(F, FAM);
+    // After sanitizing F - which may split blocks via insertShadowTagCheck -
+    // some cached analyses are invalid. This matters because
+    // sanitizeFunction(F', FAM) may indirectly call the global stack safety
+    // analysis, hence we need to make sure the analyses of F are up to date.
+    PreservedAnalyses PA = PreservedAnalyses::all();
----------------
fhahn wrote:

This is confusing, in particular because below it marks all analysis as not preserved. Should we invalidate all analysis here?

Also, the dominator tree should be very easy to preserve, to save some compile-time: `SplitBlockAndInsertIfThen` takes an optional DomTreeUpdater object to update the dominator tree.

I didn't take a look at how the pass uses the dominator tree, but if the dominator tree isn't updated after making changes to the CFG and is later used again in the same function, then it may use an out-of-date dominator tree. 

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


More information about the llvm-commits mailing list