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