summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-12-09 10:33:27 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-12-09 10:33:27 +0000
commited72cdc010dcd3926fc71c561d298f56c6720eb6 (patch)
tree4c41280e1ad37495036bd5ddbe2e75ef2e58d616
parente8f7a95941290fd566d6f6813ee3fb8287926713 (diff)
downloadbcm5719-llvm-ed72cdc010dcd3926fc71c561d298f56c6720eb6.tar.gz
bcm5719-llvm-ed72cdc010dcd3926fc71c561d298f56c6720eb6.zip
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 llvm-svn: 169694
-rw-r--r--clang/lib/CodeGen/CGRecordLayoutBuilder.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 92c5672c732..43088b4a201 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -1063,15 +1063,23 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D,
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 {
OpenPOWER on IntegriCloud