summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2016-06-09 00:29:00 +0000
committerReid Kleckner <rnk@google.com>2016-06-09 00:29:00 +0000
commit6d1d27542fd66465f5e1e3e4248910b15f47a8b2 (patch)
tree91fd333bb117ddc096a851fa5b98ff69256168e6
parent36eb047792aaa77a11d710e1ee4f2e9930464925 (diff)
downloadbcm5719-llvm-6d1d27542fd66465f5e1e3e4248910b15f47a8b2.tar.gz
bcm5719-llvm-6d1d27542fd66465f5e1e3e4248910b15f47a8b2.zip
[codeview] Skip DIGlobalVariables with no variable
They have probably been discarded during optimization. llvm-svn: 272231
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp5
-rw-r--r--llvm/test/DebugInfo/COFF/globals-discarded.ll35
2 files changed, 38 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 828f89e9254..8920d20ad39 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -1317,7 +1317,7 @@ void CodeViewDebug::emitDebugInfoForGlobals() {
switchToDebugSectionForSymbol(nullptr);
MCSymbol *EndLabel = nullptr;
for (const DIGlobalVariable *G : CU->getGlobalVariables()) {
- if (const auto *GV = dyn_cast<GlobalVariable>(G->getVariable()))
+ if (const auto *GV = dyn_cast_or_null<GlobalVariable>(G->getVariable())) {
if (!GV->hasComdat()) {
if (!EndLabel) {
OS.AddComment("Symbol subsection for globals");
@@ -1325,6 +1325,7 @@ void CodeViewDebug::emitDebugInfoForGlobals() {
}
emitDebugInfoForGlobal(G, Asm->getSymbol(GV));
}
+ }
}
if (EndLabel)
endCVSubsection(EndLabel);
@@ -1332,7 +1333,7 @@ void CodeViewDebug::emitDebugInfoForGlobals() {
// Second, emit each global that is in a comdat into its own .debug$S
// section along with its own symbol substream.
for (const DIGlobalVariable *G : CU->getGlobalVariables()) {
- if (const auto *GV = dyn_cast<GlobalVariable>(G->getVariable())) {
+ if (const auto *GV = dyn_cast_or_null<GlobalVariable>(G->getVariable())) {
if (GV->hasComdat()) {
MCSymbol *GVSym = Asm->getSymbol(GV);
OS.AddComment("Symbol subsection for " +
diff --git a/llvm/test/DebugInfo/COFF/globals-discarded.ll b/llvm/test/DebugInfo/COFF/globals-discarded.ll
new file mode 100644
index 00000000000..6699039c29f
--- /dev/null
+++ b/llvm/test/DebugInfo/COFF/globals-discarded.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s | FileCheck %s
+
+; This tests that we don't emit information about globals that were discarded
+; during optimization. We should only see one global symbol record.
+
+; CHECK: .short 4365 # Record kind: S_GDATA32
+; CHECK: .long 117 # Type
+; CHECK: .secrel32 x # DataOffset
+; CHECK: .secidx x # Segment
+; CHECK: .asciz "x" # Name
+; CHECK-NOT: S_GDATA32
+
+; ModuleID = 't.ii'
+source_filename = "t.ii"
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.0.0"
+
+@x = global i32 42
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!35, !36, !37}
+!llvm.ident = !{!38}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 272215) (llvm/trunk 272226)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !3)
+!1 = !DIFile(filename: "t.c", directory: "foo")
+!2 = !{}
+!3 = !{!4, !6}
+!4 = distinct !DIGlobalVariable(name: "_OptionsStorage", scope: !0, file: !1, line: 3, type: !5, isLocal: true, isDefinition: true)
+!5 = !DIBasicType(name: "unsigned int", size: 32, align: 32, encoding: DW_ATE_unsigned)
+!6 = distinct !DIGlobalVariable(name: "x", scope: !0, file: !1, line: 4, type: !5, isLocal: true, isDefinition: true, variable: i32* @x)
+
+!35 = !{i32 2, !"CodeView", i32 1}
+!36 = !{i32 2, !"Debug Info Version", i32 3}
+!37 = !{i32 1, !"PIC Level", i32 2}
+!38 = !{!"clang version 3.9.0 (trunk 272215) (llvm/trunk 272226)"}
OpenPOWER on IntegriCloud