]> granicus.if.org Git - clang/commitdiff
Fix a regression from r132957 involving complex integers. (Fixes failures on gcc...
authorEli Friedman <eli.friedman@gmail.com>
Wed, 15 Jun 2011 18:26:32 +0000 (18:26 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 15 Jun 2011 18:26:32 +0000 (18:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133069 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
test/CodeGen/complex-indirect.c [new file with mode: 0644]

index 5e9ecd574b65ef16e12f0eb9b7288a38c14bbae0..b80787bb180641a1337af6e53ee7a085830e9b92 100644 (file)
@@ -1189,7 +1189,8 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
     return args.add(EmitReferenceBindingToExpr(E, /*InitializedDecl=*/0),
                     type);
 
-  if (hasAggregateLLVMType(type) && isa<ImplicitCastExpr>(E) &&
+  if (hasAggregateLLVMType(type) && !E->getType()->isAnyComplexType() &&
+      isa<ImplicitCastExpr>(E) &&
       cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue) {
     LValue L = EmitLValue(cast<CastExpr>(E)->getSubExpr());
     assert(L.isSimple());
@@ -1257,7 +1258,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
     case ABIArgInfo::Indirect: {
       if (RV.isScalar() || RV.isComplex()) {
         // Make a temporary alloca to pass the argument.
-        Args.push_back(CreateMemTemp(I->Ty));
+        llvm::AllocaInst *AI = CreateMemTemp(I->Ty);
+        if (ArgInfo.getIndirectAlign() > AI->getAlignment())
+          AI->setAlignment(ArgInfo.getIndirectAlign());
+        Args.push_back(AI);
         if (RV.isScalar())
           EmitStoreOfScalar(RV.getScalarVal(), Args.back(), false,
                             Alignment, I->Ty);
diff --git a/test/CodeGen/complex-indirect.c b/test/CodeGen/complex-indirect.c
new file mode 100644 (file)
index 0000000..fbe73d6
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s
+
+// Make sure this doesn't crash, and that we don't generate a byval alloca
+// with insufficient alignment.
+
+void a(int,int,int,int,int,int,__complex__ char);
+void b(__complex__ char *y) { a(0,0,0,0,0,0,*y); }
+// CHECK: define void @b
+// CHECK: alloca %0, align 8
+// CHECK: call void @a(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, %0* byval align 8