Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Patrick Beard | b2f6820 | 2012-04-06 18:12:22 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fmodules -fmodule-cache-path %t -I %S/Inputs %s -verify -Wno-objc-root-class |
| 3 | // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodule-cache-path %t -I %S/Inputs %s -verify -Wno-objc-root-class |
Douglas Gregor | 0f75323 | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 4 | @class C2; |
| 5 | @class C3; |
| 6 | @class C3; |
Ted Kremenek | 32ad2ee | 2012-03-01 22:07:04 +0000 | [diff] [blame] | 7 | @__experimental_modules_import redecl_merge_left; |
Douglas Gregor | 447af24 | 2012-01-05 01:11:47 +0000 | [diff] [blame] | 8 | typedef struct my_struct_type *my_struct_ref; |
Douglas Gregor | dba9361 | 2012-01-01 21:47:52 +0000 | [diff] [blame] | 9 | @protocol P4; |
Douglas Gregor | 0f75323 | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 10 | @class C3; |
| 11 | @class C3; |
Ted Kremenek | 32ad2ee | 2012-03-01 22:07:04 +0000 | [diff] [blame] | 12 | @__experimental_modules_import redecl_merge_right; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 13 | |
| 14 | @implementation A |
| 15 | - (Super*)init { return self; } |
| 16 | @end |
| 17 | |
| 18 | void f(A *a) { |
| 19 | [a init]; |
| 20 | } |
| 21 | |
| 22 | @class A; |
| 23 | |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 24 | B *f1() { |
| 25 | return [B create_a_B]; |
| 26 | } |
| 27 | |
Douglas Gregor | ecb1938 | 2011-12-19 15:27:36 +0000 | [diff] [blame] | 28 | @class B; |
| 29 | |
Douglas Gregor | 27c6da2 | 2012-01-01 20:30:41 +0000 | [diff] [blame] | 30 | void testProtoMerge(id<P1> p1, id<P2> p2) { |
| 31 | [p1 protoMethod1]; |
| 32 | [p2 protoMethod2]; |
| 33 | } |
| 34 | |
Douglas Gregor | 1ca4a5c | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 35 | struct S1 { |
| 36 | int s1_field; |
| 37 | }; |
| 38 | |
| 39 | struct S3 { |
| 40 | int s3_field; |
| 41 | }; |
| 42 | |
| 43 | void testTagMerge() { |
| 44 | consume_S1(produce_S1()); |
| 45 | struct S2 s2; |
| 46 | s2.field = 0; |
| 47 | consume_S2(produce_S2()); |
| 48 | struct S1 s1; |
| 49 | s1.s1_field = 0; |
| 50 | consume_S3(produce_S3()); |
| 51 | struct S4 s4; |
| 52 | s4.field = 0; |
| 53 | consume_S4(produce_S4()); |
| 54 | struct S3 s3; |
| 55 | s3.s3_field = 0; |
| 56 | } |
| 57 | |
Douglas Gregor | 7a53740 | 2012-01-03 23:26:26 +0000 | [diff] [blame] | 58 | void testTypedefMerge(int i, double d) { |
| 59 | T1 *ip = &i; |
| 60 | // in other file: expected-note{{candidate found by name lookup is 'T2'}} |
| 61 | // FIXME: Typedefs aren't actually merged in the sense of other merges, because |
| 62 | // we should only merge them when the types are identical. |
| 63 | // in other file: expected-note{{candidate found by name lookup is 'T2'}} |
Douglas Gregor | 7076281 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 64 | // in other file: expected-note{{candidate function}} |
Douglas Gregor | 7a53740 | 2012-01-03 23:26:26 +0000 | [diff] [blame] | 65 | T2 *dp = &d; // expected-error{{reference to 'T2' is ambiguous}} |
| 66 | } |
| 67 | |
Douglas Gregor | 7076281 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 68 | void testFuncMerge(int i) { |
| 69 | func0(i); |
| 70 | // in other file: expected-note{{candidate function}} |
| 71 | func1(i); |
| 72 | func2(i); // expected-error{{call to 'func2' is ambiguous}} |
| 73 | } |
| 74 | |
Douglas Gregor | 4791fa2 | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 75 | void testVarMerge(int i) { |
| 76 | var1 = i; |
| 77 | // in other files: expected-note 2{{candidate found by name lookup is 'var2'}} |
| 78 | var2 = i; // expected-error{{reference to 'var2' is ambiguous}} |
| 79 | // in other files: expected-note 2{{candidate found by name lookup is 'var3'}} |
| 80 | var3 = i; // expected-error{{reference to 'var3' is ambiguous}} |
| 81 | } |
| 82 | |
Douglas Gregor | 2ccd89c | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 83 | // Test redeclarations of entities in explicit submodules, to make |
| 84 | // sure we're maintaining the declaration chains even when normal name |
| 85 | // lookup can't see what we're looking for. |
| 86 | void testExplicit() { |
| 87 | Explicit *e; |
| 88 | int *(*fp)(void) = &explicit_func; |
| 89 | int *ip = explicit_func(); |
| 90 | |
| 91 | // FIXME: Should complain about definition not having been imported. |
| 92 | struct explicit_struct es = { 0 }; |
| 93 | } |
| 94 | |
Douglas Gregor | 0f75323 | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 95 | // Test resolution of declarations from multiple modules with no |
| 96 | // common original declaration. |
| 97 | void test_C(C *c) { |
| 98 | c = get_a_C(); |
| 99 | accept_a_C(c); |
| 100 | } |
| 101 | |
| 102 | void test_C2(C2 *c2) { |
| 103 | c2 = get_a_C2(); |
| 104 | accept_a_C2(c2); |
| 105 | } |
| 106 | |
| 107 | void test_C3(C3 *c3) { |
| 108 | c3 = get_a_C3(); |
| 109 | accept_a_C3(c3); |
| 110 | } |
| 111 | |
Douglas Gregor | cce54aa | 2011-12-22 19:44:59 +0000 | [diff] [blame] | 112 | C4 *global_C4; |
Douglas Gregor | cc32b44 | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 113 | |
| 114 | ClassWithDef *cwd1; |
| 115 | |
Ted Kremenek | 32ad2ee | 2012-03-01 22:07:04 +0000 | [diff] [blame] | 116 | @__experimental_modules_import redecl_merge_left_left; |
Douglas Gregor | cce54aa | 2011-12-22 19:44:59 +0000 | [diff] [blame] | 117 | |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 118 | void test_C4a(C4 *c4) { |
Douglas Gregor | cce54aa | 2011-12-22 19:44:59 +0000 | [diff] [blame] | 119 | global_C4 = c4 = get_a_C4(); |
| 120 | accept_a_C4(c4); |
| 121 | } |
| 122 | |
Douglas Gregor | cc32b44 | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 123 | void test_ClassWithDef(ClassWithDef *cwd) { |
| 124 | [cwd method]; |
| 125 | } |
| 126 | |
Ted Kremenek | 32ad2ee | 2012-03-01 22:07:04 +0000 | [diff] [blame] | 127 | @__experimental_modules_import redecl_merge_bottom; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 128 | |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 129 | void test_C4b() { |
| 130 | if (&refers_to_C4) { |
| 131 | } |
| 132 | } |
| 133 | |
Douglas Gregor | ecb1938 | 2011-12-19 15:27:36 +0000 | [diff] [blame] | 134 | @implementation B |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 135 | + (B*)create_a_B { return 0; } |
Douglas Gregor | ecb1938 | 2011-12-19 15:27:36 +0000 | [diff] [blame] | 136 | @end |
| 137 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 138 | void g(A *a) { |
| 139 | [a init]; |
| 140 | } |
Douglas Gregor | f63b0a5 | 2011-12-19 18:19:24 +0000 | [diff] [blame] | 141 | |
Douglas Gregor | dba9361 | 2012-01-01 21:47:52 +0000 | [diff] [blame] | 142 | @protocol P3 |
| 143 | - (void)p3_method; |
| 144 | @end |
| 145 | |
| 146 | id<P4> p4; |
| 147 | id<P3> p3; |
| 148 | |
Douglas Gregor | f63b0a5 | 2011-12-19 18:19:24 +0000 | [diff] [blame] | 149 | #ifdef __cplusplus |
| 150 | void testVector() { |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 151 | Vector<int> vec_int; |
| 152 | vec_int.push_back(0); |
Douglas Gregor | f63b0a5 | 2011-12-19 18:19:24 +0000 | [diff] [blame] | 153 | } |
| 154 | #endif |
Douglas Gregor | 0f75323 | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 155 | |
Douglas Gregor | 91534a3 | 2012-01-13 23:49:34 +0000 | [diff] [blame] | 156 | // Make sure we don't get conflicts with 'id'. |
| 157 | funcptr_with_id fid; |
| 158 | id id_global; |