-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ASan] Move early exit checks outside "instrumentFunction()" to avoid… #133285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ASan] Move early exit checks outside "instrumentFunction()" to avoid… #133285
Conversation
… 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.
@llvm/pr-subscribers-llvm-transforms Author: Hank Chang (HankChang736) Changes… 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:
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.
|
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Hank Chang (HankChang736) Changes… 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:
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.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
… 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.