Skip to content

Commit 6d1d275

Browse files
committed
[codeview] Skip DIGlobalVariables with no variable
They have probably been discarded during optimization. llvm-svn: 272231
1 parent 36eb047 commit 6d1d275

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,22 +1317,23 @@ void CodeViewDebug::emitDebugInfoForGlobals() {
13171317
switchToDebugSectionForSymbol(nullptr);
13181318
MCSymbol *EndLabel = nullptr;
13191319
for (const DIGlobalVariable *G : CU->getGlobalVariables()) {
1320-
if (const auto *GV = dyn_cast<GlobalVariable>(G->getVariable()))
1320+
if (const auto *GV = dyn_cast_or_null<GlobalVariable>(G->getVariable())) {
13211321
if (!GV->hasComdat()) {
13221322
if (!EndLabel) {
13231323
OS.AddComment("Symbol subsection for globals");
13241324
EndLabel = beginCVSubsection(ModuleSubstreamKind::Symbols);
13251325
}
13261326
emitDebugInfoForGlobal(G, Asm->getSymbol(GV));
13271327
}
1328+
}
13281329
}
13291330
if (EndLabel)
13301331
endCVSubsection(EndLabel);
13311332

13321333
// Second, emit each global that is in a comdat into its own .debug$S
13331334
// section along with its own symbol substream.
13341335
for (const DIGlobalVariable *G : CU->getGlobalVariables()) {
1335-
if (const auto *GV = dyn_cast<GlobalVariable>(G->getVariable())) {
1336+
if (const auto *GV = dyn_cast_or_null<GlobalVariable>(G->getVariable())) {
13361337
if (GV->hasComdat()) {
13371338
MCSymbol *GVSym = Asm->getSymbol(GV);
13381339
OS.AddComment("Symbol subsection for " +
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llc < %s | FileCheck %s
2+
3+
; This tests that we don't emit information about globals that were discarded
4+
; during optimization. We should only see one global symbol record.
5+
6+
; CHECK: .short 4365 # Record kind: S_GDATA32
7+
; CHECK: .long 117 # Type
8+
; CHECK: .secrel32 x # DataOffset
9+
; CHECK: .secidx x # Segment
10+
; CHECK: .asciz "x" # Name
11+
; CHECK-NOT: S_GDATA32
12+
13+
; ModuleID = 't.ii'
14+
source_filename = "t.ii"
15+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
16+
target triple = "x86_64-pc-windows-msvc19.0.0"
17+
18+
@x = global i32 42
19+
20+
!llvm.dbg.cu = !{!0}
21+
!llvm.module.flags = !{!35, !36, !37}
22+
!llvm.ident = !{!38}
23+
24+
!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)
25+
!1 = !DIFile(filename: "t.c", directory: "foo")
26+
!2 = !{}
27+
!3 = !{!4, !6}
28+
!4 = distinct !DIGlobalVariable(name: "_OptionsStorage", scope: !0, file: !1, line: 3, type: !5, isLocal: true, isDefinition: true)
29+
!5 = !DIBasicType(name: "unsigned int", size: 32, align: 32, encoding: DW_ATE_unsigned)
30+
!6 = distinct !DIGlobalVariable(name: "x", scope: !0, file: !1, line: 4, type: !5, isLocal: true, isDefinition: true, variable: i32* @x)
31+
32+
!35 = !{i32 2, !"CodeView", i32 1}
33+
!36 = !{i32 2, !"Debug Info Version", i32 3}
34+
!37 = !{i32 1, !"PIC Level", i32 2}
35+
!38 = !{!"clang version 3.9.0 (trunk 272215) (llvm/trunk 272226)"}

0 commit comments

Comments
 (0)