-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[RemoveDIs][DebugInfo] Correctly visit DPValues in StackInfoBuilder::visit #81247
Conversation
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-debuginfo Author: Stephen Tozer (SLTozer) ChangesIn
Full diff: https://github.com/llvm/llvm-project/pull/81247.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
index 648a5276a3d60a..43366950d8df1e 100644
--- a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
@@ -110,6 +110,20 @@ Instruction *getUntagLocationIfFunctionExit(Instruction &Inst) {
}
void StackInfoBuilder::visit(Instruction &Inst) {
+ // Check for non-intrinsic debug-info records.
+ for (auto &DPV : Inst.getDbgValueRange()) {
+ for (Value *V : DPV.location_ops()) {
+ if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
+ if (!isInterestingAlloca(*AI))
+ continue;
+ AllocaInfo &AInfo = Info.AllocasToInstrument[AI];
+ auto &DPVVec = AInfo.DbgVariableRecords;
+ if (DPVVec.empty() || DPVVec.back() != &DPV)
+ DPVVec.push_back(&DPV);
+ }
+ }
+ }
+
if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
if (CI->canReturnTwice()) {
Info.CallsReturnTwice = true;
@@ -150,20 +164,6 @@ void StackInfoBuilder::visit(Instruction &Inst) {
}
}
- // Check for non-intrinsic debug-info records.
- for (auto &DPV : Inst.getDbgValueRange()) {
- for (Value *V : DPV.location_ops()) {
- if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
- if (!isInterestingAlloca(*AI))
- continue;
- AllocaInfo &AInfo = Info.AllocasToInstrument[AI];
- auto &DPVVec = AInfo.DbgVariableRecords;
- if (DPVVec.empty() || DPVVec.back() != &DPV)
- DPVVec.push_back(&DPV);
- }
- }
- }
-
Instruction *ExitUntag = getUntagLocationIfFunctionExit(Inst);
if (ExitUntag)
Info.RetVec.push_back(ExitUntag);
|
LGTM, but could we get a regression test too to prevent this from happening in the future? Should be achievable either by inserting a lifetime intrinsic into an existing test, or duplicating an existing function. |
LGTM, also would like a test.
Okay for now, but we should restructure the function to not make this happen by design, not by ordering. I can do that when I get some time. |
I've modified an existing test to trigger for this, with a comment to explain the purpose of the test - more tests could potentially be covered here, but none as conveniently as the test that I've added, and I would hazard that more testing is unnecessary for this error since there are also other tests (that I can't run locally right now) that will also fail if RemoveDIs is enabled by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; this is probably the start of a theme of "now passes can more easily forget about debug-info", which is the natural result of making it less intrusive. Testing for all of these things is the only surefire solution.
In
StackInfoBuilder::visit(Instruction &Inst)
, operations are performed on memory-related instructions, including debug intrinsics that refer to "interesting" allocas. There is a block that also visits DPValues attached to the instruction, but this block is near the end of the function; this has two problems:This patch simply moves the DPValue-visiting block to the top of the function, which should resolve both of these problems.