diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index b03fac2d22a52..477b66484c20c 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1351,6 +1351,13 @@ DIE *DwarfUnit::getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal) { ContextDIE = &getUnitDie(); // Build the decl now to ensure it precedes the definition. getOrCreateSubprogramDIE(SPDecl); + // Check whether the DIE for SP has already been created after the call + // above. + // FIXME: Should the creation of definition subprogram DIE during + // the creation of declaration subprogram DIE be allowed? + // See https://github.com/llvm/llvm-project/pull/154636. + if (DIE *SPDie = getDIE(SP)) + return SPDie; } } diff --git a/llvm/test/DebugInfo/X86/pr12831.ll b/llvm/test/DebugInfo/X86/pr12831.ll index 402bc9aa04505..c37c017a52c29 100644 --- a/llvm/test/DebugInfo/X86/pr12831.ll +++ b/llvm/test/DebugInfo/X86/pr12831.ll @@ -1,4 +1,39 @@ -; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu -o /dev/null +; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s + +; Check that there are no empty DW_TAG_subprogram tags. +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK: DW_TAG_subprogram +; CHECK-NEXT: DW_AT +; CHECK-NOT: DW_TAG_subprogram target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu"