[cfe-commits] r52060 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/empty-union-init.c
Eli Friedman
eli.friedman at gmail.com
Fri Jun 6 13:12:37 PDT 2008
Author: efriedma
Date: Fri Jun 6 15:12:37 2008
New Revision: 52060
URL: http://llvm.org/viewvc/llvm-project?rev=52060&view=rev
Log:
Reorganize this loop a bit so it doesn't crash for empty unions. Fixes
PR2419.
Added:
cfe/trunk/test/CodeGen/empty-union-init.c
Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=52060&r1=52059&r2=52060&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Jun 6 15:12:37 2008
@@ -213,13 +213,15 @@
// 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()) {
Added: cfe/trunk/test/CodeGen/empty-union-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/empty-union-init.c?rev=52060&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/empty-union-init.c (added)
+++ cfe/trunk/test/CodeGen/empty-union-init.c Fri Jun 6 15:12:37 2008
@@ -0,0 +1,12 @@
+// RUN: clang -emit-llvm < %s -o -
+
+struct Mem {
+ union {
+ } u;
+};
+
+struct Mem *columnMem(){
+ static const struct Mem nullMem = { {} };
+}
+
+
More information about the cfe-commits
mailing list