Skip to content

Preliminary fix for debug info generation with LLVM 3.4. #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 60 additions & 19 deletions gen/dibuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,54 @@ llvm::DIType ldc::DIBuilder::CreateSArrayType(Type *type)
);
}

llvm::DIType ldc::DIBuilder::CreateAArrayType(Type *type)
{
// FIXME: Implement
#if LDC_LLVM_VER >= 304
return DBuilder.createUnspecifiedType(type->toChars());
#else
return llvm::DIType(NULL);
#endif
}

////////////////////////////////////////////////////////////////////////////////

ldc::DIFunctionType ldc::DIBuilder::CreateFunctionType(Type *type)
{
TypeFunction *t = static_cast<TypeFunction*>(type);
Type *retType = t->next;

llvm::DIFile file = CreateFile(Loc(IR->dmodule, 0));

// Create "dummy" subroutine type for the return type
llvm::SmallVector<llvm::Value*, 16> Elts;
Elts.push_back(CreateTypeDescription(retType, NULL, true));
llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts);
return DBuilder.createSubroutineType(file, EltTypeArray);
}

ldc::DIFunctionType ldc::DIBuilder::CreateDelegateType(Type *type)
{
// FIXME: Implement
TypeDelegate *t = static_cast<TypeDelegate*>(type);

llvm::DIFile file = CreateFile(Loc(IR->dmodule, 0));

// Create "dummy" subroutine type for the return type
llvm::SmallVector<llvm::Value*, 16> Elts;
Elts.push_back(
#if LDC_LLVM_VER >= 304
DBuilder.createUnspecifiedType(type->toChars())
#else
llvm::DIType(NULL)
#endif
);
llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts);
return DBuilder.createSubroutineType(file, EltTypeArray);
}

////////////////////////////////////////////////////////////////////////////////

llvm::DIType ldc::DIBuilder::CreateTypeDescription(Type* type,
const char* c_name,
bool derefclass)
Expand All @@ -445,7 +493,7 @@ llvm::DIType ldc::DIBuilder::CreateTypeDescription(Type* type,
t = type->toBasetype();
}

if (t->ty == Tvoid)
if (t->ty == Tvoid || t->ty == Tnull)
#if LDC_LLVM_VER >= 304
return DBuilder.createUnspecifiedType(t->toChars());
#else
Expand All @@ -465,10 +513,17 @@ llvm::DIType ldc::DIBuilder::CreateTypeDescription(Type* type,
return CreateArrayType(type);
else if (t->ty == Tsarray)
return CreateSArrayType(type);
else if (t->ty == Taarray)
return CreateAArrayType(type);
else if (t->ty == Tstruct || t->ty == Tclass)
return CreateCompositeType(type);
else if (t->ty == Tfunction)
return CreateFunctionType(type);
else if (t->ty == Tdelegate)
return CreateDelegateType(type);

return llvm::DIType(NULL);
// Crash if the type is not supported.
llvm_unreachable("Unsupported type in debug info");
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -515,18 +570,9 @@ llvm::DISubprogram ldc::DIBuilder::EmitSubProgram(FuncDeclaration *fd)
assert(CU && CU.Verify() && "Compilation unit missing or corrupted in DIBuilder::EmitSubProgram");

llvm::DIFile file = CreateFile(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(CreateTypeDescription(retType, NULL, true));
llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts);
#if LDC_LLVM_VER >= 304
llvm::DICompositeType
#else
llvm::DIType
#endif
DIFnType = DBuilder.createSubroutineType(file, EltTypeArray);
// Create subroutine type
ldc::DIFunctionType DIFnType = CreateFunctionType(static_cast<TypeFunction*>(fd->type));

// FIXME: duplicates ?
return DBuilder.createFunction(
Expand Down Expand Up @@ -560,12 +606,7 @@ llvm::DISubprogram ldc::DIBuilder::EmitSubProgramInternal(llvm::StringRef pretty
llvm::SmallVector<llvm::Value *, 1> Elts;
Elts.push_back(llvm::DIType(NULL));
llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts);
#if LDC_LLVM_VER >= 304
llvm::DICompositeType
#else
llvm::DIType
#endif
DIFnType = DBuilder.createSubroutineType(file, EltTypeArray);
ldc::DIFunctionType DIFnType = DBuilder.createSubroutineType(file, EltTypeArray);

// FIXME: duplicates ?
return DBuilder.createFunction(
Expand Down
9 changes: 9 additions & 0 deletions gen/dibuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ extern const llvm::TargetData* gDataLayout;

namespace ldc {

#if LDC_LLVM_VER >= 304
typedef llvm::DICompositeType DIFunctionType;
#else
typedef llvm::DIType DIFunctionType;
#endif

class DIBuilder
{
IRState *const IR;
Expand Down Expand Up @@ -141,6 +147,9 @@ class DIBuilder
llvm::DIType CreateCompositeType(Type *type);
llvm::DIType CreateArrayType(Type *type);
llvm::DIType CreateSArrayType(Type *type);
llvm::DIType CreateAArrayType(Type *type);
DIFunctionType CreateFunctionType(Type *type);
DIFunctionType CreateDelegateType(Type *type);
llvm::DIType CreateTypeDescription(Type* type, const char* c_name, bool derefclass = false);

public:
Expand Down