]> granicus.if.org Git - clang/commitdiff
Define __weak attribute for objective-c pointers in
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 12 Jan 2010 18:33:57 +0000 (18:33 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 12 Jan 2010 18:33:57 +0000 (18:33 +0000)
win32 targets. Fixes radar 7530235. Daniel please review.

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

lib/Basic/Targets.cpp
test/Rewriter/rewrite-weak-attr.m [new file with mode: 0644]

index ac13b950752fcd313c7c232da6f9f955d9a73040..ef3cf89299e417e4b51817b75c3842c1944f5b7a 100644 (file)
@@ -994,6 +994,10 @@ public:
     DefineStd(Builder, "WIN32", Opts);
     DefineStd(Builder, "WINNT", Opts);
     Builder.defineMacro("_X86_");
+    if (Opts.ObjC1)
+      // __weak is always defined, for use in blocks and with objc pointers,
+      // even for i686-pc-win32 targets.
+      Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
   }
 };
 } // end anonymous namespace
diff --git a/test/Rewriter/rewrite-weak-attr.m b/test/Rewriter/rewrite-weak-attr.m
new file mode 100644 (file)
index 0000000..2e559ee
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -fblocks -Dnil=0 -rewrite-objc  -o - %s
+int main() {
+        __weak __block id foo = nil;
+        __block id foo2 = nil;
+        id foo3 = nil;
+        
+        void (^myblock)() = ^{
+                foo = nil;
+                foo2 = nil;
+                [foo3 bar];
+                id foo4 = foo3;
+        };
+}