summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-02-06 05:33:51 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-02-06 05:33:51 +0000
commit220ee4101126c94a730d42c00a1a86050aade688 (patch)
tree46ebc2e7e9ec764345cfa41ff82cb34d6b39c3f6
parent3340b9258217a1c0fb0f7166b2a3eb124bb9e292 (diff)
downloadbcm5719-llvm-220ee4101126c94a730d42c00a1a86050aade688.tar.gz
bcm5719-llvm-220ee4101126c94a730d42c00a1a86050aade688.zip
Fix the codegen of structs with flexible array members.
llvm-svn: 46806
-rw-r--r--clang/AST/ASTContext.cpp20
-rw-r--r--clang/test/CodeGen/struct.c6
2 files changed, 21 insertions, 5 deletions
diff --git a/clang/AST/ASTContext.cpp b/clang/AST/ASTContext.cpp
index 535f69271f0..6eae4584d5e 100644
--- a/clang/AST/ASTContext.cpp
+++ b/clang/AST/ASTContext.cpp
@@ -323,10 +323,22 @@ const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D,
// the future, this will need to be tweakable by targets.
for (unsigned i = 0, e = D->getNumMembers(); i != e; ++i) {
const FieldDecl *FD = D->getMember(i);
- std::pair<uint64_t, unsigned> FieldInfo = getTypeInfo(FD->getType(), L);
- uint64_t FieldSize = FieldInfo.first;
- unsigned FieldAlign = FieldInfo.second;
-
+ uint64_t FieldSize;
+ unsigned FieldAlign;
+ if (FD->getType()->isIncompleteType()) {
+ // This must be a flexible array member; we can't directly
+ // query getTypeInfo about these, so we figure it out here.
+ // Flexible array members don't have any size, but they
+ // have to be aligned appropriately for their element type.
+ const ArrayType* ATy = FD->getType()->getAsArrayType();
+ FieldAlign = getTypeAlign(ATy->getElementType(), L);
+ FieldSize = 0;
+ } else {
+ std::pair<uint64_t, unsigned> FieldInfo = getTypeInfo(FD->getType(), L);
+ FieldSize = FieldInfo.first;
+ FieldAlign = FieldInfo.second;
+ }
+
// Round up the current record size to the field's alignment boundary.
RecordSize = (RecordSize+FieldAlign-1) & ~(FieldAlign-1);
diff --git a/clang/test/CodeGen/struct.c b/clang/test/CodeGen/struct.c
index fc79f0a2f48..1b476f823d5 100644
--- a/clang/test/CodeGen/struct.c
+++ b/clang/test/CodeGen/struct.c
@@ -138,6 +138,10 @@ void f12()
}
/* struct initialization */
-struct a13 {int b; int c};
+struct a13 {int b; int c;};
struct a13 c13 = {5};
struct a14 { short a; int b; } x = {1, 1};
+
+/* flexible array members */
+struct a15 {char a; int b[];} c15;
+int a16(void) {c15.a = 1;}
OpenPOWER on IntegriCloud