Skip to content

Commit 4fe2ab5

Browse files
committed
Revert "[DebugInfo][InstrRef] Describe value sizes when spilt to stack"
This reverts commit a15b66e. This causes linker to crash at assertion: `Assertion failed: !Expr->isComplex(), file C:\b\s\w\ir\cache\builder\src\third_party\llvm\llvm\lib\CodeGen\LiveDebugValues\InstrRefBasedImpl.cpp, line 907`.
1 parent bfcb2c1 commit 4fe2ab5

File tree

5 files changed

+19
-449
lines changed

5 files changed

+19
-449
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -870,70 +870,19 @@ MachineInstrBuilder MLocTracker::emitLoc(Optional<LocIdx> MLoc,
870870
// the variable is.
871871
if (Offset == 0) {
872872
const SpillLoc &Spill = SpillLocs[SpillID.id()];
873+
Expr = TRI.prependOffsetExpression(Expr, DIExpression::ApplyOffset,
874+
Spill.SpillOffset);
873875
unsigned Base = Spill.SpillBase;
874876
MIB.addReg(Base);
877+
MIB.addImm(0);
875878

876-
// There are several ways we can dereference things, and several inputs
877-
// to consider:
878-
// * NRVO variables will appear with IsIndirect set, but should have
879-
// nothing else in their DIExpressions,
880-
// * Variables with DW_OP_stack_value in their expr already need an
881-
// explicit dereference of the stack location,
882-
// * Values that don't match the variable size need DW_OP_deref_size,
883-
// * Everything else can just become a simple location expression.
884-
885-
// We need to use deref_size whenever there's a mismatch between the
886-
// size of value and the size of variable portion being read.
887-
// Additionally, we should use it whenever dealing with stack_value
888-
// fragments, to avoid the consumer having to determine the deref size
889-
// from DW_OP_piece.
890-
bool UseDerefSize = false;
891-
unsigned ValueSizeInBits = getLocSizeInBits(*MLoc);
892-
unsigned DerefSizeInBytes = ValueSizeInBits / 8;
893-
if (auto Fragment = Var.getFragment()) {
894-
unsigned VariableSizeInBits = Fragment->SizeInBits;
895-
if (VariableSizeInBits != ValueSizeInBits || Expr->isComplex())
896-
UseDerefSize = true;
897-
} else if (auto Size = Var.getVariable()->getSizeInBits()) {
898-
if (*Size != ValueSizeInBits) {
899-
UseDerefSize = true;
900-
}
901-
}
902-
879+
// Being on the stack makes this location indirect; if it was _already_
880+
// indirect though, we need to add extra indirection. See this test for
881+
// a scenario where this happens:
882+
// llvm/test/DebugInfo/X86/spill-nontrivial-param.ll
903883
if (Properties.Indirect) {
904-
// This is something like an NRVO variable, where the pointer has been
905-
// spilt to the stack. It should end up being a memory location, with
906-
// the pointer to the variable loaded off the stack with a deref:
907-
assert(!Expr->isComplex());
908-
Expr = TRI.prependOffsetExpression(
909-
Expr, DIExpression::ApplyOffset | DIExpression::DerefAfter,
910-
Spill.SpillOffset);
911-
MIB.addImm(0);
912-
} else if (UseDerefSize) {
913-
// We're loading a value off the stack that's not the same size as the
914-
// variable. Add / subtract stack offset, explicitly deref with a size,
915-
// and add DW_OP_stack_value if not already present.
916-
SmallVector<uint64_t, 2> Ops = {dwarf::DW_OP_deref_size,
917-
DerefSizeInBytes};
918-
Expr = DIExpression::prependOpcodes(Expr, Ops, true);
919-
unsigned Flags = DIExpression::StackValue | DIExpression::ApplyOffset;
920-
Expr = TRI.prependOffsetExpression(Expr, Flags, Spill.SpillOffset);
921-
MIB.addReg(0);
922-
} else if (Expr->isComplex()) {
923-
// A variable with no size ambiguity, but with extra elements in it's
924-
// expression. Manually dereference the stack location.
925-
assert(Expr->isComplex());
926-
Expr = TRI.prependOffsetExpression(
927-
Expr, DIExpression::ApplyOffset | DIExpression::DerefAfter,
928-
Spill.SpillOffset);
929-
MIB.addReg(0);
930-
} else {
931-
// A plain value that has been spilt to the stack, with no further
932-
// context. Request a location expression, marking the DBG_VALUE as
933-
// IsIndirect.
934-
Expr = TRI.prependOffsetExpression(Expr, DIExpression::ApplyOffset,
935-
Spill.SpillOffset);
936-
MIB.addImm(0);
884+
std::vector<uint64_t> Elts = {dwarf::DW_OP_deref};
885+
Expr = DIExpression::append(Expr, Elts);
937886
}
938887
} else {
939888
// This is a stack location with a weird subregister offset: emit an undef

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -633,19 +633,6 @@ class MLocTracker {
633633
/// Return true if Idx is a spill machine location.
634634
bool isSpill(LocIdx Idx) const { return LocIdxToLocID[Idx] >= NumRegs; }
635635

636-
/// How large is this location (aka, how wide is a value defined there?).
637-
unsigned getLocSizeInBits(LocIdx L) const {
638-
unsigned ID = LocIdxToLocID[L];
639-
if (!isSpill(L)) {
640-
return TRI.getRegSizeInBits(Register(ID), MF.getRegInfo());
641-
} else {
642-
// The slot location on the stack is uninteresting, we care about the
643-
// position of the value within the slot (which comes with a size).
644-
StackSlotPos Pos = locIDToSpillIdx(ID);
645-
return Pos.first;
646-
}
647-
}
648-
649636
MLocIterator begin() { return MLocIterator(LocIdxToIDNum, 0); }
650637

651638
MLocIterator end() {

0 commit comments

Comments
 (0)