xref: /minix3/external/bsd/llvm/dist/clang/test/Modules/macros.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: rm -rf %t
2f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_top %S/Inputs/module.map
3f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_left %S/Inputs/module.map
4f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_right %S/Inputs/module.map
5f4a2713aSLionel 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 // RUN: not %clang_cc1 -E -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix CHECK-PREPROCESSED %s
8f4a2713aSLionel Sambuc // FIXME: When we have a syntax for modules in C, use that.
9f4a2713aSLionel Sambuc // These notes come from headers in modules, and are bogus.
10f4a2713aSLionel Sambuc 
11f4a2713aSLionel Sambuc // FIXME: expected-note@Inputs/macros_left.h:11{{previous definition is here}}
12f4a2713aSLionel Sambuc // FIXME: expected-note@Inputs/macros_right.h:12{{previous definition is here}}
13f4a2713aSLionel Sambuc // expected-note@Inputs/macros_right.h:12{{expanding this definition of 'LEFT_RIGHT_DIFFERENT'}}
14f4a2713aSLionel Sambuc // expected-note@Inputs/macros_right.h:13{{expanding this definition of 'LEFT_RIGHT_DIFFERENT2'}}
15f4a2713aSLionel Sambuc // expected-note@Inputs/macros_left.h:14{{other definition of 'LEFT_RIGHT_DIFFERENT'}}
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc @import macros;
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc #ifndef INTEGER
20f4a2713aSLionel Sambuc #  error INTEGER macro should be visible
21f4a2713aSLionel Sambuc #endif
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc #ifdef FLOAT
24f4a2713aSLionel Sambuc #  error FLOAT macro should not be visible
25f4a2713aSLionel Sambuc #endif
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc #ifdef MODULE
28f4a2713aSLionel Sambuc #  error MODULE macro should not be visible
29f4a2713aSLionel Sambuc #endif
30f4a2713aSLionel Sambuc 
31f4a2713aSLionel Sambuc // CHECK-PREPROCESSED: double d
32f4a2713aSLionel Sambuc double d;
33f4a2713aSLionel Sambuc DOUBLE *dp = &d;
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc #__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}}
36f4a2713aSLionel Sambuc 
f()37f4a2713aSLionel Sambuc void f() {
38f4a2713aSLionel Sambuc   // CHECK-PREPROCESSED: int i = INTEGER;
39f4a2713aSLionel Sambuc   int i = INTEGER; // the value was exported, the macro was not.
40f4a2713aSLionel Sambuc   i += macros; // expanded from __MODULE__ within the 'macros' module.
41f4a2713aSLionel Sambuc }
42f4a2713aSLionel Sambuc 
43f4a2713aSLionel Sambuc #ifdef __MODULE__
44f4a2713aSLionel Sambuc # error Not building a module!
45f4a2713aSLionel Sambuc #endif
46f4a2713aSLionel Sambuc 
47f4a2713aSLionel Sambuc #if __building_module(macros)
48f4a2713aSLionel Sambuc # error Not building a module
49f4a2713aSLionel Sambuc #endif
50f4a2713aSLionel Sambuc 
51f4a2713aSLionel Sambuc // None of the modules we depend on have been imported, and therefore
52f4a2713aSLionel Sambuc // their macros should not be visible.
53f4a2713aSLionel Sambuc #ifdef LEFT
54f4a2713aSLionel Sambuc #  error LEFT should not be visible
55f4a2713aSLionel Sambuc #endif
56f4a2713aSLionel Sambuc 
57f4a2713aSLionel Sambuc #ifdef RIGHT
58f4a2713aSLionel Sambuc #  error RIGHT should not be visible
59f4a2713aSLionel Sambuc #endif
60f4a2713aSLionel Sambuc 
61f4a2713aSLionel Sambuc #ifdef TOP
62f4a2713aSLionel Sambuc #  error TOP should not be visible
63f4a2713aSLionel Sambuc #endif
64f4a2713aSLionel Sambuc 
65f4a2713aSLionel Sambuc // Import left module (which also imports top)
66f4a2713aSLionel Sambuc @import macros_left;
67f4a2713aSLionel Sambuc 
68f4a2713aSLionel Sambuc #ifndef LEFT
69f4a2713aSLionel Sambuc #  error LEFT should be visible
70f4a2713aSLionel Sambuc #endif
71f4a2713aSLionel Sambuc 
72f4a2713aSLionel Sambuc #ifdef RIGHT
73f4a2713aSLionel Sambuc #  error RIGHT should not be visible
74f4a2713aSLionel Sambuc #endif
75f4a2713aSLionel Sambuc 
76f4a2713aSLionel Sambuc #ifndef TOP
77f4a2713aSLionel Sambuc #  error TOP should be visible
78f4a2713aSLionel Sambuc #endif
79f4a2713aSLionel Sambuc 
80*0a6a1f1dSLionel Sambuc #ifdef TOP_LEFT_UNDEF
81*0a6a1f1dSLionel Sambuc #  error TOP_LEFT_UNDEF should not be defined
82f4a2713aSLionel Sambuc #endif
83f4a2713aSLionel Sambuc 
test1()84f4a2713aSLionel Sambuc void test1() {
85f4a2713aSLionel Sambuc   int i;
86f4a2713aSLionel Sambuc   TOP_RIGHT_REDEF *ip = &i;
87f4a2713aSLionel Sambuc }
88f4a2713aSLionel Sambuc 
89f4a2713aSLionel Sambuc #define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}} \
90f4a2713aSLionel Sambuc                                      // expected-note{{other definition of 'LEFT_RIGHT_DIFFERENT2'}}
91f4a2713aSLionel Sambuc 
92f4a2713aSLionel Sambuc // Import right module (which also imports top)
93f4a2713aSLionel Sambuc @import macros_right;
94f4a2713aSLionel Sambuc 
95f4a2713aSLionel Sambuc #undef LEFT_RIGHT_DIFFERENT3
96f4a2713aSLionel Sambuc 
97f4a2713aSLionel Sambuc #ifndef LEFT
98f4a2713aSLionel Sambuc #  error LEFT should be visible
99f4a2713aSLionel Sambuc #endif
100f4a2713aSLionel Sambuc 
101f4a2713aSLionel Sambuc #ifndef RIGHT
102f4a2713aSLionel Sambuc #  error RIGHT should be visible
103f4a2713aSLionel Sambuc #endif
104f4a2713aSLionel Sambuc 
105f4a2713aSLionel Sambuc #ifndef TOP
106f4a2713aSLionel Sambuc #  error TOP should be visible
107f4a2713aSLionel Sambuc #endif
108f4a2713aSLionel Sambuc 
test2()109f4a2713aSLionel Sambuc void test2() {
110f4a2713aSLionel Sambuc   int i;
111f4a2713aSLionel Sambuc   float f;
112f4a2713aSLionel Sambuc   double d;
113*0a6a1f1dSLionel Sambuc   TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition
114f4a2713aSLionel Sambuc 
115f4a2713aSLionel Sambuc   LEFT_RIGHT_IDENTICAL *ip = &i;
116f4a2713aSLionel Sambuc   LEFT_RIGHT_DIFFERENT *ip2 = &i; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}}
117f4a2713aSLionel Sambuc   LEFT_RIGHT_DIFFERENT2 *ip3 = &i; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT2}}
118f4a2713aSLionel Sambuc   int LEFT_RIGHT_DIFFERENT3;
119f4a2713aSLionel Sambuc }
120f4a2713aSLionel Sambuc 
121f4a2713aSLionel Sambuc #define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}}
122f4a2713aSLionel Sambuc 
test3()123f4a2713aSLionel Sambuc void test3() {
124f4a2713aSLionel Sambuc   double d;
125f4a2713aSLionel Sambuc   LEFT_RIGHT_DIFFERENT *dp = &d; // okay
126f4a2713aSLionel Sambuc   int x = FN_ADD(1,2);
127f4a2713aSLionel Sambuc }
128f4a2713aSLionel Sambuc 
129f4a2713aSLionel Sambuc #ifndef TOP_RIGHT_UNDEF
130f4a2713aSLionel Sambuc #  error TOP_RIGHT_UNDEF should still be defined
131f4a2713aSLionel Sambuc #endif
132f4a2713aSLionel Sambuc 
133*0a6a1f1dSLionel Sambuc @import macros_bottom;
134*0a6a1f1dSLionel Sambuc 
TDRUf()135*0a6a1f1dSLionel Sambuc TOP_DEF_RIGHT_UNDEF *TDRUf() { return TDRUp; }
136*0a6a1f1dSLionel Sambuc 
137f4a2713aSLionel Sambuc @import macros_right.undef;
138f4a2713aSLionel Sambuc 
139*0a6a1f1dSLionel Sambuc int TOP_DEF_RIGHT_UNDEF; // ok, no longer defined
140*0a6a1f1dSLionel Sambuc 
141*0a6a1f1dSLionel Sambuc // FIXME: When macros_right.undef is built, macros_top is visible because
142*0a6a1f1dSLionel Sambuc // the state from building macros_right leaks through, so macros_right.undef
143*0a6a1f1dSLionel Sambuc // undefines macros_top's macro.
144*0a6a1f1dSLionel Sambuc #ifdef TOP_RIGHT_UNDEF
145*0a6a1f1dSLionel Sambuc # error TOP_RIGHT_UNDEF should not be defined
146f4a2713aSLionel Sambuc #endif
147*0a6a1f1dSLionel Sambuc 
148*0a6a1f1dSLionel Sambuc @import macros_other;
149*0a6a1f1dSLionel Sambuc 
150*0a6a1f1dSLionel Sambuc #ifndef TOP_OTHER_UNDEF1
151*0a6a1f1dSLionel Sambuc # error TOP_OTHER_UNDEF1 should still be defined
152*0a6a1f1dSLionel Sambuc #endif
153*0a6a1f1dSLionel Sambuc 
154*0a6a1f1dSLionel Sambuc #ifndef TOP_OTHER_UNDEF2
155*0a6a1f1dSLionel Sambuc # error TOP_OTHER_UNDEF2 should still be defined
156*0a6a1f1dSLionel Sambuc #endif
157*0a6a1f1dSLionel Sambuc 
158*0a6a1f1dSLionel Sambuc #ifndef TOP_OTHER_REDEF1
159*0a6a1f1dSLionel Sambuc # error TOP_OTHER_REDEF1 should still be defined
160*0a6a1f1dSLionel Sambuc #endif
161*0a6a1f1dSLionel Sambuc int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}}
162*0a6a1f1dSLionel Sambuc // expected-note@macros_top.h:19 {{expanding this definition}}
163*0a6a1f1dSLionel Sambuc // expected-note@macros_other.h:4 {{other definition}}
164*0a6a1f1dSLionel Sambuc 
165*0a6a1f1dSLionel Sambuc #ifndef TOP_OTHER_REDEF2
166*0a6a1f1dSLionel Sambuc # error TOP_OTHER_REDEF2 should still be defined
167*0a6a1f1dSLionel Sambuc #endif
168*0a6a1f1dSLionel Sambuc int n2 = TOP_OTHER_REDEF2; // ok
169*0a6a1f1dSLionel Sambuc 
170*0a6a1f1dSLionel Sambuc int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
171