Skip to content

Commit 86611e7

Browse files
noclownsakadutta
authored andcommitted
[BOLT][NFC] Fix for a dangling reference UB (llvm#163344)
Fix UB caused by accessing the top element of the stack via a dangling reference after a call to .pop() This is tripping static analysis. No functional changes. Performance impact is negligible, but alt. implementation of the fix is possible if needed. Testing: Both functional and unit tests are passing.
1 parent 8a9b837 commit 86611e7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

bolt/lib/Passes/FrameAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class FrameAccessAnalysis {
198198
if (CFIStack.empty())
199199
dbgs() << "Assertion is about to fail: " << BF.getPrintName() << "\n";
200200
assert(!CFIStack.empty() && "Corrupt CFI stack");
201-
std::pair<int64_t, uint16_t> &Elem = CFIStack.top();
201+
std::pair<int64_t, uint16_t> Elem = CFIStack.top();
202202
CFIStack.pop();
203203
CfaOffset = Elem.first;
204204
CfaReg = Elem.second;

bolt/lib/Passes/ShrinkWrapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void StackLayoutModifier::classifyCFIs() {
402402
break;
403403
case MCCFIInstruction::OpRestoreState: {
404404
assert(!CFIStack.empty() && "Corrupt CFI stack");
405-
std::pair<int64_t, uint16_t> &Elem = CFIStack.top();
405+
std::pair<int64_t, uint16_t> Elem = CFIStack.top();
406406
CFIStack.pop();
407407
CfaOffset = Elem.first;
408408
CfaReg = Elem.second;

0 commit comments

Comments
 (0)