blob: 3ca53005cf393aca2a55f3f91360b0762251bc3b [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'}}
Douglas Gregor4a69c2e2011-09-01 17:04:32 +000016
Douglas Gregorc50d4922012-12-11 22:11:52 +000017@import macros;
Douglas Gregor4a69c2e2011-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
Richard Smith2a553082015-04-23 22:58:06 +000031#ifndef INDIRECTLY_IN_MACROS
32# error INDIRECTLY_IN_MACROS should be visible
33#endif
34
Douglas Gregor21931ef2011-09-14 23:13:09 +000035// CHECK-PREPROCESSED: double d
Douglas Gregor4a69c2e2011-09-01 17:04:32 +000036double d;
37DOUBLE *dp = &d;
38
Douglas Gregor663b48f2012-01-03 19:48:16 +000039#__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}}
Douglas Gregor4a69c2e2011-09-01 17:04:32 +000040
Douglas Gregord7910e92011-09-14 22:14:14 +000041void f() {
Douglas Gregor21931ef2011-09-14 23:13:09 +000042 // CHECK-PREPROCESSED: int i = INTEGER;
Douglas Gregord7910e92011-09-14 22:14:14 +000043 int i = INTEGER; // the value was exported, the macro was not.
Douglas Gregorc83de302012-09-25 15:44:52 +000044 i += macros; // expanded from __MODULE__ within the 'macros' module.
Douglas Gregord7910e92011-09-14 22:14:14 +000045}
Douglas Gregorc83de302012-09-25 15:44:52 +000046
47#ifdef __MODULE__
48# error Not building a module!
49#endif
50
51#if __building_module(macros)
52# error Not building a module
53#endif
Douglas Gregor5a4649b2012-10-11 00:46:49 +000054
55// None of the modules we depend on have been imported, and therefore
56// their macros should not be visible.
57#ifdef LEFT
58# error LEFT should not be visible
59#endif
60
61#ifdef RIGHT
62# error RIGHT should not be visible
63#endif
64
65#ifdef TOP
66# error TOP should not be visible
67#endif
68
69// Import left module (which also imports top)
Douglas Gregorc50d4922012-12-11 22:11:52 +000070@import macros_left;
Douglas Gregor5a4649b2012-10-11 00:46:49 +000071
72#ifndef LEFT
73# error LEFT should be visible
74#endif
75
76#ifdef RIGHT
77# error RIGHT should not be visible
78#endif
79
80#ifndef TOP
81# error TOP should be visible
82#endif
83
Richard Smith49f906a2014-03-01 00:08:04 +000084#ifdef TOP_LEFT_UNDEF
85# error TOP_LEFT_UNDEF should not be defined
Douglas Gregor5a4649b2012-10-11 00:46:49 +000086#endif
87
88void test1() {
89 int i;
90 TOP_RIGHT_REDEF *ip = &i;
91}
92
Argyrios Kyrtzidis09796b92013-03-27 01:25:19 +000093#define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}} \
94 // expected-note{{other definition of 'LEFT_RIGHT_DIFFERENT2'}}
Douglas Gregor5a4649b2012-10-11 00:46:49 +000095
96// Import right module (which also imports top)
Douglas Gregorc50d4922012-12-11 22:11:52 +000097@import macros_right;
Douglas Gregor5a4649b2012-10-11 00:46:49 +000098
99#undef LEFT_RIGHT_DIFFERENT3
100
101#ifndef LEFT
102# error LEFT should be visible
103#endif
104
105#ifndef RIGHT
106# error RIGHT should be visible
107#endif
108
109#ifndef TOP
110# error TOP should be visible
111#endif
112
Douglas Gregor5a4649b2012-10-11 00:46:49 +0000113void test2() {
114 int i;
115 float f;
116 double d;
Richard Smith49f906a2014-03-01 00:08:04 +0000117 TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition
Douglas Gregor5a4649b2012-10-11 00:46:49 +0000118
Argyrios Kyrtzidis09796b92013-03-27 01:25:19 +0000119 LEFT_RIGHT_IDENTICAL *ip = &i;
120 LEFT_RIGHT_DIFFERENT *ip2 = &i; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}}
121 LEFT_RIGHT_DIFFERENT2 *ip3 = &i; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT2}}
Douglas Gregor5a4649b2012-10-11 00:46:49 +0000122 int LEFT_RIGHT_DIFFERENT3;
123}
124
125#define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}}
126
127void test3() {
128 double d;
129 LEFT_RIGHT_DIFFERENT *dp = &d; // okay
Argyrios Kyrtzidis0c2f30b2013-04-03 17:39:30 +0000130 int x = FN_ADD(1,2);
Douglas Gregor5a4649b2012-10-11 00:46:49 +0000131}
Douglas Gregorcfa46a82012-10-12 00:16:50 +0000132
133#ifndef TOP_RIGHT_UNDEF
134# error TOP_RIGHT_UNDEF should still be defined
135#endif
136
Richard Smith49faf9f2014-08-09 01:24:07 +0000137@import macros_bottom;
138
139TOP_DEF_RIGHT_UNDEF *TDRUf() { return TDRUp; }
140
Douglas Gregorc50d4922012-12-11 22:11:52 +0000141@import macros_right.undef;
Douglas Gregorcfa46a82012-10-12 00:16:50 +0000142
Richard Smith49faf9f2014-08-09 01:24:07 +0000143int TOP_DEF_RIGHT_UNDEF; // ok, no longer defined
144
Richard Smith49f906a2014-03-01 00:08:04 +0000145// FIXME: When macros_right.undef is built, macros_top is visible because
146// the state from building macros_right leaks through, so macros_right.undef
147// undefines macros_top's macro.
148#ifdef TOP_RIGHT_UNDEF
149# error TOP_RIGHT_UNDEF should not be defined
Douglas Gregorcfa46a82012-10-12 00:16:50 +0000150#endif
Richard Smith49f906a2014-03-01 00:08:04 +0000151
152@import macros_other;
153
154#ifndef TOP_OTHER_UNDEF1
155# error TOP_OTHER_UNDEF1 should still be defined
156#endif
157
158#ifndef TOP_OTHER_UNDEF2
159# error TOP_OTHER_UNDEF2 should still be defined
160#endif
161
162#ifndef TOP_OTHER_REDEF1
163# error TOP_OTHER_REDEF1 should still be defined
164#endif
165int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}}
166// expected-note@macros_top.h:19 {{expanding this definition}}
167// expected-note@macros_other.h:4 {{other definition}}
168
169#ifndef TOP_OTHER_REDEF2
170# error TOP_OTHER_REDEF2 should still be defined
171#endif
172int n2 = TOP_OTHER_REDEF2; // ok
173
174int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok