aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-09-03 21:36:02 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-09-03 21:36:02 +0000
commit9d798d13f3e5b089ba4426e4f26367eb1cbb4bb2 (patch)
treeb47bb08a8658f1980694820e1eb6975119481640
parent367afb5a00da7b60e2a3abec612b24a99df91fe9 (diff)
downloadllvm-9d798d13f3e5b089ba4426e4f26367eb1cbb4bb2.zip
llvm-9d798d13f3e5b089ba4426e4f26367eb1cbb4bb2.tar.gz
llvm-9d798d13f3e5b089ba4426e4f26367eb1cbb4bb2.tar.bz2
Cope with llvm's reference to bool type of 'i1' vs. clang's
type of 'i8' for the same for __block variables of type bool. refixes radar 8382559. llvm-svn: 113015
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp17
-rw-r--r--clang/test/SemaCXX/blocks.cpp20
2 files changed, 37 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 06c657f..b4d0e13 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -335,6 +335,23 @@ CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
llvm::Value *Value = EmitExprForReferenceBinding(*this, E, ReferenceTemporary,
ReferenceTemporaryDtor,
InitializedDecl);
+ if (E->getType()->isBooleanType()) {
+ // special handling for __block variable of bool type bound to
+ // a reference type.
+ bool block_byref_var = false;
+ if (const BlockDeclRefExpr *BE = dyn_cast<BlockDeclRefExpr>(E))
+ block_byref_var = BE->isByRef();
+ else if (const DeclRefExpr *BD = dyn_cast<DeclRefExpr>(E)) {
+ const NamedDecl *ND = BD->getDecl();
+ if (const VarDecl *VD = dyn_cast<VarDecl>(ND))
+ block_byref_var = VD->hasAttr<BlocksAttr>();
+ }
+ if (block_byref_var) {
+ const llvm::Type *T = ConvertTypeForMem(E->getType());
+ T = llvm::PointerType::getUnqual(T);
+ Value = Builder.CreateBitCast(Value, T);
+ }
+ }
if (!ReferenceTemporaryDtor)
return RValue::get(Value);
diff --git a/clang/test/SemaCXX/blocks.cpp b/clang/test/SemaCXX/blocks.cpp
index baa79e7..4fd9941 100644
--- a/clang/test/SemaCXX/blocks.cpp
+++ b/clang/test/SemaCXX/blocks.cpp
@@ -41,3 +41,23 @@ namespace test2 {
return Power(2).calculate(10);
}
}
+
+// rdar: // 8382559
+namespace radar8382559 {
+ void func(bool& outHasProperty);
+
+ int test3() {
+ __attribute__((__blocks__(byref))) bool hasProperty = false;
+ bool (^b)() = ^ {
+ func(hasProperty);
+ if (hasProperty)
+ hasProperty = 0;
+ return hasProperty;
+ };
+ func(hasProperty);
+ b();
+ if (hasProperty)
+ hasProperty = 1;
+ return hasProperty = 1;
+ }
+}