forked from OSchip/llvm-project
Fix implicit initialization of structures.
<rdar://problem/6113085> llvm-svn: 54237
This commit is contained in:
parent
2d7ddea240
commit
b39b1cd7c3
|
@ -426,11 +426,6 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
|
|||
// Here we iterate over the fields; this makes it simpler to both
|
||||
// default-initialize fields and skip over unnamed fields.
|
||||
for (unsigned CurFieldNo = 0; CurFieldNo != NumMembers; ++CurFieldNo) {
|
||||
if (CurInitVal >= NumInitElements) {
|
||||
// No more initializers; we're done.
|
||||
break;
|
||||
}
|
||||
|
||||
FieldDecl *CurField = SD->getMember(CurFieldNo);
|
||||
if (CurField->getIdentifier() == 0) {
|
||||
// Initializers can't initialize unnamed fields, e.g. "int : 20;"
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// RUN: clang --emit-llvm-bc -o - %s | opt --std-compile-opts | llvm-dis > %t &&
|
||||
// RUN: grep "ret i32" %t | count 2 &&
|
||||
// RUN: grep "ret i32 0" %t | count 2
|
||||
// <rdar://problem/6113085>
|
||||
|
||||
struct s0 {
|
||||
int x, y;
|
||||
};
|
||||
|
||||
int f0() {
|
||||
struct s0 x = {0};
|
||||
return x.y;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Optimizer isn't smart enough to reduce this since we use
|
||||
memset. Hrm. */
|
||||
int f1() {
|
||||
struct s0 x[2] = { {0} };
|
||||
return x[1].x;
|
||||
}
|
||||
#endif
|
||||
|
||||
int f2() {
|
||||
int x[2] = { 0 };
|
||||
return x[1];
|
||||
}
|
||||
|
Loading…
Reference in New Issue