diff options
author | Tanya Lattner <tonic@nondot.org> | 2010-03-11 23:26:52 +0000 |
---|---|---|
committer | Tanya Lattner <tonic@nondot.org> | 2010-03-11 23:26:52 +0000 |
commit | eba5906e5e54fcc0bb0c79183489a6507aea5c58 (patch) | |
tree | cdd5d7613adb1e2a9d3ad64dd06bbedf55081e46 | |
parent | b0eb828b35bc02eeaae4f61bad5b97d673a291d8 (diff) |
Merge 97981 from mainline.
add a codegen hack to work around an AST bug, allowing us to compile the
code in PR6537. This should be reverted when the ast bug is fixed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_27@98298 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 14 | ||||
-rw-r--r-- | test/CodeGen/init.c | 11 |
2 files changed, 23 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 5af6f91d14..4847ca3f82 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -662,6 +662,16 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { return; } + + // If we're initializing the whole aggregate, just do it in place. + // FIXME: This is a hack around an AST bug (PR6537). + if (NumInitElements == 1 && E->getType() == E->getInit(0)->getType()) { + EmitInitializationToLValue(E->getInit(0), + LValue::MakeAddr(DestPtr, Qualifiers()), + E->getType()); + return; + } + // Here we iterate over the fields; this makes it simpler to both // default-initialize fields and skip over unnamed fields. @@ -680,8 +690,8 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { // We never generate write-barries for initialized fields. LValue::SetObjCNonGC(FieldLoc, true); if (CurInitVal < NumInitElements) { - // Store the initializer into the field - EmitInitializationToLValue(E->getInit(CurInitVal++), FieldLoc, + // Store the initializer into the field. + EmitInitializationToLValue(E->getInit(CurInitVal++), FieldLoc, Field->getType()); } else { // We're out of initalizers; default-initialize to null diff --git a/test/CodeGen/init.c b/test/CodeGen/init.c index f6b3536157..13ffad1731 100644 --- a/test/CodeGen/init.c +++ b/test/CodeGen/init.c @@ -29,3 +29,14 @@ int f4() { static const int g4 = 12; return g4; } + +// PR6537 +typedef union vec3 { + struct { double x, y, z; }; + double component[3]; +} vec3; +vec3 f5(vec3 value) { + return (vec3) {{ + .x = value.x + }}; +} |