-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[msan] Don't modify CFG iterating it #90691
Merged
vitalybuka
merged 4 commits into
main
from
users/vitalybuka/spr/msan-dont-modify-cfg-iterating-it
May 1, 2024
Merged
[msan] Don't modify CFG iterating it #90691
vitalybuka
merged 4 commits into
main
from
users/vitalybuka/spr/msan-dont-modify-cfg-iterating-it
May 1, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.4
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) ChangesIn rare cases Somehow existing Full diff: https://github.com/llvm/llvm-project/pull/90691.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index cc2295c44023c4..4a5f4a40726574 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -1135,6 +1135,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
std::unique_ptr<VarArgHelper> VAHelper;
const TargetLibraryInfo *TLI;
Instruction *FnPrologueEnd;
+ SmallVector<Instruction *, 128> Instructions;
// The following flags disable parts of MSan instrumentation based on
// exclusion list contents and command-line options.
@@ -1520,6 +1521,11 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
for (BasicBlock *BB : depth_first(FnPrologueEnd->getParent()))
visit(*BB);
+ // `visit` above only collects instructions. Process them after iterating
+ // CFG to avoid requirement on CFG transformations.
+ for (Instruction *I : Instructions)
+ instrument(*I);
+
// Finalize PHI nodes.
for (PHINode *PN : ShadowPHINodes) {
PHINode *PNS = cast<PHINode>(getShadow(PN));
@@ -2181,14 +2187,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
return ConstantDataVector::get(IRB.getContext(), OrderingTable);
}
- // ------------------- Visitors.
- using InstVisitor<MemorySanitizerVisitor>::visit;
- void visit(Instruction &I) {
- if (I.getMetadata(LLVMContext::MD_nosanitize))
- return;
- // Don't want to visit if we're in the prologue
- if (isInPrologue(I))
- return;
+ void instrument(Instruction &I) {
if (!DebugCounter::shouldExecute(DebugInstrumentInstruction)) {
LLVM_DEBUG(dbgs() << "Skipping instruction: " << I << "\n");
// We still need to set the shadow and origin to clean values.
@@ -2199,6 +2198,18 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
InstVisitor<MemorySanitizerVisitor>::visit(I);
}
+ // ------------------- Visitors.
+ using InstVisitor<MemorySanitizerVisitor>::visit;
+ void visit(Instruction &I) {
+ if (I.getMetadata(LLVMContext::MD_nosanitize))
+ return;
+ // Don't want to visit if we're in the prologue
+ if (isInPrologue(I))
+ return;
+
+ Instructions.push_back(&I);
+ }
+
/// Instrument LoadInst
///
/// Loads the corresponding shadow and (optionally) origin.
|
Created using spr 1.3.4
fmayer
approved these changes
May 1, 2024
Created using spr 1.3.4
thurstond
approved these changes
May 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In rare cases
SplitBlockAndInsertSimpleForLoop
inpaintOrigin
crashes outsize iterators.Somehow existing
SplitBlockAndInsertIfThen
do not invalidate iterators.