From 61f615af81993a3d63a9d09adacb00cc84a02888 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Tue, 11 Jun 2013 01:08:22 +0000 Subject: [PATCH] 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 . llvm-svn: 183718 --- clang/lib/CodeGen/CGCall.cpp | 11 ++++++++++- clang/test/CodeGen/packed-nest-unpacked.c | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index a53283eb1431..77a43a2fc4a2 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/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/clang/test/CodeGen/packed-nest-unpacked.c b/clang/test/CodeGen/packed-nest-unpacked.c index 7f486c99987d..393174196f4e 100644 --- a/clang/test/CodeGen/packed-nest-unpacked.c +++ b/clang/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); } -- 2.34.1