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.
This commit is contained in:
kai
2013-03-16 21:09:40 +01:00
parent 9b6df6ae32
commit 46f8d999c5

View File

@@ -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<TypeFunction*>(fd->type)->next;
// Create "dummy" subroutine type for the return type
llvm::SmallVector<llvm::Value*, 16> 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