]> granicus.if.org Git - clang/commitdiff
Fix a FIXME in a testcase about packed structs and calls I left around
authorEli Friedman <eli.friedman@gmail.com>
Tue, 11 Jun 2013 01:08:22 +0000 (01:08 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 11 Jun 2013 01:08:22 +0000 (01:08 +0000)
while fixing a related bug.  The fix here was simpler than I thought it
would be.

Fixes <rdar://problem/10530444>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183718 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
test/CodeGen/packed-nest-unpacked.c

index a53283eb143178bf11d82949199ac35197a65331..77a43a2fc4a2f52ff95b548a772baac35b32cf03 100644 (file)
@@ -2022,7 +2022,16 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
       cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue) {
     LValue L = EmitLValue(cast<CastExpr>(E)->getSubExpr());
     assert(L.isSimple());
-    args.add(L.asAggregateRValue(), type, /*NeedsCopy*/true);
+    if (L.getAlignment() >= getContext().getTypeAlignInChars(type)) {
+      args.add(L.asAggregateRValue(), type, /*NeedsCopy*/true);
+    } else {
+      // We can't represent a misaligned lvalue in the CallArgList, so copy
+      // to an aligned temporary now.
+      llvm::Value *tmp = CreateMemTemp(type);
+      EmitAggregateCopy(tmp, L.getAddress(), type, L.isVolatile(),
+                        L.getAlignment());
+      args.add(RValue::getAggregate(tmp), type);
+    }
     return;
   }
 
index 7f486c99987dcb0dacde9179246714d7bf30228c..393174196f4e893266b7054eba2d12e0ed12ba26 100644 (file)
@@ -28,7 +28,7 @@ void test3(struct X a) {
 // <rdar://problem/10530444>
 void test4() {
   // CHECK: @test4
-  // FIXME: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y* @g, i32 0, i32 1) to i8*), i64 24, i32 1, i1 false)
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* bitcast (%struct.X* getelementptr inbounds (%struct.Y* @g, i32 0, i32 1) to i8*), i64 24, i32 1, i1 false)
   f(g.y);
 }