blob: 92ea88a480203fca8ca092da6a43dfcb22a5db51 [file] [log] [blame]
Douglas Gregor42583322011-11-16 05:16:30 +00001// RUN: rm -rf %t
Douglas Gregor953a61f2013-02-07 19:01:24 +00002// 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
Stephen Hines651f13c2014-04-23 16:59:28 -07006// 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
Douglas Gregorc13a34b2012-01-03 19:32:59 +00008// FIXME: When we have a syntax for modules in C, use that.
Douglas Gregor6c6c54a2012-10-11 00:46:49 +00009// These notes come from headers in modules, and are bogus.
Douglas Gregore8219a62012-10-11 21:07:39 +000010
Andy Gibbsb42f2002013-04-17 08:06:46 +000011// 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'}}
Andy Gibbsb42f2002013-04-17 08:06:46 +000014// 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'}}
Douglas Gregor7143aab2011-09-01 17:04:32 +000016
Douglas Gregor1b257af2012-12-11 22:11:52 +000017@import macros;
Douglas Gregor7143aab2011-09-01 17:04:32 +000018
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
Douglas Gregorde8a9052011-09-14 23:13:09 +000031// CHECK-PREPROCESSED: double d
Douglas Gregor7143aab2011-09-01 17:04:32 +000032double d;
33DOUBLE *dp = &d;
34
Douglas Gregor1ac13c32012-01-03 19:48:16 +000035#__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}}
Douglas Gregor7143aab2011-09-01 17:04:32 +000036
Douglas Gregorce835df2011-09-14 22:14:14 +000037void f() {
Douglas Gregorde8a9052011-09-14 23:13:09 +000038 // CHECK-PREPROCESSED: int i = INTEGER;
Douglas Gregorce835df2011-09-14 22:14:14 +000039 int i = INTEGER; // the value was exported, the macro was not.
Douglas Gregorb09de512012-09-25 15:44:52 +000040 i += macros; // expanded from __MODULE__ within the 'macros' module.
Douglas Gregorce835df2011-09-14 22:14:14 +000041}
Douglas Gregorb09de512012-09-25 15:44:52 +000042
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
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000050
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)
Douglas Gregor1b257af2012-12-11 22:11:52 +000066@import macros_left;
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000067
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
Stephen Hines651f13c2014-04-23 16:59:28 -070080#ifdef TOP_LEFT_UNDEF
81# error TOP_LEFT_UNDEF should not be defined
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000082#endif
83
84void test1() {
85 int i;
86 TOP_RIGHT_REDEF *ip = &i;
87}
88
Argyrios Kyrtzidis35803282013-03-27 01:25:19 +000089#define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}} \
90 // expected-note{{other definition of 'LEFT_RIGHT_DIFFERENT2'}}
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000091
92// Import right module (which also imports top)
Douglas Gregor1b257af2012-12-11 22:11:52 +000093@import macros_right;
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000094
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
Douglas Gregor6c6c54a2012-10-11 00:46:49 +0000109void test2() {
110 int i;
111 float f;
112 double d;
Stephen Hines651f13c2014-04-23 16:59:28 -0700113 TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition
Douglas Gregor6c6c54a2012-10-11 00:46:49 +0000114
Argyrios Kyrtzidis35803282013-03-27 01:25:19 +0000115 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}}
Douglas Gregor6c6c54a2012-10-11 00:46:49 +0000118 int LEFT_RIGHT_DIFFERENT3;
119}
120
121#define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}}
122
123void test3() {
124 double d;
125 LEFT_RIGHT_DIFFERENT *dp = &d; // okay
Argyrios Kyrtzidisbd25ff82013-04-03 17:39:30 +0000126 int x = FN_ADD(1,2);
Douglas Gregor6c6c54a2012-10-11 00:46:49 +0000127}
Douglas Gregor54c8a402012-10-12 00:16:50 +0000128
129#ifndef TOP_RIGHT_UNDEF
130# error TOP_RIGHT_UNDEF should still be defined
131#endif
132
Stephen Hines176edba2014-12-01 14:53:08 -0800133@import macros_bottom;
134
135TOP_DEF_RIGHT_UNDEF *TDRUf() { return TDRUp; }
136
Douglas Gregor1b257af2012-12-11 22:11:52 +0000137@import macros_right.undef;
Douglas Gregor54c8a402012-10-12 00:16:50 +0000138
Stephen Hines176edba2014-12-01 14:53:08 -0800139int TOP_DEF_RIGHT_UNDEF; // ok, no longer defined
140
Stephen Hines651f13c2014-04-23 16:59:28 -0700141// FIXME: When macros_right.undef is built, macros_top is visible because
142// the state from building macros_right leaks through, so macros_right.undef
143// undefines macros_top's macro.
144#ifdef TOP_RIGHT_UNDEF
145# error TOP_RIGHT_UNDEF should not be defined
Douglas Gregor54c8a402012-10-12 00:16:50 +0000146#endif
Stephen Hines651f13c2014-04-23 16:59:28 -0700147
148@import macros_other;
149
150#ifndef TOP_OTHER_UNDEF1
151# error TOP_OTHER_UNDEF1 should still be defined
152#endif
153
154#ifndef TOP_OTHER_UNDEF2
155# error TOP_OTHER_UNDEF2 should still be defined
156#endif
157
158#ifndef TOP_OTHER_REDEF1
159# error TOP_OTHER_REDEF1 should still be defined
160#endif
161int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}}
162// expected-note@macros_top.h:19 {{expanding this definition}}
163// expected-note@macros_other.h:4 {{other definition}}
164
165#ifndef TOP_OTHER_REDEF2
166# error TOP_OTHER_REDEF2 should still be defined
167#endif
168int n2 = TOP_OTHER_REDEF2; // ok
169
170int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok