[llvm] [ASan] Move early exit checks outside "instrumentFunction()" to avoid… (PR #133285)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Thu Mar 27 10:46:20 PDT 2025
    
    
  
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Hank Chang (HankChang736)
<details>
<summary>Changes</summary>
… unnecessary FunctionSanitizer construction (NFC)
This patch moves several early-exit checks (e.g., empty function, etc.) out of "AddressSanitizer::instrumentFunction" and into the caller. This change avoids unnecessary construction of FunctionSanitizer when instrumentation is not needed.
---
Full diff: https://github.com/llvm/llvm-project/pull/133285.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+7-8) 
``````````diff
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 80da830567d2e..0284e78577413 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1312,6 +1312,13 @@ PreservedAnalyses AddressSanitizerPass::run(Module &M,
   const StackSafetyGlobalInfo *const SSGI =
       ClUseStackSafety ? &MAM.getResult<StackSafetyGlobalAnalysis>(M) : nullptr;
   for (Function &F : M) {
+    if (F.empty())
+      continue;
+    if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) continue;
+    if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) continue;
+    if (F.getName().starts_with("__asan_")) continue;
+    if (F.isPresplitCoroutine())
+      continue;
     AddressSanitizer FunctionSanitizer(
         M, SSGI, Options.InstrumentationWithCallsThreshold,
         Options.MaxInlinePoisoningSize, Options.CompileKernel, Options.Recover,
@@ -2989,14 +2996,6 @@ bool AddressSanitizer::suppressInstrumentationSiteForDebug(int &Instrumented) {
 
 bool AddressSanitizer::instrumentFunction(Function &F,
                                           const TargetLibraryInfo *TLI) {
-  if (F.empty())
-    return false;
-  if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) return false;
-  if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return false;
-  if (F.getName().starts_with("__asan_")) return false;
-  if (F.isPresplitCoroutine())
-    return false;
-
   bool FunctionModified = false;
 
   // Do not apply any instrumentation for naked functions.
``````````
</details>
https://github.com/llvm/llvm-project/pull/133285
    
    
More information about the llvm-commits
mailing list