[cfe-commits] r113015 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/SemaCXX/blocks.cpp
Fariborz Jahanian
fjahanian at apple.com
Fri Sep 3 14:36:02 PDT 2010
Author: fjahanian
Date: Fri Sep 3 16:36:02 2010
New Revision: 113015
URL: http://llvm.org/viewvc/llvm-project?rev=113015&view=rev
Log:
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.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/SemaCXX/blocks.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=113015&r1=113014&r2=113015&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Sep 3 16:36:02 2010
@@ -335,6 +335,23 @@
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/test/SemaCXX/blocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/blocks.cpp?rev=113015&r1=113014&r2=113015&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/blocks.cpp (original)
+++ cfe/trunk/test/SemaCXX/blocks.cpp Fri Sep 3 16:36:02 2010
@@ -41,3 +41,23 @@
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;
+ }
+}
More information about the cfe-commits
mailing list