From 380827cfa191bbaba24777dffa9b6f0dc10c3b75 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 17 Oct 2008 01:07:56 +0000 Subject: [PATCH] Quick patch for PR2784, assert genereting debug info for opaque structure. - I'm not sure yet about the behavior, but this at least prevents the crash. Add some asserts on RegionStack usage. llvm-svn: 57661 --- clang/lib/CodeGen/CGDebugInfo.cpp | 10 +++++++++- clang/test/CodeGen/PR2784-debug-info-opaque-struct.c | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGen/PR2784-debug-info-opaque-struct.c diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index d6902bb93e78..240343dd8223 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -383,6 +383,10 @@ CGDebugInfo::getOrCreateRecordType(QualType type, llvm::CompileUnitDesc *Unit) return NULL; RecordDecl *RecDecl = type->getAsRecordType()->getDecl(); + // We can not get the type for forward declarations. + // FIXME: What *should* we be doing here? + if (!RecDecl->getDefinition(M->getContext())) + return NULL; const ASTRecordLayout &RL = M->getContext().getASTRecordLayout(RecDecl); SourceManager &SM = M->getContext().getSourceManager(); @@ -676,7 +680,7 @@ void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, llvm::IRBuilder<> &Builder) { llvm::BlockDesc *Block = new llvm::BlockDesc(); - if (RegionStack.size() > 0) + if (!RegionStack.empty()) Block->setContext(RegionStack.back()); RegionStack.push_back(Block); @@ -693,6 +697,8 @@ void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, /// region - "llvm.dbg.region.end." void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, llvm::IRBuilder<> &Builder) { + assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); + // Lazily construct llvm.dbg.region.end function. if (!RegionEndFn) RegionEndFn =llvm::Intrinsic::getDeclaration(&M->getModule(), @@ -712,6 +718,8 @@ void CGDebugInfo::EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, llvm::IRBuilder<> &Builder) { + assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); + // FIXME: If it is a compiler generated temporary then return. // Construct llvm.dbg.declare function. diff --git a/clang/test/CodeGen/PR2784-debug-info-opaque-struct.c b/clang/test/CodeGen/PR2784-debug-info-opaque-struct.c new file mode 100644 index 000000000000..588635923fd5 --- /dev/null +++ b/clang/test/CodeGen/PR2784-debug-info-opaque-struct.c @@ -0,0 +1,6 @@ +// RUN: clang -g -emit-llvm -o %t %s +// PR2784 + +struct OPAQUE; +typedef struct OPAQUE *PTR; +PTR p;