[cfe-commits] r83729 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenObjC/objc-read-weak-byref.m
Fariborz Jahanian
fjahanian at apple.com
Sat Oct 10 13:07:56 PDT 2009
Author: fjahanian
Date: Sat Oct 10 15:07:56 2009
New Revision: 83729
URL: http://llvm.org/viewvc/llvm-project?rev=83729&view=rev
Log:
Generate weak read barriers when reading a weak __block
variable inside the block.
Added:
cfe/trunk/test/CodeGenObjC/objc-read-weak-byref.m
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=83729&r1=83728&r2=83729&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Oct 10 15:07:56 2009
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "CodeGenFunction.h"
+#include "CGObjCRuntime.h"
#include "CodeGenModule.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
@@ -748,7 +749,10 @@
}
Value *ScalarExprEmitter::VisitBlockDeclRefExpr(const BlockDeclRefExpr *E) {
- return Builder.CreateLoad(CGF.GetAddrOfBlockDecl(E), false, "tmp");
+ llvm::Value *V = CGF.GetAddrOfBlockDecl(E);
+ if (E->getType().isObjCGCWeak())
+ return CGF.CGM.getObjCRuntime().EmitObjCWeakRead(CGF, V);
+ return Builder.CreateLoad(V, false, "tmp");
}
//===----------------------------------------------------------------------===//
Added: cfe/trunk/test/CodeGenObjC/objc-read-weak-byref.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/objc-read-weak-byref.m?rev=83729&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/objc-read-weak-byref.m (added)
+++ cfe/trunk/test/CodeGenObjC/objc-read-weak-byref.m Sat Oct 10 15:07:56 2009
@@ -0,0 +1,26 @@
+// RUN: clang-cc -fblocks -fobjc-gc -triple x86_64-apple-darwin -S %s -o %t-64.s &&
+// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s &&
+// RUN: clang-cc -fblocks -fobjc-gc -triple i386-apple-darwin -S %s -o %t-32.s &&
+// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s &&
+// RUN: true
+
+ at interface NSObject
+- copy;
+ at end
+
+int main() {
+ NSObject *object = 0;
+ __weak __block NSObject* weak_object = object;
+ void (^callback) (void) = [^{
+ if (weak_object)
+ [weak_object copy];
+ } copy];
+ callback();
+ return 0;
+}
+
+// CHECK-LP64: call _objc_read_weak
+// CHECK-LP64: call _objc_read_weak
+
+// CHECK-LP32: call L_objc_read_weak
+// CHECK-LP32: call L_objc_read_weak
More information about the cfe-commits
mailing list