diff options
| author | Akira Hatanaka <ahatanaka@apple.com> | 2016-05-02 21:52:57 +0000 |
|---|---|---|
| committer | Akira Hatanaka <ahatanaka@apple.com> | 2016-05-02 21:52:57 +0000 |
| commit | 3ba6535096a4a1abd57f7813183ac8fa0bccfc39 (patch) | |
| tree | 3c2977aee66c44f544d759f263df565f65766502 /clang/test/CodeGenObjCXX | |
| parent | 64f7a995b0f3b213e353486c5b6c6132f9bb124d (diff) | |
| download | bcm5719-llvm-3ba6535096a4a1abd57f7813183ac8fa0bccfc39.tar.gz bcm5719-llvm-3ba6535096a4a1abd57f7813183ac8fa0bccfc39.zip | |
[CodeGenObjCXX] Don't rematerialize default arguments of function
parameters in the body of a block.
This fixes a bug where clang would materialize the default argument
inside the body of a block instead of passing the value via the block
descriptor.
For example, in the code below, foo1 would always print 42 regardless
of the value of argument "a" passed to foo1.
void foo1(const int a = 42 ) {
auto block = ^{
printf("%d\n", a);
};
block();
}
rdar://problem/24449235
llvm-svn: 268314
Diffstat (limited to 'clang/test/CodeGenObjCXX')
| -rw-r--r-- | clang/test/CodeGenObjCXX/block-default-arg.mm | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/test/CodeGenObjCXX/block-default-arg.mm b/clang/test/CodeGenObjCXX/block-default-arg.mm new file mode 100644 index 00000000000..167b31d4054 --- /dev/null +++ b/clang/test/CodeGenObjCXX/block-default-arg.mm @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -std=c++11 -fblocks -fobjc-arc | FileCheck %s + +// CHECK: define internal void @___Z16test_default_argi_block_invoke(i8* %[[BLOCK_DESCRIPTOR:.*]]) +// CHECK: %[[BLOCK:.*]] = bitcast i8* %[[BLOCK_DESCRIPTOR]] to <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* +// CHECK: %[[BLOCK_CAPTURE_ADDR:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %[[BLOCK]], i32 0, i32 5 +// CHECK: %[[V0:.*]] = load i32, i32* %[[BLOCK_CAPTURE_ADDR]] +// CHECK: call void @_Z4foo1i(i32 %[[V0]]) + +void foo1(int); + +void test_default_arg(const int a = 42) { + auto block = ^{ + foo1(a); + }; + block(); +} |

