]> granicus.if.org Git - clang/commitdiff
Truncate block variable of bool type to i1 when its
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 3 Sep 2010 23:07:53 +0000 (23:07 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 3 Sep 2010 23:07:53 +0000 (23:07 +0000)
value is used. This matches with non-block variable
use of bool type. (Fixes radar 8390062).

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

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

index 5017ce720cbba67b8c7620cbebc80354bd99667d..57e5236c67e5fb7b1bdd2fe910e73568fd43c518 100644 (file)
@@ -373,7 +373,7 @@ const llvm::Type *CodeGenFunction::BuildByRefType(const ValueDecl *D) {
   }
 
   // T x;
-  Types.push_back(ConvertType(Ty));
+  Types.push_back(ConvertTypeForMem(Ty));
   
   const llvm::Type *T = llvm::StructType::get(VMContext, Types, Packed);
   
index b4d0e1399304a81b24a74d69f4432697c4ea1c0d..3750ab80c3fcd4bd0a47f6dff21e84e1b59034b4 100644 (file)
@@ -335,24 +335,6 @@ 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 4e16f66ba422f6f7f6daadd398836ef6b9aaf4e8..2318cc4e9aebc6d57406bc86587acaf5cdf6fd53 100644 (file)
@@ -1118,7 +1118,7 @@ Value *ScalarExprEmitter::VisitBlockDeclRefExpr(const BlockDeclRefExpr *E) {
   llvm::Value *V = CGF.GetAddrOfBlockDecl(E);
   if (E->getType().isObjCGCWeak())
     return CGF.CGM.getObjCRuntime().EmitObjCWeakRead(CGF, V);
-  return Builder.CreateLoad(V, "tmp");
+  return CGF.EmitLoadOfScalar(V, false, 0, E->getType());
 }
 
 //===----------------------------------------------------------------------===//
index 4fd9941a2e3eb9653d46c712719eb73ad90b9d64..adbff553e6086e06c502b67af1f2619600464839 100644 (file)
@@ -48,16 +48,23 @@ namespace radar8382559 {
 
   int test3() {
     __attribute__((__blocks__(byref))) bool hasProperty = false;
+    bool has = true;
+
     bool (^b)() = ^ {
      func(hasProperty);
      if (hasProperty)
        hasProperty = 0;
+     if (has)
+       hasProperty = 1;
      return hasProperty;
      };
     func(hasProperty);
+    func(has);
     b();
     if (hasProperty)
       hasProperty = 1;
+    if (has)
+      has = 2;
     return hasProperty = 1;
   }
 }