[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaObjC / unsafe-perform-selector.m
blobce1009e220139943b5ec1542be0775ae533594a3
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s
3 @class Thread;
5 __attribute__((objc_root_class))
6 @interface NSObject
8 - (id)performSelector:(SEL)sel;
9 - (void)performSelectorInBackground:(SEL)sel withObject:(id)arg;
10 - (void)performSelectorOnMainThread:(SEL)sel;
12 - (void)performSelectorOnMainThread:(SEL)aSelector
13                            onThread:(Thread *)thread
14                          withObject:(id)arg
15                       waitUntilDone:(int)wait
16                               modes:(id *)array;
18 @end
20 typedef struct { int x; int y; int width; int height; } Rectangle;
22 struct Struct { Rectangle r; };
24 typedef union { int x; float f; } Union;
26 @interface Base : NSObject
28 - (struct Struct)returnsStruct2; // expected-note {{method 'returnsStruct2' that returns 'struct Struct' declared here}}
29 - (Union)returnsId;
31 @end
33 @protocol IP
35 - (Union)returnsUnion; // expected-note 2 {{method 'returnsUnion' that returns 'Union' declared here}}
37 @end
39 typedef __attribute__((__ext_vector_type__(3))) float float3;
40 typedef int int4 __attribute__ ((vector_size (16)));
42 @interface I : Base<IP>
44 - (Rectangle)returnsStruct; // expected-note 4 {{method 'returnsStruct' that returns 'Rectangle' declared here}}
45 - (id)returnsId; // shadows base 'returnsId'
46 - (int)returnsInt;
47 - (I *)returnPtr;
48 - (float3)returnsExtVector; // expected-note {{method 'returnsExtVector' that returns 'float3' (vector of 3 'float' values) declared here}}
49 - (int4)returnsVector; // expected-note {{method 'returnsVector' that returns 'int4' (vector of 4 'int' values) declared here}}
51 + (Rectangle)returnsStructClass; // expected-note 2 {{method 'returnsStructClass' that returns 'Rectangle' declared here}}
52 + (void)returnsUnion; // Not really
54 @end
56 void foo(I *i) {
57   [i performSelector: @selector(returnsStruct)]; // expected-warning {{'performSelector:' is incompatible with selectors that return a struct type}}
58   [i performSelectorInBackground: @selector(returnsStruct) withObject:0]; // expected-warning {{'performSelectorInBackground:withObject:' is incompatible with selectors that return a struct type}}
59   [i performSelector: ((@selector(returnsUnion)))]; // expected-warning {{'performSelector:' is incompatible with selectors that return a union type}}
60   [i performSelectorOnMainThread: @selector(returnsStruct2)]; // expected-warning {{'performSelectorOnMainThread:' is incompatible with selectors that return a struct type}}
61   [I performSelector: (@selector(returnsStructClass))]; // expected-warning {{'performSelector:' is incompatible with selectors that return a struct type}}
63   [i performSelector: @selector(returnsId)];
64   [i performSelector: @selector(returnsInt)];
65   [i performSelector: @selector(returnsPtr)];
66   [I performSelector: @selector(returnsUnion)]; // No warning expected
68   id obj = i;
69   [obj performSelector: @selector(returnsId)];
70   [obj performSelector: @selector(returnsStruct)];
73 @interface SubClass: I
75 @end
77 @interface SubClass ()
78 - (struct Struct)returnsSubStructExt; // expected-note {{method 'returnsSubStructExt' that returns 'struct Struct' declared here}} expected-note {{method 'returnsSubStructExt' declared here}}
79 @end
81 @implementation SubClass // expected-warning {{method definition for 'returnsSubStructExt' not found}}
83 - (struct Struct)returnsSubStructImpl { // expected-note {{method 'returnsSubStructImpl' that returns 'struct Struct' declared here}}
84   struct Struct Result;
85   return Result;
88 - (void)checkPrivateCalls {
89   [self performSelector: @selector(returnsSubStructExt)]; // expected-warning {{'performSelector:' is incompatible with selectors that return a struct type}}
90   [self performSelector: @selector(returnsSubStructImpl)]; // expected-warning {{'performSelector:' is incompatible with selectors that return a struct type}}
93 - (void)checkSuperCalls {
94   [super performSelector: @selector(returnsStruct)]; // expected-warning {{'performSelector:' is incompatible with selectors that return a struct type}}
95   [super performSelectorInBackground: @selector(returnsUnion) withObject: self]; // expected-warning {{'performSelectorInBackground:withObject:' is incompatible with selectors that return a union type}}
96   [super performSelector: @selector(returnsId)];
99 + (struct Struct)returnsSubStructClassImpl { // expected-note {{method 'returnsSubStructClassImpl' that returns 'struct Struct' declared here}}
100   struct Struct Result;
101   return Result;
104 + (void)checkClassPrivateCalls {
105   [self performSelector: @selector(returnsSubStructClassImpl)]; // expected-warning {{'performSelector:' is incompatible with selectors that return a struct type}}
108 + (void)checkClassSuperCalls {
109   [super performSelector: @selector(returnsStructClass)]; // expected-warning {{'performSelector:' is incompatible with selectors that return a struct type}}
110   [super performSelector: @selector(returnsUnion)]; // No warning expected
113 @end
115 @implementation I (LongPerformSelectors)
117 - (void)checkLongCallsFromCategory {
118   [self performSelectorOnMainThread: @selector(returnsStruct) onThread:0 withObject:self waitUntilDone:1 modes:0]; // expected-warning {{'performSelectorOnMainThread:onThread:withObject:waitUntilDone:modes:' is incompatible with selectors that return a struct type}}
121 - (void)checkVectorReturn {
122   [self performSelector: @selector(returnsExtVector)]; // expected-warning {{'performSelector:' is incompatible with selectors that return a vector type}}
123   [self performSelector: @selector(returnsVector)]; // expected-warning {{'performSelector:' is incompatible with selectors that return a vector type}}
126 @end