From 46f8d999c5cf1c6170ee0b1ccf1d19262d27a73e Mon Sep 17 00:00:00 2001 From: kai Date: Sat, 16 Mar 2013 21:09:40 +0100 Subject: [PATCH] Fix a LLVM 3.3 problem with debug info generation. In some cases an assertion is triggered because the debug context of a local variale is verified. It turns out that LLVM returns always false for DISubprogram.Verify() if the return type is not a composite type. Reading the Clang source it looks like the return type must be a subroutine type. This commit introduces a dummy subroutine type to define the return type. --- gen/todebug.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gen/todebug.cpp b/gen/todebug.cpp index 6792c7b2..03497f1f 100644 --- a/gen/todebug.cpp +++ b/gen/todebug.cpp @@ -475,17 +475,26 @@ llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd) Logger::println("D to dwarf subprogram"); LOG_SCOPE; + llvm::DICompileUnit CU(gIR->dibuilder.getCU()); + assert(CU && CU.Verify() && "Compilation unit missing or corrupted"); + llvm::DIFile file = DtoDwarfFile(fd->loc); Type *retType = static_cast(fd->type)->next; + // Create "dummy" subroutine type for the return type + llvm::SmallVector Elts; + Elts.push_back(dwarfTypeDescription(retType, NULL)); + llvm::DIArray EltTypeArray = gIR->dibuilder.getOrCreateArray(Elts); + llvm::DIType DIFnType = gIR->dibuilder.createSubroutineType(file, EltTypeArray); + // FIXME: duplicates ? return gIR->dibuilder.createFunction( - llvm::DICompileUnit(file), // context + CU, // context fd->toPrettyChars(), // name fd->mangle(), // linkage name file, // file fd->loc.linnum, // line no - dwarfTypeDescription(retType, NULL), // type + DIFnType, // type fd->protection == PROTprivate, // is local to unit gIR->dmodule == getDefinedModule(fd), // isdefinition #if LDC_LLVM_VER >= 301