fdeazeve updated this revision to Diff 497321. fdeazeve added a comment. Added verifier test
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D143921/new/ https://reviews.llvm.org/D143921 Files: clang/lib/CodeGen/CGDebugInfo.cpp llvm/docs/LangRef.rst llvm/lib/IR/Verifier.cpp llvm/test/Verifier/disubprogram_declaration.ll Index: llvm/test/Verifier/disubprogram_declaration.ll =================================================================== --- /dev/null +++ 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 Index: llvm/lib/IR/Verifier.cpp =================================================================== --- llvm/lib/IR/Verifier.cpp +++ 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()) { Index: llvm/docs/LangRef.rst =================================================================== --- llvm/docs/LangRef.rst +++ llvm/docs/LangRef.rst @@ -5772,11 +5772,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 @@ -5785,9 +5786,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, Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -4217,7 +4217,7 @@ llvm::DISubprogram *SP = DBuilder.createFunction(FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags, SPFlags, TParamsArray.get(), - getFunctionDeclaration(D), nullptr, Annotations); + 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
Index: llvm/test/Verifier/disubprogram_declaration.ll =================================================================== --- /dev/null +++ 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 Index: llvm/lib/IR/Verifier.cpp =================================================================== --- llvm/lib/IR/Verifier.cpp +++ 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()) { Index: llvm/docs/LangRef.rst =================================================================== --- llvm/docs/LangRef.rst +++ llvm/docs/LangRef.rst @@ -5772,11 +5772,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 @@ -5785,9 +5786,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, Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -4217,7 +4217,7 @@ llvm::DISubprogram *SP = DBuilder.createFunction(FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags, SPFlags, TParamsArray.get(), - getFunctionDeclaration(D), nullptr, Annotations); + 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits