diff options
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 10 | ||||
-rw-r--r-- | test/CodeGen/empty-union-init.c | 12 |
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 58b1884817..f5977728af 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -213,13 +213,15 @@ public: // Find the field decl we're initializing, if any int FieldNo = 0; // Field no in RecordDecl - FieldDecl* curField; - do { + FieldDecl* curField = 0; + while (FieldNo < RD->getNumMembers()) { curField = RD->getMember(FieldNo); FieldNo++; - } while (!curField->getIdentifier() && FieldNo < RD->getNumMembers()); + if (curField->getIdentifier()) + break; + } - if (ILE->getNumInits() == 0 || !curField->getIdentifier()) + if (!curField || !curField->getIdentifier() || ILE->getNumInits() == 0) return llvm::Constant::getNullValue(Ty); if (curField->isBitField()) { diff --git a/test/CodeGen/empty-union-init.c b/test/CodeGen/empty-union-init.c new file mode 100644 index 0000000000..6b8def9a64 --- /dev/null +++ b/test/CodeGen/empty-union-init.c @@ -0,0 +1,12 @@ +// RUN: clang -emit-llvm < %s -o - + +struct Mem { + union { + } u; +}; + +struct Mem *columnMem(){ + static const struct Mem nullMem = { {} }; +} + + |