summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGBlocks.cpp
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@apple.com>2016-05-02 21:52:57 +0000
committerAkira Hatanaka <ahatanaka@apple.com>2016-05-02 21:52:57 +0000
commit3ba6535096a4a1abd57f7813183ac8fa0bccfc39 (patch)
tree3c2977aee66c44f544d759f263df565f65766502 /clang/lib/CodeGen/CGBlocks.cpp
parent64f7a995b0f3b213e353486c5b6c6132f9bb124d (diff)
downloadbcm5719-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/lib/CodeGen/CGBlocks.cpp')
-rw-r--r--clang/lib/CodeGen/CGBlocks.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index ea164aad915..88786bc9fcf 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -262,6 +262,11 @@ static bool isSafeForCXXConstantCapture(QualType type) {
static llvm::Constant *tryCaptureAsConstant(CodeGenModule &CGM,
CodeGenFunction *CGF,
const VarDecl *var) {
+ // Don't rematerialize default arguments of function parameters.
+ if (auto *PD = dyn_cast<ParmVarDecl>(var))
+ if (PD->hasDefaultArg())
+ return nullptr;
+
QualType type = var->getType();
// We can only do this if the variable is const.
OpenPOWER on IntegriCloud