aboutsummaryrefslogtreecommitdiff
path: root/test/Rewriter
diff options
context:
space:
mode:
Diffstat (limited to 'test/Rewriter')
-rw-r--r--test/Rewriter/blockcast3.mm23
-rw-r--r--test/Rewriter/rewrite-block-pointer.mm16
-rw-r--r--test/Rewriter/rewrite-byref-vars.mm10
-rw-r--r--test/Rewriter/rewrite-cast-ivar-access.mm53
-rw-r--r--test/Rewriter/rewrite-category-property.mm15
-rw-r--r--test/Rewriter/rewrite-implementation.mm13
-rw-r--r--test/Rewriter/rewrite-message-expr.mm25
-rw-r--r--test/Rewriter/rewrite-nested-ivar.mm33
-rw-r--r--test/Rewriter/rewrite-protocol-qualified.mm41
-rw-r--r--test/Rewriter/rewrite-typeof.mm21
-rw-r--r--test/Rewriter/rewrite-unique-block-api.mm31
11 files changed, 280 insertions, 1 deletions
diff --git a/test/Rewriter/blockcast3.mm b/test/Rewriter/blockcast3.mm
new file mode 100644
index 000000000000..97f417cec9ef
--- /dev/null
+++ b/test/Rewriter/blockcast3.mm
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7607781
+
+typedef struct {
+ int a;
+ int b;
+} mystruct;
+
+void g(int (^block)(mystruct s)) {
+ mystruct x;
+ int v = block(x);
+}
+
+void f(const void **arg) {
+ __block const void **q = arg;
+ g(^(mystruct s){
+ *q++ = (void*)s.a;
+ return 314;
+ });
+}
+
+// CHECK-LP: (struct __Block_byref_q_0 *)&q
diff --git a/test/Rewriter/rewrite-block-pointer.mm b/test/Rewriter/rewrite-block-pointer.mm
new file mode 100644
index 000000000000..b03b7a9dec0a
--- /dev/null
+++ b/test/Rewriter/rewrite-block-pointer.mm
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7638400
+
+@interface X
+@end
+
+void foo(void (^block)(int));
+
+@implementation X
+static void enumerateIt(void (^block)(id, id, char *)) {
+ foo(^(int idx) { });
+}
+@end
+
+// CHECK-LP: static void enumerateIt(void (*)(id, id, char *));
diff --git a/test/Rewriter/rewrite-byref-vars.mm b/test/Rewriter/rewrite-byref-vars.mm
index 1489c5947293..58b925a2b28c 100644
--- a/test/Rewriter/rewrite-byref-vars.mm
+++ b/test/Rewriter/rewrite-byref-vars.mm
@@ -36,9 +36,19 @@ __declspec(dllexport) extern "C" __declspec(dllexport) void XXXXBreakTheRewriter
id list;
}
- (void) Meth;
+// radar 7589385 use before definition
+- (void) allObjects;
@end
@implementation I
+// radar 7589385 use before definition
+- (void) allObjects {
+ __attribute__((__blocks__(byref))) id *listp;
+
+ ^(void) {
+ *listp++ = 0;
+ };
+}
- (void) Meth { __attribute__((__blocks__(byref))) void ** listp = (void **)list; }
@end
diff --git a/test/Rewriter/rewrite-cast-ivar-access.mm b/test/Rewriter/rewrite-cast-ivar-access.mm
new file mode 100644
index 000000000000..c04cbab40369
--- /dev/null
+++ b/test/Rewriter/rewrite-cast-ivar-access.mm
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7575882
+
+@interface F {
+ int supervar;
+}
+@end
+
+@interface G : F {
+@public
+ int ivar;
+}
+@end
+
+@implementation G
+- (void)foo:(F *)arg {
+ int q = arg->supervar;
+ int v = ((G *)arg)->ivar;
+}
+@end
+
+void objc_assign_strongCast(id);
+void __CFAssignWithWriteBarrier(void **location, void *value) {
+ objc_assign_strongCast((id)value);
+}
+
+// radar 7607605
+@interface RealClass {
+ @public
+ int f;
+}
+@end
+
+@implementation RealClass
+@end
+
+@interface Foo {
+ id reserved;
+}
+@end
+
+@implementation Foo
+- (void)bar {
+ ((RealClass*)reserved)->f = 99;
+}
+@end
+
+// CHECK-LP: ((struct G_IMPL *)arg)->ivar
+
+// CHECK-LP: objc_assign_strongCast((id)value)
+
+// CHECK-LP: ((struct RealClass_IMPL *)((RealClass *)((struct Foo_IMPL *)self)->reserved))->f
diff --git a/test/Rewriter/rewrite-category-property.mm b/test/Rewriter/rewrite-category-property.mm
new file mode 100644
index 000000000000..6b8f07622234
--- /dev/null
+++ b/test/Rewriter/rewrite-category-property.mm
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x objective-c++ -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7630636
+
+@class Y, Z;
+
+@interface A
+@property (readonly) Y *y;
+@end
+
+@interface A (cat)
+@property (readonly) Z *z;
+@end
+
+// CHECK-LP: // @property (readonly) Z *z;
diff --git a/test/Rewriter/rewrite-implementation.mm b/test/Rewriter/rewrite-implementation.mm
new file mode 100644
index 000000000000..608707c43034
--- /dev/null
+++ b/test/Rewriter/rewrite-implementation.mm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -DSEL="void *" -S %t-rw.cpp
+// radar 7649577
+
+@interface a
+@end
+
+@interface b : a
+@end
+
+@implementation b
+@end
+
diff --git a/test/Rewriter/rewrite-message-expr.mm b/test/Rewriter/rewrite-message-expr.mm
new file mode 100644
index 000000000000..d909f3ef93c3
--- /dev/null
+++ b/test/Rewriter/rewrite-message-expr.mm
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7617047
+
+@interface Baz
+- (id)y;
++ (id)z;
+@end
+
+@interface Foo {
+@public
+ int bar;
+}
+@end
+
+extern Foo* x(id a);
+
+int f(Baz *baz) {
+ int i = x([Baz z])->bar;
+ int j = ((Foo*)[Baz z])->bar;
+ int k = x([baz y])->bar;
+ return i+j+k;
+}
+
+// CHECK-LP: ((struct Foo_IMPL *)x(((id (*)(id, SEL))(void *)objc_msgSend)(objc_getClass("Baz"), sel_registerName("z"))))->bar
diff --git a/test/Rewriter/rewrite-nested-ivar.mm b/test/Rewriter/rewrite-nested-ivar.mm
new file mode 100644
index 000000000000..bbc9d28d2513
--- /dev/null
+++ b/test/Rewriter/rewrite-nested-ivar.mm
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7583971
+
+
+@interface NSURLResponse {
+@public
+ NSURLResponse *InnerResponse;
+}
+@end
+
+@interface NSCachedURLResponseInternal
+{
+ @public
+ NSURLResponse *response;
+}
+@end
+
+@interface NSCachedURLResponse
+{
+ @private
+ NSCachedURLResponseInternal *_internal;
+}
+- (void) Meth;
+@end
+
+@implementation NSCachedURLResponse
+- (void) Meth {
+ _internal->response->InnerResponse = 0;
+ }
+@end
+
+// CHECK-LP: ((struct NSURLResponse_IMPL *)((struct NSCachedURLResponseInternal_IMPL *)((struct NSCachedURLResponse_IMPL *)self)->_internal)->response)->InnerResponse
diff --git a/test/Rewriter/rewrite-protocol-qualified.mm b/test/Rewriter/rewrite-protocol-qualified.mm
new file mode 100644
index 000000000000..e91c3db8616f
--- /dev/null
+++ b/test/Rewriter/rewrite-protocol-qualified.mm
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7589414
+
+@protocol NSPortDelegate;
+@interface NSConnection @end
+
+@interface NSMessagePort
+- (void) clone;
+@end
+
+@implementation NSMessagePort
+- (void) clone {
+ NSConnection <NSPortDelegate> *conn = 0;
+ id <NSPortDelegate> *idc = 0;
+}
+@end
+
+// radar 7607413
+@protocol Proto1, Proto2;
+
+@protocol Proto
+@end
+
+unsigned char func(id<Proto1, Proto2> inProxy);
+
+id bar(id);
+
+void f() {
+ id a;
+ id b = bar((id <Proto>)a);
+}
+
+// CHECK-LP: NSConnection /*<NSPortDelegate>*/ *conn = 0;
+
+// CHECK-LP: id /*<NSPortDelegate>*/ *idc = 0;
+
+// CHECK-LP: func(id/*<Proto1, Proto2>*/ inProxy);
+
+// CHECK-LP: bar((id /*<Proto>*/)a);
+
diff --git a/test/Rewriter/rewrite-typeof.mm b/test/Rewriter/rewrite-typeof.mm
index f95cd9ac7c76..b859ac3d684c 100644
--- a/test/Rewriter/rewrite-typeof.mm
+++ b/test/Rewriter/rewrite-typeof.mm
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -o - %s
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
extern "C" {
extern "C" void *_Block_copy(const void *aBlock);
@@ -18,3 +19,21 @@ int main() {
return 0;
}
+// CHECK-LP: ((void (^)(void))_Block_copy((const void *)(b)))
+
+// radar 7628153
+void f() {
+ int a;
+ __typeof__(a) aVal = a;
+ char *a1t = (char *)@encode(__typeof__(a));
+ __typeof__(aVal) bVal;
+ char *a2t = (char *)@encode(__typeof__(bVal));
+ __typeof__(bVal) cVal = bVal;
+ char *a3t = (char *)@encode(__typeof__(cVal));
+
+}
+
+
+// CHECK-LP: int aVal = a;
+
+// CHECK-LP: int bVal;
diff --git a/test/Rewriter/rewrite-unique-block-api.mm b/test/Rewriter/rewrite-unique-block-api.mm
new file mode 100644
index 000000000000..780a3f0a5e2b
--- /dev/null
+++ b/test/Rewriter/rewrite-unique-block-api.mm
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7630551
+
+void f(void (^b)(char c));
+
+@interface a
+- (void)processStuff;
+@end
+
+@implementation a
+- (void)processStuff {
+ f(^(char x) { });
+}
+@end
+
+@interface b
+- (void)processStuff;
+@end
+
+@implementation b
+- (void)processStuff {
+ f(^(char x) { });
+}
+@end
+
+// CHECK-LP: struct __a__processStuff_block_impl_0
+// CHECK-LP: static void __a__processStuff_block_func_0
+
+// CHECK-LP: struct __b__processStuff_block_impl_0
+// CHECK-LP: static void __b__processStuff_block_func_0