diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2011-11-18 01:32:26 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2011-11-18 01:32:26 +0000 |
commit | e5c85622c915dc2ff8a3b4012882a1ec3a3d521c (patch) | |
tree | fff3ef0538ea4103eff7515faaf0167377f2a991 | |
parent | ee94534662f9a5e52b59c9324b6e280842eb8795 (diff) | |
download | bcm5719-llvm-e5c85622c915dc2ff8a3b4012882a1ec3a3d521c.tar.gz bcm5719-llvm-e5c85622c915dc2ff8a3b4012882a1ec3a3d521c.zip |
Don't try to expand struct arguments containing holes on x86-32. From gcc struct layout tests.
llvm-svn: 144961
-rw-r--r-- | clang/lib/CodeGen/TargetInfo.cpp | 8 | ||||
-rw-r--r-- | clang/test/CodeGen/x86_32-arguments-darwin.c | 4 |
2 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 7ad351050dd..5be38978f26 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -292,6 +292,8 @@ static bool canExpandIndirectArgument(QualType Ty, ASTContext &Context) { if (!RD->isStruct() || isa<CXXRecordDecl>(RD)) return false; + uint64_t Size = 0; + for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i) { const FieldDecl *FD = *i; @@ -304,8 +306,14 @@ static bool canExpandIndirectArgument(QualType Ty, ASTContext &Context) { // counts as "basic" is more complicated than what we were doing previously. if (FD->isBitField()) return false; + + Size += Context.getTypeSize(FD->getType()); } + // Make sure there are not any holes in the struct. + if (Size != Context.getTypeSize(Ty)) + return false; + return true; } diff --git a/clang/test/CodeGen/x86_32-arguments-darwin.c b/clang/test/CodeGen/x86_32-arguments-darwin.c index 856a6d72eae..cc203d2add8 100644 --- a/clang/test/CodeGen/x86_32-arguments-darwin.c +++ b/clang/test/CodeGen/x86_32-arguments-darwin.c @@ -288,3 +288,7 @@ void f58(union u58 x) {} // CHECK: define i64 @f59() struct s59 { float x __attribute((aligned(8))); }; struct s59 f59() { while (1) {} } + +// CHECK: define void @f60(%struct.s60* byval align 4, i32 %y) +struct s60 { int x __attribute((aligned(8))); }; +void f60(struct s60 x, int y) {} |