blob: e367fb685b95e25ced023cafd043948baa9c8ed3 [file] [log] [blame]
Douglas Gregor84febf42011-11-16 05:16:30 +00001// RUN: rm -rf %t
Douglas Gregor35b04d62013-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
Ben Langmuir9eb229b2014-01-22 23:19:39 +00006// 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 Gregorda82e702012-01-03 19:32:59 +00008// FIXME: When we have a syntax for modules in C, use that.
Douglas Gregor5a4649b2012-10-11 00:46:49 +00009// These notes come from headers in modules, and are bogus.
Douglas Gregor5968b1b2012-10-11 21:07:39 +000010
Andy Gibbsfcc699a2013-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 Gibbsfcc699a2013-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'}}
Richard Smith20e883e2015-04-29 23:20:19 +000016// expected-note@Inputs/macros_left.h:11{{other definition of 'LEFT_RIGHT_DIFFERENT2'}}
Douglas Gregor4a69c2e2011-09-01 17:04:32 +000017
Douglas Gregorc50d4922012-12-11 22:11:52 +000018@import macros;
Douglas Gregor4a69c2e2011-09-01 17:04:32 +000019
20#ifndef INTEGER
21# error INTEGER macro should be visible
22#endif
23
24#ifdef FLOAT
25# error FLOAT macro should not be visible
26#endif
27
28#ifdef MODULE
29# error MODULE macro should not be visible
30#endif
31
Richard Smith2a553082015-04-23 22:58:06 +000032#ifndef INDIRECTLY_IN_MACROS
33# error INDIRECTLY_IN_MACROS should be visible
34#endif
35
Douglas Gregor21931ef2011-09-14 23:13:09 +000036// CHECK-PREPROCESSED: double d
Douglas Gregor4a69c2e2011-09-01 17:04:32 +000037double d;
38DOUBLE *dp = &d;
39
Douglas Gregor663b48f2012-01-03 19:48:16 +000040#__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}}
Douglas Gregor4a69c2e2011-09-01 17:04:32 +000041
Douglas Gregord7910e92011-09-14 22:14:14 +000042void f() {
Douglas Gregor21931ef2011-09-14 23:13:09 +000043 // CHECK-PREPROCESSED: int i = INTEGER;
Douglas Gregord7910e92011-09-14 22:14:14 +000044 int i = INTEGER; // the value was exported, the macro was not.
Douglas Gregorc83de302012-09-25 15:44:52 +000045 i += macros; // expanded from __MODULE__ within the 'macros' module.
Douglas Gregord7910e92011-09-14 22:14:14 +000046}
Douglas Gregorc83de302012-09-25 15:44:52 +000047
48#ifdef __MODULE__
49# error Not building a module!
50#endif
51
52#if __building_module(macros)
53# error Not building a module
54#endif
Douglas Gregor5a4649b2012-10-11 00:46:49 +000055
56// None of the modules we depend on have been imported, and therefore
57// their macros should not be visible.
58#ifdef LEFT
59# error LEFT should not be visible
60#endif
61
62#ifdef RIGHT
63# error RIGHT should not be visible
64#endif
65
66#ifdef TOP
67# error TOP should not be visible
68#endif
69
70// Import left module (which also imports top)
Douglas Gregorc50d4922012-12-11 22:11:52 +000071@import macros_left;
Douglas Gregor5a4649b2012-10-11 00:46:49 +000072
73#ifndef LEFT
74# error LEFT should be visible
75#endif
76
77#ifdef RIGHT
78# error RIGHT should not be visible
79#endif
80
81#ifndef TOP
82# error TOP should be visible
83#endif
84
Richard Smith49f906a2014-03-01 00:08:04 +000085#ifdef TOP_LEFT_UNDEF
86# error TOP_LEFT_UNDEF should not be defined
Douglas Gregor5a4649b2012-10-11 00:46:49 +000087#endif
88
89void test1() {
90 int i;
91 TOP_RIGHT_REDEF *ip = &i;
92}
93
Argyrios Kyrtzidis09796b92013-03-27 01:25:19 +000094#define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}} \
95 // expected-note{{other definition of 'LEFT_RIGHT_DIFFERENT2'}}
Douglas Gregor5a4649b2012-10-11 00:46:49 +000096
97// Import right module (which also imports top)
Douglas Gregorc50d4922012-12-11 22:11:52 +000098@import macros_right;
Douglas Gregor5a4649b2012-10-11 00:46:49 +000099
100#undef LEFT_RIGHT_DIFFERENT3
101
102#ifndef LEFT
103# error LEFT should be visible
104#endif
105
106#ifndef RIGHT
107# error RIGHT should be visible
108#endif
109
110#ifndef TOP
111# error TOP should be visible
112#endif
113
Douglas Gregor5a4649b2012-10-11 00:46:49 +0000114void test2() {
115 int i;
116 float f;
117 double d;
Richard Smith49f906a2014-03-01 00:08:04 +0000118 TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition
Douglas Gregor5a4649b2012-10-11 00:46:49 +0000119
Argyrios Kyrtzidis09796b92013-03-27 01:25:19 +0000120 LEFT_RIGHT_IDENTICAL *ip = &i;
121 LEFT_RIGHT_DIFFERENT *ip2 = &i; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}}
122 LEFT_RIGHT_DIFFERENT2 *ip3 = &i; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT2}}
Douglas Gregor5a4649b2012-10-11 00:46:49 +0000123 int LEFT_RIGHT_DIFFERENT3;
124}
125
126#define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}}
127
128void test3() {
129 double d;
130 LEFT_RIGHT_DIFFERENT *dp = &d; // okay
Argyrios Kyrtzidis0c2f30b2013-04-03 17:39:30 +0000131 int x = FN_ADD(1,2);
Douglas Gregor5a4649b2012-10-11 00:46:49 +0000132}
Douglas Gregorcfa46a82012-10-12 00:16:50 +0000133
134#ifndef TOP_RIGHT_UNDEF
135# error TOP_RIGHT_UNDEF should still be defined
136#endif
137
Richard Smith49faf9f2014-08-09 01:24:07 +0000138@import macros_bottom;
139
140TOP_DEF_RIGHT_UNDEF *TDRUf() { return TDRUp; }
141
Douglas Gregorc50d4922012-12-11 22:11:52 +0000142@import macros_right.undef;
Douglas Gregorcfa46a82012-10-12 00:16:50 +0000143
Richard Smith49faf9f2014-08-09 01:24:07 +0000144int TOP_DEF_RIGHT_UNDEF; // ok, no longer defined
145
Richard Smith49f906a2014-03-01 00:08:04 +0000146// FIXME: When macros_right.undef is built, macros_top is visible because
147// the state from building macros_right leaks through, so macros_right.undef
148// undefines macros_top's macro.
149#ifdef TOP_RIGHT_UNDEF
150# error TOP_RIGHT_UNDEF should not be defined
Douglas Gregorcfa46a82012-10-12 00:16:50 +0000151#endif
Richard Smith49f906a2014-03-01 00:08:04 +0000152
153@import macros_other;
154
155#ifndef TOP_OTHER_UNDEF1
156# error TOP_OTHER_UNDEF1 should still be defined
157#endif
158
159#ifndef TOP_OTHER_UNDEF2
160# error TOP_OTHER_UNDEF2 should still be defined
161#endif
162
163#ifndef TOP_OTHER_REDEF1
164# error TOP_OTHER_REDEF1 should still be defined
165#endif
166int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}}
167// expected-note@macros_top.h:19 {{expanding this definition}}
168// expected-note@macros_other.h:4 {{other definition}}
169
170#ifndef TOP_OTHER_REDEF2
171# error TOP_OTHER_REDEF2 should still be defined
172#endif
173int n2 = TOP_OTHER_REDEF2; // ok
174
175int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok