[cfe-commits] r169694 - /cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Chandler Carruth
chandlerc at gmail.com
Sun Dec 9 02:33:27 PST 2012
Author: chandlerc
Date: Sun Dec 9 04:33:27 2012
New Revision: 169694
URL: http://llvm.org/viewvc/llvm-project?rev=169694&view=rev
Log:
Cleanup and fix an assert that was mis-firing.
Note that there is no test suite update. This was found by a couple of
tests failing when the test suite was run on a powerpc64 host (thanks
Roman!). The tests don't specify a triple, which might seem surprising
for a codegen test. But in fact, these tests don't even inspect their
output. Not at all. I could add a bunch of triples to these tests so
that we'd get the test coverage for normal builds, but really someone
needs to go through and add actual *tests* to these tests. =[ The ones
in question are:
test/CodeGen/bitfield-init.c
test/CodeGen/union.c
Modified:
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=169694&r1=169693&r2=169694&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Sun Dec 9 04:33:27 2012
@@ -1063,15 +1063,23 @@
if (FD->getBitWidthValue(getContext()) == 0)
continue;
- unsigned FieldNo = RL->getLLVMFieldNo(FD);
const CGBitFieldInfo &Info = RL->getBitFieldInfo(FD);
- llvm::Type *ElementTy = ST->getTypeAtIndex(FieldNo);
+ llvm::Type *ElementTy = ST->getTypeAtIndex(RL->getLLVMFieldNo(FD));
+
// Unions have overlapping elements dictating their layout, but for
// non-unions we can verify that this section of the layout is the exact
- // expected size. For unions we verify that the start is zero and the size
- // is in-bounds.
+ // expected size.
if (D->isUnion()) {
- assert(Info.Offset == 0 && "Union bitfield with a non-zero offset");
+ // For unions we verify that the start is zero and the size
+ // is in-bounds. However, on BE systems, the offset may be non-zero, but
+ // the size + offset should match the storage size in that case as it
+ // "starts" at the back.
+ if (getDataLayout().isBigEndian())
+ assert((Info.Offset + Info.Size) == Info.StorageSize &&
+ "Big endian union bitfield does not end at the back");
+ else
+ assert(Info.Offset == 0 &&
+ "Little endian union bitfield with a non-zero offset");
assert(Info.StorageSize <= SL->getSizeInBits() &&
"Union not large enough for bitfield storage");
} else {
More information about the cfe-commits
mailing list