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