]> granicus.if.org Git - clang/commitdiff
Cope with llvm's reference to bool type of 'i1' vs. clang's
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 3 Sep 2010 21:36:02 +0000 (21:36 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 3 Sep 2010 21:36:02 +0000 (21:36 +0000)
type of 'i8' for the same for __block variables of
type bool. refixes radar 8382559.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113015 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/SemaCXX/blocks.cpp

index 06c657fa92619948a4f39200b97125a88e5315ef..b4d0e1399304a81b24a74d69f4432697c4ea1c0d 100644 (file)
@@ -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);
index baa79e7d89717ab12c54edb5ca677611251d7d36..4fd9941a2e3eb9653d46c712719eb73ad90b9d64 100644 (file)
@@ -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;
+  }
+}