diff options
author | John McCall <rjmccall@apple.com> | 2012-04-26 21:14:42 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2012-04-26 21:14:42 +0000 |
commit | 6ea4841da1390b4f76d066f25333f11f6d8c5f40 (patch) | |
tree | e7d243636f7cec06291969aeaec69431b3ed866e | |
parent | e002631101d3bafbc90ed8589ffc615f04dc245b (diff) |
Fix a bug with block layout when the block contains something
more aligned than the block header but also contains something
smaller than the block-header alignment but not exactly half
the difference between the large alignment and the header
alignment. Got that?
I'm really not sure what I was thinking with the buggy computation
here, but the fix is pretty obvious.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155662 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGBlocks.cpp | 13 | ||||
-rw-r--r-- | test/CodeGen/blocks.c | 8 |
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index f8c7bcd4d7..379da11033 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -458,19 +458,22 @@ static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF, } } + assert(endAlign == getLowBit(blockSize)); + // At this point, we just have to add padding if the end align still // isn't aligned right. if (endAlign < maxFieldAlign) { - CharUnits padding = maxFieldAlign - endAlign; + CharUnits newBlockSize = blockSize.RoundUpToAlignment(maxFieldAlign); + CharUnits padding = newBlockSize - blockSize; elementTypes.push_back(llvm::ArrayType::get(CGM.Int8Ty, padding.getQuantity())); - blockSize += padding; - - endAlign = getLowBit(blockSize); - assert(endAlign >= maxFieldAlign); + blockSize = newBlockSize; + endAlign = maxFieldAlign; } + assert(endAlign == getLowBit(blockSize)); + // Slam everything else on now. This works because they have // strictly decreasing alignment and we expect that size is always a // multiple of alignment. diff --git a/test/CodeGen/blocks.c b/test/CodeGen/blocks.c index bef44c3690..77fb0e1899 100644 --- a/test/CodeGen/blocks.c +++ b/test/CodeGen/blocks.c @@ -40,3 +40,11 @@ void f3() { _Bool b = 0; f3_helper(^{ if (b) {} }); } + +// rdar://problem/11322251 +void f4_helper(long long (^)(void)); +void f4(void) { + _Bool b = 0; + long long ll = 0; + f4_helper(^{ if (b) return ll; return 0LL; }); +} |