Skip to content

Commit d443cd6

Browse files
authored
[ASan] Move early exit checks outside "instrumentFunction()" to avoid… (#133285)
… 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.
1 parent 3a3732c commit d443cd6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,16 @@ PreservedAnalyses AddressSanitizerPass::run(Module &M,
13121312
const StackSafetyGlobalInfo *const SSGI =
13131313
ClUseStackSafety ? &MAM.getResult<StackSafetyGlobalAnalysis>(M) : nullptr;
13141314
for (Function &F : M) {
1315+
if (F.empty())
1316+
continue;
1317+
if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage)
1318+
continue;
1319+
if (!ClDebugFunc.empty() && ClDebugFunc == F.getName())
1320+
continue;
1321+
if (F.getName().starts_with("__asan_"))
1322+
continue;
1323+
if (F.isPresplitCoroutine())
1324+
continue;
13151325
AddressSanitizer FunctionSanitizer(
13161326
M, SSGI, Options.InstrumentationWithCallsThreshold,
13171327
Options.MaxInlinePoisoningSize, Options.CompileKernel, Options.Recover,
@@ -2989,14 +2999,6 @@ bool AddressSanitizer::suppressInstrumentationSiteForDebug(int &Instrumented) {
29892999

29903000
bool AddressSanitizer::instrumentFunction(Function &F,
29913001
const TargetLibraryInfo *TLI) {
2992-
if (F.empty())
2993-
return false;
2994-
if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) return false;
2995-
if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return false;
2996-
if (F.getName().starts_with("__asan_")) return false;
2997-
if (F.isPresplitCoroutine())
2998-
return false;
2999-
30003002
bool FunctionModified = false;
30013003

30023004
// Do not apply any instrumentation for naked functions.

0 commit comments

Comments
 (0)