From: Eli Friedman Date: Tue, 11 Jun 2013 01:08:22 +0000 (+0000) Subject: Fix a FIXME in a testcase about packed structs and calls I left around X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d39083deac93d6580a42ccd5d213aba2bb89cc76;p=clang Fix a FIXME in a testcase about packed structs and calls I left around while fixing a related bug. The fix here was simpler than I thought it would be. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183718 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index a53283eb14..77a43a2fc4 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -2022,7 +2022,16 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E, cast(E)->getCastKind() == CK_LValueToRValue) { LValue L = EmitLValue(cast(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; } diff --git a/test/CodeGen/packed-nest-unpacked.c b/test/CodeGen/packed-nest-unpacked.c index 7f486c9998..393174196f 100644 --- a/test/CodeGen/packed-nest-unpacked.c +++ b/test/CodeGen/packed-nest-unpacked.c @@ -28,7 +28,7 @@ void test3(struct X a) { // 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); }