[cfe-commits] r107387 - in /cfe/trunk: lib/CodeGen/CGCall.cpp lib/CodeGen/CodeGenTypes.cpp lib/CodeGen/CodeGenTypes.h test/CodeGen/decl.c

Chris Lattner sabre at nondot.org
Wed Jun 30 23:20:47 PDT 2010


Author: lattner
Date: Thu Jul  1 01:20:47 2010
New Revision: 107387

URL: http://llvm.org/viewvc/llvm-project?rev=107387&view=rev
Log:
fix rdar://8147692 - yet another crash due to my abi work.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.h
    cfe/trunk/test/CodeGen/decl.c

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=107387&r1=107386&r2=107387&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Jul  1 01:20:47 2010
@@ -251,18 +251,27 @@
     // If this is being called from the guts of the ConvertType loop, make sure
     // to call ConvertTypeRecursive so we don't get into issues with cyclic
     // pointer type structures.
-    const llvm::Type *ArgType;
-    if (IsRecursive)
-      ArgType = ConvertTypeRecursive(*I);
-    else 
-      ArgType = ConvertType(*I);
-    PreferredArgTypes.push_back(ArgType);
+    PreferredArgTypes.push_back(ConvertTypeRecursive(*I));
   }
-
+  
   // Compute ABI information.
   getABIInfo().computeInfo(*FI, getContext(), TheModule.getContext(),
                            PreferredArgTypes.data(), PreferredArgTypes.size());
 
+  // If this is a top-level call and ConvertTypeRecursive hit unresolved pointer
+  // types, resolve them now.  These pointers may point to this function, which
+  // we *just* filled in the FunctionInfo for.
+  if (!IsRecursive && !PointersToResolve.empty()) {
+    // Use PATypeHolder's so that our preferred types don't dangle under
+    // refinement.
+    llvm::SmallVector<llvm::PATypeHolder, 8> Handles(PreferredArgTypes.begin(),
+                                                     PreferredArgTypes.end());
+    HandleLateResolvedPointers();
+    PreferredArgTypes.clear();
+    PreferredArgTypes.append(Handles.begin(), Handles.end());
+  }
+  
+  
   return *FI;
 }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=107387&r1=107386&r2=107387&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Thu Jul  1 01:20:47 2010
@@ -42,14 +42,11 @@
     delete &*I++;
 }
 
-/// ConvertType - Convert the specified type to its LLVM form.
-const llvm::Type *CodeGenTypes::ConvertType(QualType T, bool IsRecursive) {
-  const llvm::Type *RawResult = ConvertTypeRecursive(T);
-  
-  if (IsRecursive || PointersToResolve.empty())
-    return RawResult;
-
-  llvm::PATypeHolder Result = RawResult;
+/// HandleLateResolvedPointers - For top-level ConvertType calls, this handles
+/// pointers that are referenced but have not been converted yet.  This is used
+/// to handle cyclic structures properly.
+void CodeGenTypes::HandleLateResolvedPointers() {
+  assert(!PointersToResolve.empty() && "No pointers to resolve!");
   
   // Any pointers that were converted deferred evaluation of their pointee type,
   // creating an opaque type instead.  This is in order to avoid problems with
@@ -64,7 +61,21 @@
     const llvm::Type *NT = ConvertTypeForMemRecursive(P.first);
     P.second->refineAbstractTypeTo(NT);
   }
+}
 
+
+/// ConvertType - Convert the specified type to its LLVM form.
+const llvm::Type *CodeGenTypes::ConvertType(QualType T, bool IsRecursive) {
+  const llvm::Type *Result = ConvertTypeRecursive(T);
+  
+  // If this is a top-level call to ConvertType and sub-conversions caused
+  // pointers to get lazily built as opaque types, resolve the pointers, which
+  // might cause Result to be merged away.
+  if (!IsRecursive && !PointersToResolve.empty()) {
+    llvm::PATypeHolder ResultHandle = Result;
+    HandleLateResolvedPointers();
+    Result = ResultHandle;
+  }
   return Result;
 }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.h?rev=107387&r1=107386&r2=107387&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.h Thu Jul  1 01:20:47 2010
@@ -94,6 +94,12 @@
   /// is available only for ConvertType(). CovertType() is preferred
   /// interface to convert type T into a llvm::Type.
   const llvm::Type *ConvertNewType(QualType T);
+  
+  /// HandleLateResolvedPointers - For top-level ConvertType calls, this handles
+  /// pointers that are referenced but have not been converted yet.  This is
+  /// used to handle cyclic structures properly.
+  void HandleLateResolvedPointers();
+
 public:
   CodeGenTypes(ASTContext &Ctx, llvm::Module &M, const llvm::TargetData &TD,
                const ABIInfo &Info);

Modified: cfe/trunk/test/CodeGen/decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/decl.c?rev=107387&r1=107386&r2=107387&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/decl.c (original)
+++ cfe/trunk/test/CodeGen/decl.c Thu Jul  1 01:20:47 2010
@@ -102,3 +102,18 @@
   global_dc->x = cp_diagnostic_starter;
 }
 
+
+
+// rdar://8147692 - ABI crash in recursive struct-through-function-pointer.
+typedef struct {
+  int x5a;
+} x5;
+
+typedef struct x2 *x0;
+typedef long (*x1)(x0 x0a, x5 x6);
+struct x2 {
+  x1 x4;
+};
+long x3(x0 x0a, x5 a) {
+  return x0a->x4(x0a, a);
+}





More information about the cfe-commits mailing list