Skip to content

Commit bf6ed35

Browse files
committed
Reland "[AsmPrinter] fix -disable-debug-info option"
This reverts commit 105ed27, and removes the offending line from the tests.
1 parent 2e26459 commit bf6ed35

File tree

3 files changed

+72
-15
lines changed

3 files changed

+72
-15
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ using namespace llvm;
131131

132132
#define DEBUG_TYPE "asm-printer"
133133

134+
// FIXME: this option currently only applies to DWARF, and not CodeView, tables
135+
static cl::opt<bool>
136+
DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
137+
cl::desc("Disable debug info printing"));
138+
134139
static const char *const DWARFGroupName = "dwarf";
135140
static const char *const DWARFGroupDescription = "DWARF Emission";
136141
static const char *const DbgTimerName = "emit";
@@ -232,9 +237,11 @@ void AsmPrinter::EmitToStreamer(MCStreamer &S, const MCInst &Inst) {
232237
}
233238

234239
void AsmPrinter::emitInitialRawDwarfLocDirective(const MachineFunction &MF) {
235-
assert(DD && "Dwarf debug file is not defined.");
236-
assert(OutStreamer->hasRawTextSupport() && "Expected assembly output mode.");
237-
(void)DD->emitInitialLocDirective(MF, /*CUID=*/0);
240+
if (DD) {
241+
assert(OutStreamer->hasRawTextSupport() &&
242+
"Expected assembly output mode.");
243+
(void)DD->emitInitialLocDirective(MF, /*CUID=*/0);
244+
}
238245
}
239246

240247
/// getCurrentSection() - Return the current section we are emitting to.
@@ -262,6 +269,9 @@ bool AsmPrinter::doInitialization(Module &M) {
262269

263270
OutStreamer->InitSections(false);
264271

272+
if (DisableDebugInfoPrinting)
273+
MMI->setDebugInfoAvailability(false);
274+
265275
// Emit the version-min deployment target directive if needed.
266276
//
267277
// FIXME: If we end up with a collection of these sorts of Darwin-specific
@@ -314,10 +324,12 @@ bool AsmPrinter::doInitialization(Module &M) {
314324
CodeViewLineTablesGroupDescription);
315325
}
316326
if (!EmitCodeView || M.getDwarfVersion()) {
317-
DD = new DwarfDebug(this);
318-
Handlers.emplace_back(std::unique_ptr<DwarfDebug>(DD), DbgTimerName,
319-
DbgTimerDescription, DWARFGroupName,
320-
DWARFGroupDescription);
327+
if (!DisableDebugInfoPrinting) {
328+
DD = new DwarfDebug(this);
329+
Handlers.emplace_back(std::unique_ptr<DwarfDebug>(DD), DbgTimerName,
330+
DbgTimerDescription, DWARFGroupName,
331+
DWARFGroupDescription);
332+
}
321333
}
322334
}
323335

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ using namespace llvm;
6767

6868
STATISTIC(NumCSParams, "Number of dbg call site params created");
6969

70-
static cl::opt<bool>
71-
DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
72-
cl::desc("Disable debug info printing"));
73-
7470
static cl::opt<bool> UseDwarfRangesBaseAddressSpecifier(
7571
"use-dwarf-ranges-base-address-specifier", cl::Hidden,
7672
cl::desc("Use base address specifiers in debug_ranges"), cl::init(false));
@@ -1122,7 +1118,7 @@ sortGlobalExprs(SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
11221118
void DwarfDebug::beginModule(Module *M) {
11231119
DebugHandlerBase::beginModule(M);
11241120

1125-
if (!Asm || !MMI->hasDebugInfo() || DisableDebugInfoPrinting)
1121+
if (!Asm || !MMI->hasDebugInfo())
11261122
return;
11271123

11281124
unsigned NumDebugCUs = std::distance(M->debug_compile_units_begin(),
@@ -1390,9 +1386,8 @@ void DwarfDebug::endModule() {
13901386
}
13911387

13921388
// If we aren't actually generating debug info (check beginModule -
1393-
// conditionalized on !DisableDebugInfoPrinting and the presence of the
1394-
// llvm.dbg.cu metadata node)
1395-
if (!Asm || !MMI->hasDebugInfo() || DisableDebugInfoPrinting)
1389+
// conditionalized on the presence of the llvm.dbg.cu metadata node)
1390+
if (!Asm || !MMI->hasDebugInfo())
13961391
return;
13971392

13981393
// Finalize the debug info for the module.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; RUN: llc -disable-debug-info-print=true -exception-model=dwarf -o - %s | FileCheck %s
2+
; RUN: llc -disable-debug-info-print=true -exception-model=sjlj -o - %s | FileCheck %s --check-prefix=SJLJ-CHECK
3+
4+
define i16 @main() nounwind !dbg !7 {
5+
entry:
6+
ret i16 0, !dbg !9
7+
}
8+
9+
define i16 @helper() !dbg !10 {
10+
entry:
11+
ret i16 0, !dbg !11
12+
}
13+
14+
15+
; CHECK: main
16+
; CHECK-NOT: cfi_startproc
17+
; CHECK-NOT: .file
18+
; CHECK-NOT: .loc
19+
; CHECK: helper
20+
; CHECK: cfi_startproc
21+
; CHECK-NOT: .file
22+
; CHECK-NOT: .loc
23+
; CHECK: cfi_endproc
24+
25+
; SJLJ-CHECK: main
26+
; SJLJ-CHECK-NOT: cfi_startproc
27+
; SJLJ-CHECK-NOT: .file
28+
; SJLJ-CHECK-NOT: .loc
29+
; SJLJ-CHECK: helper
30+
; SJLJ-CHECK-NOT: cfi_startproc
31+
; SJLJ-CHECK-NOT: .file
32+
; SJLJ-CHECK-NOT: .loc
33+
34+
35+
!llvm.dbg.cu = !{!0}
36+
!llvm.module.flags = !{!3, !4, !5}
37+
!llvm.ident = !{!6}
38+
39+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, splitDebugInlining: false, nameTableKind: None)
40+
!1 = !DIFile(filename: "unwind-tables.c", directory: "/tmp")
41+
!2 = !{}
42+
!3 = !{i32 7, !"Dwarf Version", i32 4}
43+
!4 = !{i32 2, !"Debug Info Version", i32 3}
44+
!5 = !{i32 1, !"wchar_size", i32 4}
45+
!6 = !{!"clang version 12.0.0"}
46+
!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
47+
!8 = !DISubroutineType(types: !2)
48+
!9 = !DILocation(line: 2, column: 3, scope: !7)
49+
!10 = distinct !DISubprogram(name: "helper", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
50+
!11 = !DILocation(line: 2, column: 3, scope: !10)

0 commit comments

Comments
 (0)