Skip to content

Commit e392865

Browse files
committed
Temporary fix for D85085 debug_loc bug with basic block sections.
Until then, this one line fix removes the assert fail with basic block sections with debug info. Bug tracking this: #47549 This fix does not generate loc list or DW_AT_const_value if the argument is mentioned in a different section than the start of the function. Temporarily fixes bugzilla : https://bugs.llvm.org/show_bug.cgi?id=47549 Differential Revision: https://reviews.llvm.org/D87787
1 parent 506b617 commit e392865

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,16 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
220220
// doing that violates the ranges that are calculated in the history map.
221221
// However, we currently do not emit debug values for constant arguments
222222
// directly at the start of the function, so this code is still useful.
223+
// FIXME: If the first mention of an argument is in a unique section basic
224+
// block, we cannot always assign the CurrentFnBeginLabel as it lies in a
225+
// different section. Temporarily, we disable generating loc list
226+
// information or DW_AT_const_value when the block is in a different
227+
// section.
223228
const DILocalVariable *DIVar =
224229
Entries.front().getInstr()->getDebugVariable();
225230
if (DIVar->isParameter() &&
226-
getDISubprogram(DIVar->getScope())->describes(&MF->getFunction())) {
231+
getDISubprogram(DIVar->getScope())->describes(&MF->getFunction()) &&
232+
Entries.front().getInstr()->getParent()->sameSection(&MF->front())) {
227233
if (!IsDescribedByReg(Entries.front().getInstr()))
228234
LabelsBeforeInsn[Entries.front().getInstr()] = Asm->getFunctionBegin();
229235
if (Entries.front().getInstr()->getDebugExpression()->isFragment()) {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
;; The dbg value for buflen in the non-entry basic block spans the entire
2+
;; function and is emitted as DW_AT_const_value. Even with basic block
3+
;; sections, this can be done as the entire function is represented as ranges.
4+
;; FIXME: Basic block sections should have the same behavior as the default.
5+
6+
; RUN: llc %s --dwarf-version=4 --basic-block-sections=none -filetype=obj -o %t
7+
; RUN: llvm-dwarfdump %t | FileCheck %s
8+
; RUN: llc %s --dwarf-version=4 --basic-block-sections=all -filetype=obj -o %t
9+
; RUN: llvm-dwarfdump %t | FileCheck --check-prefix=MISSING %s
10+
11+
; CHECK: DW_AT_const_value (157)
12+
; CHECK-NEXT: DW_AT_name ("buflen")
13+
; MISSING-NOT: DW_AT_const_value (157)
14+
15+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
16+
target triple = "x86_64-grtev4-linux-gnu"
17+
18+
define dso_local void @_ZL4ncatPcjz(i8* %0, i32 %1, ...) unnamed_addr align 32 !dbg !22 {
19+
.critedge3:
20+
call void @llvm.dbg.value(metadata i32 157, metadata !27, metadata !DIExpression()), !dbg !46
21+
call void @llvm.va_start(i8* nonnull undef), !dbg !47
22+
br label %2
23+
24+
2: ; preds = %2, %.critedge3
25+
br label %2
26+
}
27+
28+
; Function Attrs: nounwind
29+
declare void @llvm.va_start(i8*) #1
30+
31+
; Function Attrs: nounwind readnone speculatable willreturn
32+
declare void @llvm.dbg.value(metadata, metadata, metadata) #2
33+
34+
attributes #1 = { nounwind }
35+
attributes #2 = { nounwind readnone speculatable willreturn }
36+
37+
!llvm.dbg.cu = !{!0}
38+
!llvm.module.flags = !{!20, !21}
39+
40+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2)
41+
!1 = !DIFile(filename: "bug.cpp", directory: "/proc/self/cwd")
42+
!2 = !{!3, !6, !9, !10, !11, !13, !16, !17, !15}
43+
!3 = !DIDerivedType(tag: DW_TAG_typedef, name: "int32_t", file: !4, line: 38, baseType: !5)
44+
!4 = !DIFile(filename: "stdint.h", directory: "/proc/self/cwd")
45+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
46+
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
47+
!7 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8)
48+
!8 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)
49+
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
50+
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
51+
!11 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint32_t", file: !4, line: 51, baseType: !12)
52+
!12 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
53+
!13 = !DIDerivedType(tag: DW_TAG_typedef, name: "UChar", file: !14, line: 372, baseType: !15)
54+
!14 = !DIFile(filename: "umachine.h", directory: "/proc/self/cwd")
55+
!15 = !DIBasicType(name: "char16_t", size: 16, encoding: DW_ATE_UTF)
56+
!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !3, size: 64)
57+
!17 = !DIDerivedType(tag: DW_TAG_typedef, name: "UBool", file: !14, line: 261, baseType: !18)
58+
!18 = !DIDerivedType(tag: DW_TAG_typedef, name: "int8_t", file: !4, line: 36, baseType: !19)
59+
!19 = !DIBasicType(name: "signed char", size: 8, encoding: DW_ATE_signed_char)
60+
!20 = !{i32 2, !"Debug Info Version", i32 3}
61+
!21 = !{i32 7, !"PIC Level", i32 2}
62+
!22 = distinct !DISubprogram(name: "ncat", linkageName: "_ZL4ncatPcjz", scope: !1, file: !1, line: 37, type: !23, scopeLine: 37, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !25)
63+
!23 = !DISubroutineType(types: !24)
64+
!24 = !{!3, !9, !11, null}
65+
!25 = !{!26, !27, !28, !41, !42, !43, !44}
66+
!26 = !DILocalVariable(name: "buffer", arg: 1, scope: !22, file: !1, line: 37, type: !9)
67+
!27 = !DILocalVariable(name: "buflen", arg: 2, scope: !22, file: !1, line: 37, type: !11)
68+
!28 = !DILocalVariable(name: "args", scope: !22, file: !1, line: 38, type: !29)
69+
!29 = !DIDerivedType(tag: DW_TAG_typedef, name: "va_list", file: !30, line: 14, baseType: !31)
70+
!30 = !DIFile(filename: "stdarg.h", directory: "/proc/self/cwd")
71+
!31 = !DIDerivedType(tag: DW_TAG_typedef, name: "__builtin_va_list", file: !1, line: 38, baseType: !32)
72+
!32 = !DICompositeType(tag: DW_TAG_array_type, baseType: !33, size: 192, elements: !39)
73+
!33 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "__va_list_tag", file: !1, line: 38, size: 192, flags: DIFlagTypePassByValue, elements: !34, identifier: "_ZTS13__va_list_tag")
74+
!34 = !{!35, !36, !37, !38}
75+
!35 = !DIDerivedType(tag: DW_TAG_member, name: "gp_offset", scope: !33, file: !1, line: 38, baseType: !12, size: 32)
76+
!36 = !DIDerivedType(tag: DW_TAG_member, name: "fp_offset", scope: !33, file: !1, line: 38, baseType: !12, size: 32, offset: 32)
77+
!37 = !DIDerivedType(tag: DW_TAG_member, name: "overflow_arg_area", scope: !33, file: !1, line: 38, baseType: !10, size: 64, offset: 64)
78+
!38 = !DIDerivedType(tag: DW_TAG_member, name: "reg_save_area", scope: !33, file: !1, line: 38, baseType: !10, size: 64, offset: 128)
79+
!39 = !{!40}
80+
!40 = !DISubrange(count: 1)
81+
!41 = !DILocalVariable(name: "str", scope: !22, file: !1, line: 39, type: !9)
82+
!42 = !DILocalVariable(name: "p", scope: !22, file: !1, line: 40, type: !9)
83+
!43 = !DILocalVariable(name: "e", scope: !22, file: !1, line: 41, type: !6)
84+
!44 = !DILocalVariable(name: "c", scope: !45, file: !1, line: 49, type: !8)
85+
!45 = distinct !DILexicalBlock(scope: !22, file: !1, line: 48, column: 45)
86+
!46 = !DILocation(line: 0, scope: !22)
87+
!47 = !DILocation(line: 47, column: 3, scope: !22)

0 commit comments

Comments
 (0)