Skip to content

Commit cf0e32d

Browse files
committed
[CodeView] Properly handle a DISubprogram in getScopeIndex.
Differential Revision: https://reviews.llvm.org/D113142
1 parent a4ba780 commit cf0e32d

File tree

2 files changed

+137
-1
lines changed

2 files changed

+137
-1
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,16 @@ std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) {
341341

342342
TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
343343
// No scope means global scope and that uses the zero index.
344-
if (!Scope || isa<DIFile>(Scope))
344+
//
345+
// We also use zero index when the scope is a DISubprogram
346+
// to suppress the emission of LF_STRING_ID for the function,
347+
// which can trigger a link-time error with the linker in
348+
// VS2019 version 16.11.2 or newer.
349+
// Note, however, skipping the debug info emission for the DISubprogram
350+
// is a temporary fix. The root issue here is that we need to figure out
351+
// the proper way to encode a function nested in another function
352+
// (as introduced by the Fortran 'contains' keyword) in CodeView.
353+
if (!Scope || isa<DIFile>(Scope) || isa<DISubprogram>(Scope))
345354
return TypeIndex();
346355

347356
assert(!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type");
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
; RUN: llc -o %t.obj %s -filetype=obj
2+
; RUN: llvm-pdbutil dump -symbols -types %t.obj | FileCheck %s
3+
;
4+
; The IR in this test derives from the following Fortran program
5+
; with inlining enabled:
6+
; program if_test
7+
; implicit none
8+
; integer, allocatable :: a
9+
; allocate(a)
10+
; call sub(a)
11+
; contains
12+
; subroutine sub(aa)
13+
; implicit none
14+
; integer :: aa, bb
15+
; bb = 1
16+
; aa = bb
17+
; end subroutine sub
18+
; end program if_test
19+
;
20+
; CHECK: [[proc_t:.*]] | LF_PROCEDURE
21+
;
22+
; CHECK: [[func_id_sub:.*]] | LF_FUNC_ID
23+
; CHECK-NEXT: name = SUB, type = [[proc_t]], parent scope = <no type>
24+
;
25+
; CHECK: [[func_id_if_test:.*]] | LF_FUNC_ID
26+
; CHECK-NEXT: name = IF_TEST, type = [[proc_t]], parent scope = <no type>
27+
;
28+
; CHECK: S_GPROC32_ID [size = {{.*}}] `IF_TEST`
29+
; CHECK-NEXT: parent
30+
; CHECK-NEXT: type = `[[func_id_if_test]] (IF_TEST)`
31+
;
32+
; ModuleID = 'tr1.f90'
33+
source_filename = "tr1.f90"
34+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
35+
target triple = "x86_64-pc-windows-msvc"
36+
37+
@"IF_TEST$A" = internal global i32* null, align 8, !dbg !0
38+
@0 = internal unnamed_addr constant i32 65536
39+
@1 = internal unnamed_addr constant i32 2
40+
41+
; Function Attrs: nounwind uwtable
42+
define void @MAIN__() local_unnamed_addr #0 !dbg !2 {
43+
alloca_0:
44+
%func_result = tail call i32 @for_set_fpe_(i32* nonnull @0) #4, !dbg !22
45+
%func_result2 = tail call i32 @for_set_reentrancy(i32* nonnull @1) #4, !dbg !22
46+
%func_result4 = tail call i32 @for_alloc_allocatable(i64 4, i8** bitcast (i32** @"IF_TEST$A" to i8**), i32 262144) #4, !dbg !23
47+
%"IF_TEST$A_fetch.1" = load i32*, i32** @"IF_TEST$A", align 8, !dbg !24, !tbaa !25
48+
call void @llvm.dbg.declare(metadata i32* %"IF_TEST$A_fetch.1", metadata !29, metadata !DIExpression()), !dbg !33
49+
call void @llvm.dbg.value(metadata i32 1, metadata !32, metadata !DIExpression()), !dbg !35
50+
store i32 1, i32* %"IF_TEST$A_fetch.1", align 1, !dbg !36, !tbaa !37, !alias.scope !41
51+
ret void, !dbg !44
52+
}
53+
54+
; Function Attrs: mustprogress nofree norecurse nosync nounwind uwtable willreturn writeonly
55+
define void @IF_TEST_ip_SUB(i32* noalias nocapture dereferenceable(4) %AA) local_unnamed_addr #1 !dbg !30 {
56+
alloca_1:
57+
call void @llvm.dbg.declare(metadata i32* %AA, metadata !29, metadata !DIExpression()), !dbg !45
58+
call void @llvm.dbg.value(metadata i32 1, metadata !32, metadata !DIExpression()), !dbg !46
59+
store i32 1, i32* %AA, align 1, !dbg !47, !tbaa !37
60+
ret void, !dbg !48
61+
}
62+
63+
declare i32 @for_set_fpe_(i32* nocapture readonly) local_unnamed_addr
64+
65+
; Function Attrs: nofree
66+
declare i32 @for_set_reentrancy(i32* nocapture readonly) local_unnamed_addr #2
67+
68+
; Function Attrs: nofree
69+
declare i32 @for_alloc_allocatable(i64, i8** nocapture, i32) local_unnamed_addr #2
70+
71+
; Function Attrs: mustprogress nofree nosync nounwind readnone speculatable willreturn
72+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #3
73+
74+
; Function Attrs: mustprogress nofree nosync nounwind readnone speculatable willreturn
75+
declare void @llvm.dbg.value(metadata, metadata, metadata) #3
76+
77+
attributes #0 = { nounwind uwtable "denormal-fp-math"="preserve_sign,preserve_sign" "frame-pointer"="none" "intel-lang"="fortran" "min-legal-vector-width"="0" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" }
78+
attributes #1 = { mustprogress nofree norecurse nosync nounwind uwtable willreturn writeonly "denormal-fp-math"="preserve_sign,preserve_sign" "frame-pointer"="none" "intel-lang"="fortran" "min-legal-vector-width"="0" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" }
79+
attributes #2 = { nofree "intel-lang"="fortran" }
80+
attributes #3 = { mustprogress nofree nosync nounwind readnone speculatable willreturn }
81+
attributes #4 = { nounwind }
82+
83+
!llvm.module.flags = !{!11, !12, !13}
84+
!llvm.dbg.cu = !{!6}
85+
!omp_offload.info = !{}
86+
87+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
88+
!1 = distinct !DIGlobalVariable(name: "A", linkageName: "IF_TEST$A", scope: !2, file: !3, line: 11, type: !9, isLocal: true, isDefinition: true)
89+
!2 = distinct !DISubprogram(name: "IF_TEST", linkageName: "MAIN__", scope: !3, file: !3, line: 9, type: !4, scopeLine: 9, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, unit: !6, retainedNodes: !8)
90+
!3 = !DIFile(filename: "tr1.f90", directory: "d:\\iusers\\cchen15\\examples\\tests\\jr14335")
91+
!4 = !DISubroutineType(types: !5)
92+
!5 = !{null}
93+
!6 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Intel(R) Fortran 22.0-1087", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !7, splitDebugInlining: false, nameTableKind: None)
94+
!7 = !{!0}
95+
!8 = !{}
96+
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64)
97+
!10 = !DIBasicType(name: "INTEGER*4", size: 32, encoding: DW_ATE_signed)
98+
!11 = !{i32 7, !"PIC Level", i32 2}
99+
!12 = !{i32 2, !"Debug Info Version", i32 3}
100+
!13 = !{i32 2, !"CodeView", i32 1}
101+
!22 = !DILocation(line: 9, scope: !2)
102+
!23 = !DILocation(line: 12, scope: !2)
103+
!24 = !DILocation(line: 14, scope: !2)
104+
!25 = !{!26, !26, i64 0}
105+
!26 = !{!"ifx$unique_sym$1", !27, i64 0}
106+
!27 = !{!"Generic Fortran Symbol", !28, i64 0}
107+
!28 = !{!"ifx$root$1$MAIN__"}
108+
!29 = !DILocalVariable(name: "AA", arg: 1, scope: !30, file: !3, line: 17, type: !10)
109+
!30 = distinct !DISubprogram(name: "SUB", linkageName: "IF_TEST_ip_SUB", scope: !2, file: !3, line: 17, type: !4, scopeLine: 17, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !31)
110+
!31 = !{!29, !32}
111+
!32 = !DILocalVariable(name: "BB", scope: !30, file: !3, line: 19, type: !10)
112+
!33 = !DILocation(line: 17, scope: !30, inlinedAt: !34)
113+
!34 = distinct !DILocation(line: 14, scope: !2)
114+
!35 = !DILocation(line: 0, scope: !30, inlinedAt: !34)
115+
!36 = !DILocation(line: 21, scope: !30, inlinedAt: !34)
116+
!37 = !{!38, !38, i64 0}
117+
!38 = !{!"ifx$unique_sym$3", !39, i64 0}
118+
!39 = !{!"Generic Fortran Symbol", !40, i64 0}
119+
!40 = !{!"ifx$root$2$IF_TEST_ip_SUB"}
120+
!41 = !{!42}
121+
!42 = distinct !{!42, !43, !"IF_TEST_ip_SUB: %AA"}
122+
!43 = distinct !{!43, !"IF_TEST_ip_SUB"}
123+
!44 = !DILocation(line: 16, scope: !2)
124+
!45 = !DILocation(line: 17, scope: !30)
125+
!46 = !DILocation(line: 0, scope: !30)
126+
!47 = !DILocation(line: 21, scope: !30)
127+
!48 = !DILocation(line: 22, scope: !30)

0 commit comments

Comments
 (0)