[cfe-commits] r113027 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprScalar.cpp test/SemaCXX/blocks.cpp

Douglas Gregor dgregor at apple.com
Fri Sep 3 16:28:46 PDT 2010


On Sep 3, 2010, at 4:07 PM, Fariborz Jahanian wrote:

> Author: fjahanian
> Date: Fri Sep  3 18:07:53 2010
> New Revision: 113027
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=113027&view=rev
> Log:
> Truncate block variable of bool type to i1 when its
> value is used. This matches with non-block variable
> use of bool type. (Fixes radar 8390062).

This is great, thank you!

	- Doug

> Modified:
>    cfe/trunk/lib/CodeGen/CGDecl.cpp
>    cfe/trunk/lib/CodeGen/CGExpr.cpp
>    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>    cfe/trunk/test/SemaCXX/blocks.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=113027&r1=113026&r2=113027&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Sep  3 18:07:53 2010
> @@ -373,7 +373,7 @@
>   }
> 
>   // T x;
> -  Types.push_back(ConvertType(Ty));
> +  Types.push_back(ConvertTypeForMem(Ty));
> 
>   const llvm::Type *T = llvm::StructType::get(VMContext, Types, Packed);
> 
> 
> Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=113027&r1=113026&r2=113027&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Sep  3 18:07:53 2010
> @@ -335,24 +335,6 @@
>   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);
> 
> 
> Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=113027&r1=113026&r2=113027&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Sep  3 18:07:53 2010
> @@ -1118,7 +1118,7 @@
>   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());
> }
> 
> //===----------------------------------------------------------------------===//
> 
> Modified: cfe/trunk/test/SemaCXX/blocks.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/blocks.cpp?rev=113027&r1=113026&r2=113027&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/blocks.cpp (original)
> +++ cfe/trunk/test/SemaCXX/blocks.cpp Fri Sep  3 18:07:53 2010
> @@ -48,16 +48,23 @@
> 
>   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;
>   }
> }
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list