Hi,

this is a fix for PR11905.

The current behaviour when generation a function prolog for arguments
of coerced types is to allocate a stack temp of the real argument type
and store the argument(s) there. This is wrong, because storage size
of the coerce-to type can be larger than that of the real type.

The new behaviour is to allocate a temp of the coerced type, copy it,
and then reference through a bitcasted pointer of the real type.

Please review.
Index: test/CodeGenObjCXX/copy.mm
===================================================================
--- test/CodeGenObjCXX/copy.mm	(revision 149603)
+++ test/CodeGenObjCXX/copy.mm	(working copy)
@@ -9,7 +9,7 @@
 
   // CHECK:    define [[A:%.*]]* @_ZN5test04testENS_1AE(
   // CHECK:      alloca
-  // CHECK-NEXT: getelementptr
+  // CHECK-NEXT: bitcast
   // CHECK-NEXT: store
   // CHECK-NEXT: call noalias i8* @_Znwm(
   // CHECK-NEXT: bitcast
Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp	(revision 149603)
+++ lib/CodeGen/CGCall.cpp	(working copy)
@@ -1013,7 +1013,8 @@
         break;
       }
 
-      llvm::AllocaInst *Alloca = CreateMemTemp(Ty, "coerce");
+      llvm::AllocaInst *Alloca =
+        CreateTempAlloca(ArgI.getCoerceToType(), Arg->getName());
 
       // The alignment we need to use is the max of the requested alignment for
       // the argument plus the alignment required by our access code below.
@@ -1023,9 +1024,11 @@
                         (unsigned)getContext().getDeclAlign(Arg).getQuantity());
 
       Alloca->setAlignment(AlignmentToUse);
-      llvm::Value *V = Alloca;
-      llvm::Value *Ptr = V;    // Pointer to store into.
 
+      llvm::Value *Ptr = Alloca;    // Pointer to store into.
+      llvm::Value* V = Builder.CreateBitCast(Ptr,
+          llvm::PointerType::getUnqual(ConvertTypeForMem(Ty)));
+
       // If the value is offset in memory, apply the offset now.
       if (unsigned Offs = ArgI.getDirectOffset()) {
         Ptr = Builder.CreateBitCast(Ptr, Builder.getInt8PtrTy());
@@ -1039,7 +1042,6 @@
       // and the optimizer generally likes scalar values better than FCAs.
       if (llvm::StructType *STy =
             dyn_cast<llvm::StructType>(ArgI.getCoerceToType())) {
-        Ptr = Builder.CreateBitCast(Ptr, llvm::PointerType::getUnqual(STy));
 
         for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
           assert(AI != Fn->arg_end() && "Argument mismatch!");
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to