1 // RUN: rm -rf %t
2 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_top %S/Inputs/module.map
3 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_left %S/Inputs/module.map
4 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_right %S/Inputs/module.map
5 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros %S/Inputs/module.map
6 // RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s
7 
8 // This test checks some of the same things as macros.c, but imports modules in
9 // a different order.
10 
11 @import macros_other;
12 
13 int n0 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
14 
15 @import macros_top;
16 
17 TOP_OTHER_DEF_RIGHT_UNDEF *n0b; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_DEF_RIGHT_UNDEF'}}
18 // expected-note@macros_top.h:22 {{expanding this definition of 'TOP_OTHER_DEF_RIGHT_UNDEF'}}
19 // expected-note@macros_other.h:6 {{other definition of 'TOP_OTHER_DEF_RIGHT_UNDEF'}}
20 
21 @import macros_right;
22 @import macros_left;
23 
24 #ifdef TOP_LEFT_UNDEF
25 #  error TOP_LEFT_UNDEF should not be defined
26 #endif
27 
28 #ifndef TOP_RIGHT_UNDEF
29 #  error TOP_RIGHT_UNDEF should still be defined
30 #endif
31 
test()32 void test() {
33   float f;
34   TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition
35 
36   // Note, left's definition wins here, whereas right's definition wins in
37   // macros.c.
38   int i;
39   LEFT_RIGHT_IDENTICAL *ip = &i;
40   LEFT_RIGHT_DIFFERENT *ip2 = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}}
41   // expected-note@macros_left.h:14 {{expanding this}}
42   // expected-note@macros_right.h:12 {{other}}
43   LEFT_RIGHT_DIFFERENT2 *ip3 = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT2}}
44   // expected-note@macros_left.h:11 {{expanding this}}
45   // expected-note@macros_right.h:13 {{other}}
46 #undef LEFT_RIGHT_DIFFERENT3
47   int LEFT_RIGHT_DIFFERENT3;
48 }
49 
50 @import macros_right.undef;
51 
52 // FIXME: See macros.c.
53 #ifdef TOP_RIGHT_UNDEF
54 # error TOP_RIGHT_UNDEF should not be defined
55 #endif
56 
57 #ifndef TOP_OTHER_UNDEF1
58 # error TOP_OTHER_UNDEF1 should still be defined
59 #endif
60 
61 #ifndef TOP_OTHER_UNDEF2
62 # error TOP_OTHER_UNDEF2 should still be defined
63 #endif
64 
65 #ifndef TOP_OTHER_REDEF1
66 # error TOP_OTHER_REDEF1 should still be defined
67 #endif
68 int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}}
69 // expected-note@macros_top.h:19 {{expanding this definition}}
70 // expected-note@macros_other.h:4 {{other definition}}
71 
72 #ifndef TOP_OTHER_REDEF2
73 # error TOP_OTHER_REDEF2 should still be defined
74 #endif
75 int n2 = TOP_OTHER_REDEF2; // ok
76 
77 int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
78 
79 int top_redef_in_submodules = TOP_REDEF_IN_SUBMODULES;
80 @import macros_top.c;
test2()81 void test2() {
82   int TOP_REDEF_IN_SUBMODULES = top_redef_in_submodules;
83 }
84