From b1ef991097c1276fae00d19367da78d0b58ddf9a Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Thu, 28 Jan 2010 18:22:03 +0000 Subject: [PATCH] Fix an incorrect union layout assert. Fixes PR6164. llvm-svn: 94754 --- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 7 ++++++- clang/test/CodeGen/union.c | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index 9f90ec5ff6e0..cc474033c11b 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -162,6 +162,8 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) { uint64_t Size = 0; unsigned Align = 0; + bool HasOnlyZeroSizedBitFields = true; + unsigned FieldNo = 0; for (RecordDecl::field_iterator Field = D->field_begin(), FieldEnd = D->field_end(); Field != FieldEnd; ++Field, ++FieldNo) { @@ -181,6 +183,8 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) { } else Types.addFieldInfo(*Field, 0); + HasOnlyZeroSizedBitFields = false; + const llvm::Type *FieldTy = Types.ConvertTypeForMemRecursive(Field->getType()); unsigned FieldAlign = Types.getTargetData().getABITypeAlignment(FieldTy); @@ -207,7 +211,8 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) { } } if (!Align) { - assert((D->field_begin() == D->field_end()) && "LayoutUnion - Align 0"); + assert(HasOnlyZeroSizedBitFields && + "0-align record did not have all zero-sized bit-fields!"); Align = 1; } diff --git a/clang/test/CodeGen/union.c b/clang/test/CodeGen/union.c index b40a405597ac..1883ca639b7e 100644 --- a/clang/test/CodeGen/union.c +++ b/clang/test/CodeGen/union.c @@ -39,3 +39,6 @@ int qfunc() {q buf; unsigned char* x = buf.x;} union RR {_Bool a : 1;} RRU; int RRF(void) {return RRU.a;} +// PR6164 +typedef union T0 { unsigned int : 0; } T0; +T0 t0;