Skip to content

Commit acd2efd

Browse files
committed
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. llvm-svn: 98298
1 parent f498a64 commit acd2efd

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,16 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
662662

663663
return;
664664
}
665+
666+
// If we're initializing the whole aggregate, just do it in place.
667+
// FIXME: This is a hack around an AST bug (PR6537).
668+
if (NumInitElements == 1 && E->getType() == E->getInit(0)->getType()) {
669+
EmitInitializationToLValue(E->getInit(0),
670+
LValue::MakeAddr(DestPtr, Qualifiers()),
671+
E->getType());
672+
return;
673+
}
674+
665675

666676
// Here we iterate over the fields; this makes it simpler to both
667677
// default-initialize fields and skip over unnamed fields.
@@ -680,8 +690,8 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
680690
// We never generate write-barries for initialized fields.
681691
LValue::SetObjCNonGC(FieldLoc, true);
682692
if (CurInitVal < NumInitElements) {
683-
// Store the initializer into the field
684-
EmitInitializationToLValue(E->getInit(CurInitVal++), FieldLoc,
693+
// Store the initializer into the field.
694+
EmitInitializationToLValue(E->getInit(CurInitVal++), FieldLoc,
685695
Field->getType());
686696
} else {
687697
// We're out of initalizers; default-initialize to null

clang/test/CodeGen/init.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ int f4() {
2929
static const int g4 = 12;
3030
return g4;
3131
}
32+
33+
// PR6537
34+
typedef union vec3 {
35+
struct { double x, y, z; };
36+
double component[3];
37+
} vec3;
38+
vec3 f5(vec3 value) {
39+
return (vec3) {{
40+
.x = value.x
41+
}};
42+
}

0 commit comments

Comments
 (0)