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

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 12:56:37 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();
----------------
thurstond wrote:

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

ASan, MSan, DFSan and HWASan all share the same "invalidate all the analyses, including GlobalsAA, at the end of the pass" boilerplate code, so perhaps it's not strictly necessary for HWASan.

But even if all the analyses are stale at the end of the HWASan pass, they don't necessarily need to be eagerly invalidated after each function is sanitized, as long as the analysis is not used by the rest of the HWASan pass. The stack safety global analysis is a special case because, by definition, it looks at every function.

> 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.

That's a good idea, thanks! I'll update the pull request shortly.



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


More information about the llvm-commits mailing list