Skip to content

Commit bd79e28

Browse files
Merge pull request #6313 from felipepiovezan/felipe/cherry-pick-recursive-subprogram
[cherry-pick][debug-info][codegen] Prevent creation of self-referential SP node
2 parents d712748 + 490a57d commit bd79e28

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,10 +4209,10 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
42094209
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
42104210

42114211
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
4212+
llvm::DISubroutineType *STy = getOrCreateFunctionType(D, FnType, Unit);
42124213
llvm::DISubprogram *SP = DBuilder.createFunction(
4213-
FDContext, Name, LinkageName, Unit, LineNo,
4214-
getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
4215-
TParamsArray.get(), getFunctionDeclaration(D), nullptr, Annotations);
4214+
FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags,
4215+
SPFlags, TParamsArray.get(), nullptr, nullptr, Annotations);
42164216

42174217
if (IsDeclForCallSite)
42184218
Fn->setSubprogram(SP);

llvm/docs/LangRef.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5672,11 +5672,12 @@ retained, even if their IR counterparts are optimized out of the IR. The
56725672

56735673
.. _DISubprogramDeclaration:
56745674

5675-
When ``isDefinition: false``, subprograms describe a declaration in the type
5676-
tree as opposed to a definition of a function. If the scope is a composite
5677-
type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``,
5678-
then the subprogram declaration is uniqued based only on its ``linkageName:``
5679-
and ``scope:``.
5675+
When ``spFlags: DISPFlagDefinition`` is not present, subprograms describe a
5676+
declaration in the type tree as opposed to a definition of a function. In this
5677+
case, the ``declaration`` field must be empty. If the scope is a composite type
5678+
with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, then
5679+
the subprogram declaration is uniqued based only on its ``linkageName:`` and
5680+
``scope:``.
56805681

56815682
.. code-block:: text
56825683

@@ -5685,9 +5686,9 @@ and ``scope:``.
56855686
}
56865687

56875688
!0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
5688-
file: !2, line: 7, type: !3, isLocal: true,
5689-
isDefinition: true, scopeLine: 8,
5690-
containingType: !4,
5689+
file: !2, line: 7, type: !3,
5690+
spFlags: DISPFlagDefinition | DISPFlagLocalToUnit,
5691+
scopeLine: 8, containingType: !4,
56915692
virtuality: DW_VIRTUALITY_pure_virtual,
56925693
virtualIndex: 10, flags: DIFlagPrototyped,
56935694
isOptimized: true, unit: !5, templateParams: !6,

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,8 @@ void Verifier::visitDISubprogram(const DISubprogram &N) {
14161416
} else {
14171417
// Subprogram declarations (part of the type hierarchy).
14181418
CheckDI(!Unit, "subprogram declarations must not have a compile unit", &N);
1419+
CheckDI(!N.getRawDeclaration(),
1420+
"subprogram declaration must not have a declaration field");
14191421
}
14201422

14211423
if (auto *RawThrownTypes = N.getRawThrownTypes()) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: llvm-as -disable-output <%s 2>&1| FileCheck %s
2+
3+
declare !dbg !12 i32 @declared_only()
4+
5+
!llvm.module.flags = !{!2}
6+
!llvm.dbg.cu = !{!5}
7+
8+
!2 = !{i32 2, !"Debug Info Version", i32 3}
9+
!5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !6, producer: "clang", emissionKind: FullDebug)
10+
!6 = !DIFile(filename: "a.cpp", directory: "/")
11+
!7 = !{}
12+
!11 = !DISubroutineType(types: !7)
13+
14+
!12 = !DISubprogram(name: "declared_only", scope: !6, file: !6, line: 2, type: !11, spFlags: DISPFlagOptimized, retainedNodes: !7, declaration: !13)
15+
!13 = !DISubprogram(name: "declared_only", scope: !6, file: !6, line: 2, type: !11, spFlags: DISPFlagOptimized, retainedNodes: !7)
16+
; CHECK: subprogram declaration must not have a declaration field
17+
; CHECK: warning: ignoring invalid debug info

0 commit comments

Comments
 (0)