[cfe-commits] r57661 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp test/CodeGen/PR2784-debug-info-opaque-struct.c

Daniel Dunbar daniel at zuster.org
Thu Oct 16 18:07:57 PDT 2008


Author: ddunbar
Date: Thu Oct 16 20:07:56 2008
New Revision: 57661

URL: http://llvm.org/viewvc/llvm-project?rev=57661&view=rev
Log:
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.

Added:
    cfe/trunk/test/CodeGen/PR2784-debug-info-opaque-struct.c
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=57661&r1=57660&r2=57661&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Oct 16 20:07:56 2008
@@ -383,6 +383,10 @@
     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 @@
                                   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 @@
 /// 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 @@
                               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.

Added: cfe/trunk/test/CodeGen/PR2784-debug-info-opaque-struct.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/PR2784-debug-info-opaque-struct.c?rev=57661&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/PR2784-debug-info-opaque-struct.c (added)
+++ cfe/trunk/test/CodeGen/PR2784-debug-info-opaque-struct.c Thu Oct 16 20:07:56 2008
@@ -0,0 +1,6 @@
+// RUN: clang -g -emit-llvm -o %t %s
+// PR2784
+
+struct OPAQUE;
+typedef struct OPAQUE *PTR;
+PTR p;





More information about the cfe-commits mailing list