]> granicus.if.org Git - clang/commitdiff
Quick fix for PR2950, infinite loop generating debug info for
authorDaniel Dunbar <daniel@zuster.org>
Fri, 31 Oct 2008 04:04:54 +0000 (04:04 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 31 Oct 2008 04:04:54 +0000 (04:04 +0000)
recursive types.
 - Style will be clean up in further patches.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58490 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h
test/CodeGen/PR2950-debug-info-on-recursive-type.c [new file with mode: 0644]

index 64ce8f70e8ed95d34ffad97a27a73c29a5c93868..e9f3aa299ba541407c0d0d8c2e33015c7017068a 100644 (file)
@@ -375,22 +375,27 @@ CGDebugInfo::getOrCreateFunctionType(QualType type, llvm::CompileUnitDesc *Unit)
 }
 
 /// getOrCreateRecordType - get structure or union type.
-llvm::TypeDesc *
-CGDebugInfo::getOrCreateRecordType(QualType type, llvm::CompileUnitDesc *Unit)
+void CGDebugInfo::getOrCreateRecordType(QualType type,
+                                        llvm::CompileUnitDesc *Unit,
+                                        llvm::TypeDesc *&Slot)
 {
+  // Prevent recursing in type generation by initializing the slot
+  // here.
   llvm::CompositeTypeDesc *RecType;
   if (type->isStructureType())
-    RecType = new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_structure_type);
+    Slot = RecType = 
+      new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_structure_type);
   else if (type->isUnionType())
-    RecType = new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_union_type);
+    Slot = RecType = 
+      new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_union_type);
   else
-    return NULL;
+    return;
 
   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;
+    return;
   const ASTRecordLayout &RL = M->getContext().getASTRecordLayout(RecDecl);
 
   SourceManager &SM = M->getContext().getSourceManager();
@@ -417,7 +422,6 @@ CGDebugInfo::getOrCreateRecordType(QualType type, llvm::CompileUnitDesc *Unit)
     RecType->setAlign(RL.getAlignment());
     RecType->setOffset(0);
   }
-  return RecType;
 }
 
 /// getOrCreateEnumType - get Enum type.
@@ -428,7 +432,7 @@ CGDebugInfo::getOrCreateEnumType(QualType type, llvm::CompileUnitDesc *Unit)
     = new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_enumeration_type);
 
   EnumType *EType = dyn_cast<EnumType>(type);
-  if (!EType) return NULL;
+  if (!EType) return(NULL);
 
   EnumDecl *EDecl = EType->getDecl();
   SourceManager &SM = M->getContext().getSourceManager();
@@ -520,15 +524,14 @@ CGDebugInfo::getOrCreateArrayType(QualType type, llvm::CompileUnitDesc *Unit)
 
 
 /// getOrCreateTaggedType - get or create structure/union/Enum type.
-llvm::TypeDesc *
-CGDebugInfo::getOrCreateTaggedType(QualType type, llvm::CompileUnitDesc *Unit)
+void CGDebugInfo::getOrCreateTaggedType(QualType type, 
+                                        llvm::CompileUnitDesc *Unit,
+                                        llvm::TypeDesc *&Slot)
 {
   if (type->isStructureType() || type->isUnionType())
-    return getOrCreateRecordType(type, Unit);
+    getOrCreateRecordType(type, Unit, Slot);
   else if (type->isEnumeralType())
-    return getOrCreateEnumType(type, Unit);
-  else
-    return NULL;
+    Slot = getOrCreateEnumType(type, Unit);
 }
   
 /// getOrCreateType - Get the type from the cache or create a new
@@ -545,7 +548,7 @@ CGDebugInfo::getOrCreateType(QualType type, llvm::CompileUnitDesc *Unit)
 
   // We need to check for the CVR qualifiers as the first thing.
   if (type.getCVRQualifiers()) {
-    Slot = getOrCreateCVRType (type, Unit);
+    Slot = getOrCreateCVRType(type, Unit);
     return Slot;
   }
 
@@ -582,7 +585,7 @@ CGDebugInfo::getOrCreateType(QualType type, llvm::CompileUnitDesc *Unit)
       break;
 
     case Type::Tagged:
-      Slot = getOrCreateTaggedType(type, Unit);
+      getOrCreateTaggedType(type, Unit, Slot);
       break;
 
     case Type::ConstantArray:
index 28834eee086b79a6bb1fa16525fa96903241571f..9e5ad17b0fd722d77950f239230807dc00e0fd35 100644 (file)
@@ -88,12 +88,14 @@ private:
                                          llvm::CompileUnitDesc *unit);
   llvm::TypeDesc *getOrCreateFunctionType(QualType type, 
                                           llvm::CompileUnitDesc *unit);
-  llvm::TypeDesc *getOrCreateRecordType(QualType type,
-                                        llvm::CompileUnitDesc *unit);
+  void getOrCreateRecordType(QualType type,
+                             llvm::CompileUnitDesc *unit,
+                             llvm::TypeDesc *&Slot);
   llvm::TypeDesc *getOrCreateEnumType(QualType type,
                                       llvm::CompileUnitDesc *unit);
-  llvm::TypeDesc *getOrCreateTaggedType(QualType type,
-                                        llvm::CompileUnitDesc *unit);
+  void getOrCreateTaggedType(QualType type,
+                             llvm::CompileUnitDesc *unit,
+                             llvm::TypeDesc *&Slot);
   llvm::TypeDesc *getOrCreateArrayType(QualType type,
                                        llvm::CompileUnitDesc *unit);
 
diff --git a/test/CodeGen/PR2950-debug-info-on-recursive-type.c b/test/CodeGen/PR2950-debug-info-on-recursive-type.c
new file mode 100644 (file)
index 0000000..4768d7e
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: clang -g -emit-llvm -o %t %s
+
+struct s0;
+struct s0 { struct s0 *p; } g0;
+
+struct s0 *f0(struct s0 *a0) {
+  return a0->p;
+}
+  
+