Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -775,6 +775,28 @@ bool Deref = MI->getOperand(0).isReg() && MI->getOperand(1).isImm(); int64_t Offset = Deref ? MI->getOperand(1).getImm() : 0; + for (unsigned i = 0; i < Expr->getNumElements(); ++i) { + if (Deref) { + // We currently don't support extra Offsets or derefs after the first + // one. Bail out early instead of emitting an incorrect comment + OS << " [complex expression]"; + AP.OutStreamer->emitRawComment(OS.str()); + return true; + } + uint64_t Op = Expr->getElement(i); + if (Op == dwarf::DW_OP_deref) { + Deref = true; + continue; + } + uint64_t ExtraOffset = Expr->getElement(i++); + if (Op == dwarf::DW_OP_plus) + Offset += ExtraOffset; + else { + assert(Op == dwarf::DW_OP_minus); + Offset -= ExtraOffset; + } + } + // Register or immediate value. Register 0 means undef. if (MI->getOperand(0).isFPImm()) { APFloat APF = APFloat(MI->getOperand(0).getFPImm()->getValueAPF()); Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -951,7 +951,7 @@ "Expected inlined-at fields to agree"); uint64_t Offset = DI->getOffset(); // A dbg.value for an alloca is always indirect. - bool IsIndirect = isa(V) || Offset != 0; + bool IsIndirect = Offset != 0; SDDbgValue *SDV; if (Val.getNode()) { if (!EmitFuncArgumentDbgValue(V, Variable, Expr, dl, Offset, IsIndirect, @@ -4528,12 +4528,10 @@ // Check unused arguments map. N = UnusedArgNodeMap[V]; if (N.getNode()) { - // A dbg.value for an alloca is always indirect. - bool IsIndirect = isa(V) || Offset != 0; if (!EmitFuncArgumentDbgValue(V, Variable, Expression, dl, Offset, - IsIndirect, N)) { + false, N)) { SDV = DAG.getDbgValue(Variable, Expression, N.getNode(), N.getResNo(), - IsIndirect, Offset, dl, SDNodeOrder); + false, Offset, dl, SDNodeOrder); DAG.AddDbgValue(SDV, N.getNode(), false); } } else if (!V->use_empty() ) { Index: lib/Transforms/Utils/Local.cpp =================================================================== --- lib/Transforms/Utils/Local.cpp +++ lib/Transforms/Utils/Local.cpp @@ -1071,8 +1071,14 @@ if (LdStHasDebugValue(DIVar, LI)) return true; - Builder.insertDbgValueIntrinsic(LI->getOperand(0), 0, DIVar, DIExpr, - DDI->getDebugLoc(), LI); + // We are now tracking the loaded value instead of the address. In the + // future if multi-location support is added to the IR, it might be + // preferable to keep tracking both the loaded value and the original + // address in case the alloca can not be elided. + Instruction *DbgValue = + Builder.insertDbgValueIntrinsic(LI, 0, DIVar, DIExpr, + DDI->getDebugLoc(), (Instruction*) nullptr); + DbgValue->insertAfter(LI); return true; } @@ -1114,9 +1120,14 @@ // This is a call by-value or some other instruction that // takes a pointer to the variable. Insert a *value* // intrinsic that describes the alloca. + SmallVector NewDIExpr; + auto *DIExpr = DDI->getExpression(); + NewDIExpr.push_back(dwarf::DW_OP_deref); + if (DIExpr) + NewDIExpr.append(DIExpr->elements_begin(), DIExpr->elements_end()); DIB.insertDbgValueIntrinsic(AI, 0, DDI->getVariable(), - DDI->getExpression(), DDI->getDebugLoc(), - CI); + DIB.createExpression(NewDIExpr), + DDI->getDebugLoc(), CI); } DDI->eraseFromParent(); } Index: test/CodeGen/ARM/debug-info-blocks.ll =================================================================== --- test/CodeGen/ARM/debug-info-blocks.ll +++ test/CodeGen/ARM/debug-info-blocks.ll @@ -1,5 +1,5 @@ ; RUN: llc -O0 < %s | FileCheck %s -; CHECK: @DEBUG_VALUE: foobar_func_block_invoke_0:mydata <- [%SP+{{[0-9]+}}] +; CHECK: @DEBUG_VALUE: foobar_func_block_invoke_0:mydata <- [complex expression] ; Radar 9331779 target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:64-v128:32:128-a0:0:32-n32" target triple = "thumbv7-apple-ios" Index: test/DebugInfo/AArch64/coalescing.ll =================================================================== --- test/DebugInfo/AArch64/coalescing.ll +++ test/DebugInfo/AArch64/coalescing.ll @@ -60,6 +60,6 @@ !13 = !{i32 2, !"Debug Info Version", i32 3} !14 = !{!"clang version 3.6.0 (trunk 223149) (llvm/trunk 223115)"} !15 = !DILocation(line: 5, column: 3, scope: !4) -!16 = !DIExpression() +!16 = !DIExpression(DW_OP_deref) !17 = !DILocation(line: 4, column: 12, scope: !4) !18 = !DILocation(line: 8, column: 1, scope: !4) Index: test/DebugInfo/Mips/dsr-fixed-objects.ll =================================================================== --- test/DebugInfo/Mips/dsr-fixed-objects.ll +++ test/DebugInfo/Mips/dsr-fixed-objects.ll @@ -55,11 +55,11 @@ } -; F1: DW_AT_location [DW_FORM_sec_offset] (0x00000033) +; F1: DW_AT_location [DW_FORM_sec_offset] (0x00000032) ; F1: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000006b] = "x") ; x -> DW_OP_reg1(51) -; F1: 0x00000033: Beginning address offset: 0x0000000000000080 +; F1: 0x00000032: Beginning address offset: 0x0000000000000080 ; F1: Ending address offset: 0x0000000000000088 ; F1: Location description: 51 Index: test/DebugInfo/X86/array.ll =================================================================== --- test/DebugInfo/X86/array.ll +++ test/DebugInfo/X86/array.ll @@ -35,13 +35,13 @@ %array = alloca [4 x i32], align 16 tail call void @llvm.dbg.value(metadata i32 %argc, i64 0, metadata !19, metadata !DIExpression()), !dbg !35 tail call void @llvm.dbg.value(metadata i8** %argv, i64 0, metadata !20, metadata !DIExpression()), !dbg !35 - tail call void @llvm.dbg.value(metadata [4 x i32]* %array, i64 0, metadata !21, metadata !DIExpression()), !dbg !36 + tail call void @llvm.dbg.value(metadata [4 x i32]* %array, i64 0, metadata !21, metadata !DIExpression(DW_OP_deref)), !dbg !36 %1 = bitcast [4 x i32]* %array to i8*, !dbg !36 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* bitcast ([4 x i32]* @main.array to i8*), i64 16, i32 16, i1 false), !dbg !36 - tail call void @llvm.dbg.value(metadata [4 x i32]* %array, i64 0, metadata !21, metadata !DIExpression()), !dbg !36 + tail call void @llvm.dbg.value(metadata [4 x i32]* %array, i64 0, metadata !21, metadata !DIExpression(DW_OP_deref)), !dbg !36 %2 = getelementptr inbounds [4 x i32], [4 x i32]* %array, i64 0, i64 0, !dbg !37 call void @f(i32* %2), !dbg !37 - tail call void @llvm.dbg.value(metadata [4 x i32]* %array, i64 0, metadata !21, metadata !DIExpression()), !dbg !36 + tail call void @llvm.dbg.value(metadata [4 x i32]* %array, i64 0, metadata !21, metadata !DIExpression(DW_OP_deref)), !dbg !36 %3 = load i32, i32* %2, align 16, !dbg !38, !tbaa !30 ret i32 %3, !dbg !38 } Index: test/DebugInfo/X86/dbg-value-const-byref.ll =================================================================== --- test/DebugInfo/X86/dbg-value-const-byref.ll +++ test/DebugInfo/X86/dbg-value-const-byref.ll @@ -56,7 +56,7 @@ %call1 = call i32 (...) @f1() #3, !dbg !19 call void @llvm.dbg.value(metadata i32 %call1, i64 0, metadata !10, metadata !DIExpression()), !dbg !19 store i32 %call1, i32* %i, align 4, !dbg !19, !tbaa !20 - call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !10, metadata !DIExpression()), !dbg !24 + call void @llvm.dbg.value(metadata i32* %i, i64 0, metadata !10, metadata !DIExpression(DW_OP_deref)), !dbg !24 call void @f2(i32* %i) #3, !dbg !24 ret i32 0, !dbg !25 } Index: test/DebugInfo/X86/debug-loc-asan.ll =================================================================== --- test/DebugInfo/X86/debug-loc-asan.ll +++ /dev/null @@ -1,182 +0,0 @@ -; RUN: llc -O0 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s - -; Verify that we have correct debug info for local variables in code -; instrumented with AddressSanitizer. - -; Generated from the source file test.cc: -; int bar(int y) { -; return y + 2; -; } -; with "clang++ -S -emit-llvm -fsanitize=address -O0 -g test.cc" - -; First, argument variable "y" resides in %rdi: -; CHECK: DEBUG_VALUE: bar:y <- %RDI - -; Then its address is stored in a location on a stack: -; CHECK: movq %rdi, [[OFFSET:[0-9]+]](%rsp) -; CHECK-NEXT: [[START_LABEL:.Ltmp[0-9]+]] -; CHECK-NEXT: DEBUG_VALUE: bar:y <- [%RSP+[[OFFSET]]] -; This location should be valid until the end of the function. - -; CHECK: .Ldebug_loc{{[0-9]+}}: -; We expect two location ranges for the variable. - -; First, its address is stored in %rdi: -; CHECK: .quad .Lfunc_begin0-.Lfunc_begin0 -; CHECK-NEXT: .quad [[START_LABEL]]-.Lfunc_begin0 -; CHECK: DW_OP_breg5 - -; Then it's addressed via %rsp: -; CHECK: .quad [[START_LABEL]]-.Lfunc_begin0 -; CHECK-NEXT: .Lfunc_end0-.Lfunc_begin0 -; CHECK: DW_OP_breg7 -; CHECK-NEXT: [[OFFSET]] -; CHECK: DW_OP_deref - -; ModuleID = 'test.cc' -target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-unknown-linux-gnu" - -@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }] -@__asan_option_detect_stack_use_after_return = external global i32 -@__asan_gen_ = private unnamed_addr constant [16 x i8] c"1 32 4 6 y.addr\00", align 1 - -; Function Attrs: nounwind sanitize_address uwtable -define i32 @_Z3bari(i32 %y) #0 !dbg !4 { -entry: - %MyAlloca = alloca [64 x i8], align 32 - %0 = ptrtoint [64 x i8]* %MyAlloca to i64 - %1 = load i32, i32* @__asan_option_detect_stack_use_after_return - %2 = icmp ne i32 %1, 0 - br i1 %2, label %3, label %5 - -;