Skip to content

Commit eb4c98c

Browse files
committedSep 27, 2019
[DebugInfo] Exclude memory location values as parameter entry values
Abandon describing of loaded values due to safety concerns. Loaded values are described as derefed memory location at caller point. At callee we can unintentionally change that memory location which would lead to different entry being printed value before and after the memory location clobbering. This problem is described in llvm.org/PR43343. Patch by Nikola Prica Differential Revision: https://reviews.llvm.org/D67717 llvm-svn: 373089
1 parent 2319eb6 commit eb4c98c

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed
 

‎llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI,
246246
// a call site parameter expression and if that expression is just a register
247247
// location, emit it with addBReg and offset 0, because we should emit a DWARF
248248
// expression representing a value, rather than a location.
249-
if (!isMemoryLocation() && !HasComplexExpression && (!isParameterValue() ||
250-
isEntryValue())) {
249+
if (!isMemoryLocation() && !HasComplexExpression &&
250+
(!isParameterValue() || isEntryValue())) {
251251
for (auto &Reg : DwarfRegs) {
252252
if (Reg.DwarfRegNo >= 0)
253253
addReg(Reg.DwarfRegNo, Reg.Comment);
@@ -413,6 +413,9 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
413413
break;
414414
case dwarf::DW_OP_deref:
415415
assert(!isRegisterLocation());
416+
// For more detailed explanation see llvm.org/PR43343.
417+
assert(!isParameterValue() && "Parameter entry values should not be "
418+
"dereferenced due to safety reasons.");
416419
if (!isMemoryLocation() && ::isMemoryLocation(ExprCursor))
417420
// Turning this into a memory location description makes the deref
418421
// implicit.

‎llvm/lib/CodeGen/TargetInstrInfo.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -1133,18 +1133,6 @@ TargetInstrInfo::describeLoadedValue(const MachineInstr &MI) const {
11331133
} else if (MI.isMoveImmediate()) {
11341134
Op = &MI.getOperand(1);
11351135
return ParamLoadedValue(*Op, Expr);
1136-
} else if (MI.hasOneMemOperand()) {
1137-
int64_t Offset;
1138-
const auto &TRI = MF->getSubtarget().getRegisterInfo();
1139-
const auto &TII = MF->getSubtarget().getInstrInfo();
1140-
const MachineOperand *BaseOp;
1141-
1142-
if (!TII->getMemOperandWithOffset(MI, BaseOp, Offset, TRI))
1143-
return None;
1144-
1145-
Expr = DIExpression::prepend(Expr, DIExpression::DerefAfter, Offset);
1146-
Op = BaseOp;
1147-
return ParamLoadedValue(*Op, Expr);
11481136
}
11491137

11501138
return None;

‎llvm/test/DebugInfo/MIR/X86/dbgcall-site-interpretation.mir

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
# CHECK-NEXT: DW_AT_low_pc
2222
# CHECK-EMPTY:
2323
# CHECK-NEXT: DW_TAG_GNU_call_site_parameter
24-
# CHECK-NEXT: DW_AT_location (DW_OP_reg2 RCX)
25-
# CHECK-NEXT: DW_AT_GNU_call_site_value (DW_OP_fbreg +8, DW_OP_deref)
26-
# CHECK-EMPTY:
27-
# CHECK-NEXT: DW_TAG_GNU_call_site_parameter
24+
# RCX loads memory location. We can't rely that memory location won't be changed.
25+
# CHECK-NOT: DW_AT_location (DW_OP_reg2 RCX)
2826
# CHECK-NEXT: DW_AT_location (DW_OP_reg4 RSI)
2927
# CHECK-NEXT: DW_AT_GNU_call_site_value (DW_OP_lit4)
3028
# CHECK-EMPTY:

0 commit comments

Comments
 (0)
Please sign in to comment.