diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -4214,10 +4214,9 @@ llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D); llvm::DISubroutineType *STy = getOrCreateFunctionType(D, FnType, Unit); - llvm::DISubprogram *SP = - DBuilder.createFunction(FDContext, Name, LinkageName, Unit, LineNo, STy, - ScopeLine, Flags, SPFlags, TParamsArray.get(), - getFunctionDeclaration(D), nullptr, Annotations); + llvm::DISubprogram *SP = DBuilder.createFunction( + FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags, + SPFlags, TParamsArray.get(), nullptr, nullptr, Annotations); // Preserve btf_decl_tag attributes for parameters of extern functions // for BPF target. The parameters created in this loop are attached as diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -5776,11 +5776,12 @@ .. _DISubprogramDeclaration: -When ``isDefinition: false``, subprograms describe a declaration in the type -tree as opposed to a definition of a function. If the scope is a composite -type with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, -then the subprogram declaration is uniqued based only on its ``linkageName:`` -and ``scope:``. +When ``spFlags: DISPFlagDefinition`` is not present, subprograms describe a +declaration in the type tree as opposed to a definition of a function. In this +case, the ``declaration`` field must be empty. If the scope is a composite type +with an ODR ``identifier:`` and that does not set ``flags: DIFwdDecl``, then +the subprogram declaration is uniqued based only on its ``linkageName:`` and +``scope:``. .. code-block:: text @@ -5789,9 +5790,9 @@ } !0 = distinct !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1, - file: !2, line: 7, type: !3, isLocal: true, - isDefinition: true, scopeLine: 8, - containingType: !4, + file: !2, line: 7, type: !3, + spFlags: DISPFlagDefinition | DISPFlagLocalToUnit, + scopeLine: 8, containingType: !4, virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10, flags: DIFlagPrototyped, isOptimized: true, unit: !5, templateParams: !6, diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1400,6 +1400,8 @@ } else { // Subprogram declarations (part of the type hierarchy). CheckDI(!Unit, "subprogram declarations must not have a compile unit", &N); + CheckDI(!N.getRawDeclaration(), + "subprogram declaration must not have a declaration field"); } if (auto *RawThrownTypes = N.getRawThrownTypes()) { diff --git a/llvm/test/Verifier/disubprogram_declaration.ll b/llvm/test/Verifier/disubprogram_declaration.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Verifier/disubprogram_declaration.ll @@ -0,0 +1,17 @@ +; RUN: llvm-as -disable-output <%s 2>&1| FileCheck %s + +declare !dbg !12 i32 @declared_only() + +!llvm.module.flags = !{!2} +!llvm.dbg.cu = !{!5} + +!2 = !{i32 2, !"Debug Info Version", i32 3} +!5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !6, producer: "clang", emissionKind: FullDebug) +!6 = !DIFile(filename: "a.cpp", directory: "/") +!7 = !{} +!11 = !DISubroutineType(types: !7) + +!12 = !DISubprogram(name: "declared_only", scope: !6, file: !6, line: 2, type: !11, spFlags: DISPFlagOptimized, retainedNodes: !7, declaration: !13) +!13 = !DISubprogram(name: "declared_only", scope: !6, file: !6, line: 2, type: !11, spFlags: DISPFlagOptimized, retainedNodes: !7) +; CHECK: subprogram declaration must not have a declaration field +; CHECK: warning: ignoring invalid debug info