summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp9
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h2
-rw-r--r--llvm/test/DebugInfo/X86/global-expression.ll41
4 files changed, 51 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 2eb0157f1e0..4a5c7b324d6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -230,8 +230,13 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
addOpAddress(*Loc, Sym);
}
}
- if (Expr)
- DwarfExpr->addExpression(Expr);
+ // Global variables attached to symbols are memory locations.
+ // It would be better if this were unconditional, but malformed input that
+ // mixes non-fragments and fragments for the same variable is too expensive
+ // to detect in the verifier.
+ if (!DwarfExpr->isMemoryLocation())
+ DwarfExpr->setMemoryLocationKind();
+ DwarfExpr->addExpression(Expr);
}
if (Loc)
addBlock(*VariableDIE, dwarf::DW_AT_location, DwarfExpr->finalize());
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index 379e9b14569..043d02e3ce4 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -361,7 +361,7 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
break;
case dwarf::DW_OP_deref:
assert(LocationKind != Register);
- if (LocationKind != Memory && isMemoryLocation(ExprCursor))
+ if (LocationKind != Memory && ::isMemoryLocation(ExprCursor))
// Turning this into a memory location description makes the deref
// implicit.
LocationKind = Memory;
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
index ea5cbc40ba3..7d6d45e64d6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
@@ -211,6 +211,8 @@ public:
/// Emit an unsigned constant.
void addUnsignedConstant(const APInt &Value);
+ bool isMemoryLocation() const { return LocationKind == Memory; }
+
/// Lock this down to become a memory location description.
void setMemoryLocationKind() {
assert(LocationKind == Unknown);
diff --git a/llvm/test/DebugInfo/X86/global-expression.ll b/llvm/test/DebugInfo/X86/global-expression.ll
new file mode 100644
index 00000000000..fdae9bd5fa2
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/global-expression.ll
@@ -0,0 +1,41 @@
+; RUN: llc -mtriple=x86_64-apple-darwin %s -o - -filetype=obj | \
+; RUN: llvm-dwarfdump --name i --name indirect - | FileCheck %s
+;
+; This is a hand-crafted testcase generated from:
+; int i = 23;
+; int *indirect = &i;
+
+; CHECK: DW_TAG_variable
+; CHECK: DW_AT_name ("i")
+; CHECK: DW_AT_location (DW_OP_addr 0x8, DW_OP_deref)
+; CHECK: DW_TAG_variable
+; CHECK: DW_AT_name ("indirect")
+; CHECK: DW_AT_location (DW_OP_addr 0x8
+
+source_filename = "global-deref.c"
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.13.0"
+
+@i = global i32 23, align 4
+@indirect = global i32* @i, align 8, !dbg !6, !dbg !0, !dbg !14, !dbg !15
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!10, !11, !12, !13}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression(DW_OP_deref))
+!1 = distinct !DIGlobalVariable(name: "i", scope: !2, file: !3, line: 1, type: !9, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "global-deref.c", directory: "/")
+!4 = !{}
+!5 = !{!0, !6}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = distinct !DIGlobalVariable(name: "indirect", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
+!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !{i32 2, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{i32 1, !"wchar_size", i32 4}
+!13 = !{i32 7, !"PIC Level", i32 2}
+; This is malformed, but too expensive to detect in the verifier.
+!14 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!15 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression(DW_OP_LLVM_fragment, 0, 1))
OpenPOWER on IntegriCloud