xref: /minix3/external/bsd/llvm/dist/clang/test/Modules/redecl-merge.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: rm -rf %t
2*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fmodules -Wreturn-type -fmodules-cache-path=%t -I %S/Inputs %s -verify -Wno-objc-root-class
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc@class C2;
5*f4a2713aSLionel Sambuc@class C3;
6*f4a2713aSLionel Sambuc@class C3;
7*f4a2713aSLionel Sambuc@import redecl_merge_left;
8*f4a2713aSLionel Sambuctypedef struct my_struct_type *my_struct_ref;
9*f4a2713aSLionel Sambuc@protocol P4;
10*f4a2713aSLionel Sambuc@class C3;
11*f4a2713aSLionel Sambuc@class C3;
12*f4a2713aSLionel Sambuc
13*f4a2713aSLionel Sambucint *call_eventually_noreturn(void) {
14*f4a2713aSLionel Sambuc  eventually_noreturn();
15*f4a2713aSLionel Sambuc} // expected-warning{{control reaches end of non-void function}}
16*f4a2713aSLionel Sambuc
17*f4a2713aSLionel Sambucint *call_eventually_noreturn2(void) {
18*f4a2713aSLionel Sambuc  eventually_noreturn2();
19*f4a2713aSLionel Sambuc} // expected-warning{{control reaches end of non-void function}}
20*f4a2713aSLionel Sambuc
21*f4a2713aSLionel Sambuc@import redecl_merge_right;
22*f4a2713aSLionel Sambuc
23*f4a2713aSLionel Sambucint *call_eventually_noreturn_again(void) {
24*f4a2713aSLionel Sambuc  eventually_noreturn();
25*f4a2713aSLionel Sambuc}
26*f4a2713aSLionel Sambuc
27*f4a2713aSLionel Sambucint *call_eventually_noreturn2_again(void) {
28*f4a2713aSLionel Sambuc  // noreturn and non-noreturn functions have different types
29*f4a2713aSLionel Sambuc  eventually_noreturn2(); // expected-error{{call to 'eventually_noreturn2' is ambiguous}}
30*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-left.h:93{{candidate function}}
31*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-right.h:90{{candidate function}}
32*f4a2713aSLionel Sambuc}
33*f4a2713aSLionel Sambuc
34*f4a2713aSLionel Sambuc@implementation A
35*f4a2713aSLionel Sambuc- (Super*)init { return self; }
36*f4a2713aSLionel Sambuc@end
37*f4a2713aSLionel Sambuc
38*f4a2713aSLionel Sambucvoid f(A *a) {
39*f4a2713aSLionel Sambuc  [a init];
40*f4a2713aSLionel Sambuc}
41*f4a2713aSLionel Sambuc
42*f4a2713aSLionel Sambuc@class A;
43*f4a2713aSLionel Sambuc
44*f4a2713aSLionel SambucB *f1() {
45*f4a2713aSLionel Sambuc  return [B create_a_B];
46*f4a2713aSLionel Sambuc}
47*f4a2713aSLionel Sambuc
48*f4a2713aSLionel Sambuc@class B;
49*f4a2713aSLionel Sambuc
50*f4a2713aSLionel Sambucvoid testProtoMerge(id<P1> p1, id<P2> p2) {
51*f4a2713aSLionel Sambuc  [p1 protoMethod1];
52*f4a2713aSLionel Sambuc  [p2 protoMethod2];
53*f4a2713aSLionel Sambuc}
54*f4a2713aSLionel Sambuc
55*f4a2713aSLionel Sambucstruct S1 {
56*f4a2713aSLionel Sambuc  int s1_field;
57*f4a2713aSLionel Sambuc};
58*f4a2713aSLionel Sambuc
59*f4a2713aSLionel Sambucstruct S3 {
60*f4a2713aSLionel Sambuc  int s3_field;
61*f4a2713aSLionel Sambuc};
62*f4a2713aSLionel Sambuc
63*f4a2713aSLionel Sambucvoid testTagMerge() {
64*f4a2713aSLionel Sambuc  consume_S1(produce_S1());
65*f4a2713aSLionel Sambuc  struct S2 s2;
66*f4a2713aSLionel Sambuc  s2.field = 0;
67*f4a2713aSLionel Sambuc  consume_S2(produce_S2());
68*f4a2713aSLionel Sambuc  struct S1 s1;
69*f4a2713aSLionel Sambuc  s1.s1_field = 0;
70*f4a2713aSLionel Sambuc  consume_S3(produce_S3());
71*f4a2713aSLionel Sambuc  struct S4 s4;
72*f4a2713aSLionel Sambuc  s4.field = 0;
73*f4a2713aSLionel Sambuc  consume_S4(produce_S4());
74*f4a2713aSLionel Sambuc  struct S3 s3;
75*f4a2713aSLionel Sambuc  s3.s3_field = 0;
76*f4a2713aSLionel Sambuc}
77*f4a2713aSLionel Sambuc
78*f4a2713aSLionel Sambucvoid testTypedefMerge(int i, double d) {
79*f4a2713aSLionel Sambuc  T1 *ip = &i;
80*f4a2713aSLionel Sambuc  // FIXME: Typedefs aren't actually merged in the sense of other merges, because
81*f4a2713aSLionel Sambuc  // we should only merge them when the types are identical.
82*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-left.h:60{{candidate found by name lookup is 'T2'}}
83*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-right.h:63{{candidate found by name lookup is 'T2'}}
84*f4a2713aSLionel Sambuc  T2 *dp = &d; // expected-error{{reference to 'T2' is ambiguous}}
85*f4a2713aSLionel Sambuc}
86*f4a2713aSLionel Sambuc
87*f4a2713aSLionel Sambucvoid testFuncMerge(int i) {
88*f4a2713aSLionel Sambuc  func0(i);
89*f4a2713aSLionel Sambuc  func1(i);
90*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-left.h:64{{candidate function}}
91*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-right.h:70{{candidate function}}
92*f4a2713aSLionel Sambuc  func2(i); // expected-error{{call to 'func2' is ambiguous}}
93*f4a2713aSLionel Sambuc}
94*f4a2713aSLionel Sambuc
95*f4a2713aSLionel Sambucvoid testVarMerge(int i) {
96*f4a2713aSLionel Sambuc  var1 = i;
97*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-left.h:77{{candidate found by name lookup is 'var2'}}
98*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-right.h:77{{candidate found by name lookup is 'var2'}}
99*f4a2713aSLionel Sambuc  var2 = i; // expected-error{{reference to 'var2' is ambiguous}}
100*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-left.h:79{{candidate found by name lookup is 'var3'}}
101*f4a2713aSLionel Sambuc  // expected-note@Inputs/redecl-merge-right.h:79{{candidate found by name lookup is 'var3'}}
102*f4a2713aSLionel Sambuc  var3 = i; // expected-error{{reference to 'var3' is ambiguous}}
103*f4a2713aSLionel Sambuc}
104*f4a2713aSLionel Sambuc
105*f4a2713aSLionel Sambuc// Test redeclarations of entities in explicit submodules, to make
106*f4a2713aSLionel Sambuc// sure we're maintaining the declaration chains even when normal name
107*f4a2713aSLionel Sambuc// lookup can't see what we're looking for.
108*f4a2713aSLionel Sambucvoid testExplicit() {
109*f4a2713aSLionel Sambuc  Explicit *e;
110*f4a2713aSLionel Sambuc  int *(*fp)(void) = &explicit_func;
111*f4a2713aSLionel Sambuc  int *ip = explicit_func();
112*f4a2713aSLionel Sambuc
113*f4a2713aSLionel Sambuc  // FIXME: Should complain about definition not having been imported.
114*f4a2713aSLionel Sambuc  struct explicit_struct es = { 0 };
115*f4a2713aSLionel Sambuc}
116*f4a2713aSLionel Sambuc
117*f4a2713aSLionel Sambuc// Test resolution of declarations from multiple modules with no
118*f4a2713aSLionel Sambuc// common original declaration.
119*f4a2713aSLionel Sambucvoid test_C(C *c) {
120*f4a2713aSLionel Sambuc  c = get_a_C();
121*f4a2713aSLionel Sambuc  accept_a_C(c);
122*f4a2713aSLionel Sambuc}
123*f4a2713aSLionel Sambuc
124*f4a2713aSLionel Sambucvoid test_C2(C2 *c2) {
125*f4a2713aSLionel Sambuc  c2 = get_a_C2();
126*f4a2713aSLionel Sambuc  accept_a_C2(c2);
127*f4a2713aSLionel Sambuc}
128*f4a2713aSLionel Sambuc
129*f4a2713aSLionel Sambucvoid test_C3(C3 *c3) {
130*f4a2713aSLionel Sambuc  c3 = get_a_C3();
131*f4a2713aSLionel Sambuc  accept_a_C3(c3);
132*f4a2713aSLionel Sambuc}
133*f4a2713aSLionel Sambuc
134*f4a2713aSLionel SambucC4 *global_C4;
135*f4a2713aSLionel Sambuc
136*f4a2713aSLionel SambucClassWithDef *cwd1;
137*f4a2713aSLionel Sambuc
138*f4a2713aSLionel Sambuc@import redecl_merge_left_left;
139*f4a2713aSLionel Sambuc
140*f4a2713aSLionel Sambucvoid test_C4a(C4 *c4) {
141*f4a2713aSLionel Sambuc  global_C4 = c4 = get_a_C4();
142*f4a2713aSLionel Sambuc  accept_a_C4(c4);
143*f4a2713aSLionel Sambuc}
144*f4a2713aSLionel Sambuc
145*f4a2713aSLionel Sambucvoid test_ClassWithDef(ClassWithDef *cwd) {
146*f4a2713aSLionel Sambuc  [cwd method];
147*f4a2713aSLionel Sambuc}
148*f4a2713aSLionel Sambuc
149*f4a2713aSLionel Sambuc@import redecl_merge_bottom;
150*f4a2713aSLionel Sambuc
151*f4a2713aSLionel Sambucvoid test_C4b() {
152*f4a2713aSLionel Sambuc  if (&refers_to_C4) {
153*f4a2713aSLionel Sambuc  }
154*f4a2713aSLionel Sambuc}
155*f4a2713aSLionel Sambuc
156*f4a2713aSLionel Sambuc@implementation B
157*f4a2713aSLionel Sambuc+ (B*)create_a_B { return 0; }
158*f4a2713aSLionel Sambuc@end
159*f4a2713aSLionel Sambuc
160*f4a2713aSLionel Sambucvoid g(A *a) {
161*f4a2713aSLionel Sambuc  [a init];
162*f4a2713aSLionel Sambuc}
163*f4a2713aSLionel Sambuc
164*f4a2713aSLionel Sambuc@protocol P3
165*f4a2713aSLionel Sambuc- (void)p3_method;
166*f4a2713aSLionel Sambuc@end
167*f4a2713aSLionel Sambuc
168*f4a2713aSLionel Sambucid<P4> p4;
169*f4a2713aSLionel Sambucid<P3> p3;
170*f4a2713aSLionel Sambuc
171*f4a2713aSLionel Sambuc// Make sure we don't get conflicts with 'id'.
172*f4a2713aSLionel Sambucfuncptr_with_id fid;
173*f4a2713aSLionel Sambucid id_global;
174*f4a2713aSLionel Sambuc
175*f4a2713aSLionel Sambuc
176