Index: llvm/trunk/lib/Transforms/Utils/Local.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/Local.cpp +++ llvm/trunk/lib/Transforms/Utils/Local.cpp @@ -1597,13 +1597,13 @@ DIExpr->getElement(0) != dwarf::DW_OP_deref) return; - // Insert the offset immediately after the first deref. + // Insert the offset before the first deref. // We could just change the offset argument of dbg.value, but it's unsigned... if (Offset) { SmallVector Ops; - Ops.push_back(dwarf::DW_OP_deref); DIExpression::appendOffset(Ops, Offset); Ops.append(DIExpr->elements_begin() + 1, DIExpr->elements_end()); + Ops.push_back(dwarf::DW_OP_deref); DIExpr = Builder.createExpression(Ops); } Index: llvm/trunk/test/Transforms/SafeStack/X86/debug-loc2.ll =================================================================== --- llvm/trunk/test/Transforms/SafeStack/X86/debug-loc2.ll +++ llvm/trunk/test/Transforms/SafeStack/X86/debug-loc2.ll @@ -25,7 +25,7 @@ tail call void @llvm.dbg.value(metadata i32* %x1, metadata !10, metadata !24), !dbg !16 ; Supported dbg.value: rewritted based on the [[USP]] value. -; CHECK: call void @llvm.dbg.value(metadata i8* %[[USP]], metadata ![[X1:.*]], metadata !DIExpression(DW_OP_deref, DW_OP_constu, 4, DW_OP_minus)) +; CHECK: call void @llvm.dbg.value(metadata i8* %[[USP]], metadata ![[X1:.*]], metadata !DIExpression(DW_OP_constu, 4, DW_OP_minus, DW_OP_deref)) tail call void @llvm.dbg.value(metadata i32* %x1, metadata !10, metadata !15), !dbg !16 call void @capture(i32* nonnull %x1), !dbg !17 @@ -33,7 +33,7 @@ ; CHECK: call void @llvm.random.metadata.use(metadata ![[EMPTY]]) call void @llvm.random.metadata.use(metadata i32* %x2) -; CHECK: call void @llvm.dbg.value(metadata i8* %[[USP]], metadata ![[X2:.*]], metadata !DIExpression(DW_OP_deref, DW_OP_constu, 8, DW_OP_minus)) +; CHECK: call void @llvm.dbg.value(metadata i8* %[[USP]], metadata ![[X2:.*]], metadata !DIExpression(DW_OP_constu, 8, DW_OP_minus, DW_OP_deref)) call void @llvm.dbg.value(metadata i32* %x2, metadata !12, metadata !15), !dbg !18 call void @capture(i32* nonnull %x2), !dbg !19 ret void, !dbg !20