@@ -870,70 +870,19 @@ MachineInstrBuilder MLocTracker::emitLoc(Optional<LocIdx> MLoc,
870
870
// the variable is.
871
871
if (Offset == 0 ) {
872
872
const SpillLoc &Spill = SpillLocs[SpillID.id ()];
873
+ Expr = TRI.prependOffsetExpression (Expr, DIExpression::ApplyOffset,
874
+ Spill.SpillOffset );
873
875
unsigned Base = Spill.SpillBase ;
874
876
MIB.addReg (Base);
877
+ MIB.addImm (0 );
875
878
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
903
883
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);
937
886
}
938
887
} else {
939
888
// This is a stack location with a weird subregister offset: emit an undef
0 commit comments