[cfe-commits] r107216 - in /cfe/trunk: lib/CodeGen/CGCall.cpp lib/CodeGen/CodeGenTypes.cpp lib/CodeGen/CodeGenTypes.h test/CodeGenCXX/x86_64-arguments.cpp

Chris Lattner sabre at nondot.org
Tue Jun 29 15:39:04 PDT 2010


Author: lattner
Date: Tue Jun 29 17:39:04 2010
New Revision: 107216

URL: http://llvm.org/viewvc/llvm-project?rev=107216&view=rev
Log:
fix PR7523, which was caused by the ABI code calling ConvertType instead
of ConvertTypeRecursive when it needed to in a few cases, causing pointer
types to get resolved at the wrong time.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.h
    cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=107216&r1=107215&r2=107216&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Jun 29 17:39:04 2010
@@ -287,7 +287,8 @@
 /***/
 
 void CodeGenTypes::GetExpandedTypes(QualType Ty,
-                                    std::vector<const llvm::Type*> &ArgTys) {
+                                    std::vector<const llvm::Type*> &ArgTys,
+                                    bool IsRecursive) {
   const RecordType *RT = Ty->getAsStructureType();
   assert(RT && "Can only expand structure types.");
   const RecordDecl *RD = RT->getDecl();
@@ -302,9 +303,9 @@
 
     QualType FT = FD->getType();
     if (CodeGenFunction::hasAggregateLLVMType(FT)) {
-      GetExpandedTypes(FT, ArgTys);
+      GetExpandedTypes(FT, ArgTys, IsRecursive);
     } else {
-      ArgTys.push_back(ConvertType(FT));
+      ArgTys.push_back(ConvertType(FT, IsRecursive));
     }
   }
 }
@@ -567,11 +568,12 @@
         cast<FunctionDecl>(GD.getDecl())->getType()->getAs<FunctionProtoType>())
     Variadic = FPT->isVariadic();
 
-  return GetFunctionType(FI, Variadic);
+  return GetFunctionType(FI, Variadic, false);
 }
 
 const llvm::FunctionType *
-CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI, bool IsVariadic) {
+CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI, bool IsVariadic,
+                              bool IsRecursive) {
   std::vector<const llvm::Type*> ArgTys;
 
   const llvm::Type *ResultType = 0;
@@ -584,13 +586,13 @@
 
   case ABIArgInfo::Extend:
   case ABIArgInfo::Direct:
-    ResultType = ConvertType(RetTy);
+    ResultType = ConvertType(RetTy, IsRecursive);
     break;
 
   case ABIArgInfo::Indirect: {
     assert(!RetAI.getIndirectAlign() && "Align unused on indirect return.");
     ResultType = llvm::Type::getVoidTy(getLLVMContext());
-    const llvm::Type *STy = ConvertType(RetTy);
+    const llvm::Type *STy = ConvertType(RetTy, IsRecursive);
     ArgTys.push_back(llvm::PointerType::get(STy, RetTy.getAddressSpace()));
     break;
   }
@@ -635,11 +637,11 @@
 
     case ABIArgInfo::Extend:
     case ABIArgInfo::Direct:
-      ArgTys.push_back(ConvertType(it->type));
+      ArgTys.push_back(ConvertType(it->type, IsRecursive));
       break;
 
     case ABIArgInfo::Expand:
-      GetExpandedTypes(it->type, ArgTys);
+      GetExpandedTypes(it->type, ArgTys, IsRecursive);
       break;
     }
   }
@@ -652,7 +654,7 @@
   const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
   
   if (!VerifyFuncTypeComplete(FPT))
-    return GetFunctionType(getFunctionInfo(MD), FPT->isVariadic());
+    return GetFunctionType(getFunctionInfo(MD), FPT->isVariadic(), false);
 
   return llvm::OpaqueType::get(getLLVMContext());
 }
@@ -787,7 +789,7 @@
       // FIXME: This is rather inefficient. Do we ever actually need to do
       // anything here? The result should be just reconstructed on the other
       // side, so extension should be a non-issue.
-      getTypes().GetExpandedTypes(ParamType, Tys);
+      getTypes().GetExpandedTypes(ParamType, Tys, false);
       Index += Tys.size();
       continue;
     }

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=107216&r1=107215&r2=107216&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Tue Jun 29 17:39:04 2010
@@ -43,9 +43,14 @@
 }
 
 /// ConvertType - Convert the specified type to its LLVM form.
-const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
-  llvm::PATypeHolder Result = ConvertTypeRecursive(T);
+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;
+  
   // Any pointers that were converted deferred evaluation of their pointee type,
   // creating an opaque type instead.  This is in order to avoid problems with
   // circular types.  Loop through all these defered pointees, if any, and
@@ -332,7 +337,7 @@
       isVariadic = true;
     }
 
-    return GetFunctionType(*FI, isVariadic);
+    return GetFunctionType(*FI, isVariadic, true);
   }
 
   case Type::ObjCObject:

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.h?rev=107216&r1=107215&r2=107216&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.h Tue Jun 29 17:39:04 2010
@@ -106,7 +106,7 @@
   llvm::LLVMContext &getLLVMContext() { return TheModule.getContext(); }
 
   /// ConvertType - Convert type T into a llvm::Type.
-  const llvm::Type *ConvertType(QualType T);
+  const llvm::Type *ConvertType(QualType T, bool IsRecursive = false);
   const llvm::Type *ConvertTypeRecursive(QualType T);
 
   /// ConvertTypeForMem - Convert type T into a llvm::Type.  This differs from
@@ -118,7 +118,8 @@
 
   /// GetFunctionType - Get the LLVM function type for \arg Info.
   const llvm::FunctionType *GetFunctionType(const CGFunctionInfo &Info,
-                                            bool IsVariadic);
+                                            bool IsVariadic,
+                                            bool IsRecursive = false);
 
   const llvm::FunctionType *GetFunctionType(GlobalDecl GD);
 
@@ -193,7 +194,8 @@
   /// GetExpandedTypes - Expand the type \arg Ty into the LLVM
   /// argument types it would be passed as on the provided vector \arg
   /// ArgTys. See ABIArgInfo::Expand.
-  void GetExpandedTypes(QualType Ty, std::vector<const llvm::Type*> &ArgTys);
+  void GetExpandedTypes(QualType Ty, std::vector<const llvm::Type*> &ArgTys,
+                        bool IsRecursive);
   
   /// ContainsPointerToDataMember - Return whether the given type contains a
   /// pointer to a data member.

Modified: cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp?rev=107216&r1=107215&r2=107216&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/x86_64-arguments.cpp Tue Jun 29 17:39:04 2010
@@ -30,3 +30,18 @@
 typedef int (s4::*s4_mfp)();
 s4_mdp f4_0(s4_mdp a) { return a; }
 s4_mfp f4_1(s4_mfp a) { return a; }
+
+
+namespace PR7523 {
+struct StringRef {
+  char *a;
+};
+
+void AddKeyword(StringRef, int x);
+
+void foo() {
+  // CHECK: define void @_ZN6PR75233fooEv()
+  // CHECK: call void @_ZN6PR752310AddKeywordENS_9StringRefEi(i8* {{.*}}, i32 4)
+  AddKeyword(StringRef(), 4);
+}
+}
\ No newline at end of file





More information about the cfe-commits mailing list