[llvm-commits] [llvm-gcc-4.2] r93485 - /llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp

Devang Patel dpatel at apple.com
Thu Jan 14 16:33:29 PST 2010


Author: dpatel
Date: Thu Jan 14 18:33:29 2010
New Revision: 93485

URL: http://llvm.org/viewvc/llvm-project?rev=93485&view=rev
Log:
Avoid recursive while emitting debug info for function types.
test/FrontendC/2010-01-14-FnType-DebugInfo.c is the test case.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=93485&r1=93484&r2=93485&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Thu Jan 14 18:33:29 2010
@@ -512,6 +512,21 @@
 /// createMethodType - Create MethodType.
 DIType DebugInfo::createMethodType(tree type) {
 
+  // Create a  place holder type first. The may be used as a context
+  // for the argument types.
+  llvm::DIType FwdType = 
+    DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
+                                     getOrCreateCompileUnit(NULL), 
+                                     StringRef(),
+                                     getOrCreateCompileUnit(NULL), 
+                                     0, 0, 0, 0, 0,
+                                     llvm::DIType(), llvm::DIArray());
+  llvm::TrackingVH<llvm::MDNode> FwdTypeNode = FwdType.getNode();
+  TypeCache[type] = WeakVH(FwdType.getNode());
+  // Push the struct on region stack.
+  RegionStack.push_back(WeakVH(FwdType.getNode()));
+  RegionMap[type] = WeakVH(FwdType.getNode());
+  
   llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
   
   // Add the result type at least.
@@ -527,12 +542,24 @@
   llvm::DIArray EltTypeArray =
     DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
 
-  return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
-                                          findRegion(TYPE_CONTEXT(type)), 
-                                          StringRef(),
-                                          getOrCreateCompileUnit(NULL), 
-                                          0, 0, 0, 0, 0,
-                                          llvm::DIType(), EltTypeArray);
+  RegionStack.pop_back();
+  std::map<tree_node *, WeakVH>::iterator RI = RegionMap.find(type);
+  if (RI != RegionMap.end())
+    RegionMap.erase(RI);
+
+  llvm::DIType RealType =
+    DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
+                                     findRegion(TYPE_CONTEXT(type)), 
+                                     StringRef(),
+                                     getOrCreateCompileUnit(NULL), 
+                                     0, 0, 0, 0, 0,
+                                     llvm::DIType(), EltTypeArray);
+
+  // Now that we have a real decl for the struct, replace anything using the
+  // old decl with the new one.  This will recursively update the debug info.
+  llvm::DIDerivedType(FwdTypeNode).replaceAllUsesWith(RealType);
+
+  return RealType;
 }
 
 /// createPointerType - Create PointerType.





More information about the llvm-commits mailing list