From 6bd78496a1e0f6a09bda85dd033497899bda4794 Mon Sep 17 00:00:00 2001 From: kai Date: Mon, 19 Aug 2013 22:11:57 +0200 Subject: [PATCH] Preliminary fix for debug info generation with LLVM 3.4. There is no debug information generated for several types. As LLVM 3.4 does not support empty nodes, it is now time to implement the missing debug info. --- gen/dibuilder.cpp | 79 +++++++++++++++++++++++++++++++++++------------ gen/dibuilder.h | 9 ++++++ 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/gen/dibuilder.cpp b/gen/dibuilder.cpp index ec701c31..6684f860 100644 --- a/gen/dibuilder.cpp +++ b/gen/dibuilder.cpp @@ -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(type); + Type *retType = t->next; + + llvm::DIFile file = CreateFile(Loc(IR->dmodule, 0)); + + // Create "dummy" subroutine type for the return type + llvm::SmallVector 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(type); + + llvm::DIFile file = CreateFile(Loc(IR->dmodule, 0)); + + // Create "dummy" subroutine type for the return type + llvm::SmallVector 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) @@ -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 @@ -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"); } //////////////////////////////////////////////////////////////////////////////// @@ -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(fd->type)->next; - // Create "dummy" subroutine type for the return type - llvm::SmallVector 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(fd->type)); // FIXME: duplicates ? return DBuilder.createFunction( @@ -560,12 +606,7 @@ llvm::DISubprogram ldc::DIBuilder::EmitSubProgramInternal(llvm::StringRef pretty llvm::SmallVector 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( diff --git a/gen/dibuilder.h b/gen/dibuilder.h index 7d05d58a..27d9e854 100644 --- a/gen/dibuilder.h +++ b/gen/dibuilder.h @@ -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; @@ -141,6 +147,9 @@ private: 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: