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