blob: 1178711cd29924634413ef635057044f089ab0a3 [file] [log] [blame]
Argyrios Kyrtzidis0c06cbc2013-01-23 18:21:56 +00001// XFAIL: *
Douglas Gregor42583322011-11-16 05:16:30 +00002// RUN: rm -rf %t
Douglas Gregor6c6c54a2012-10-11 00:46:49 +00003// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_top %S/Inputs/module.map
4// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_left %S/Inputs/module.map
5// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_right %S/Inputs/module.map
Douglas Gregorc13a34b2012-01-03 19:32:59 +00006// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros %S/Inputs/module.map
7// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodule-cache-path %t %s
8// RUN: %clang_cc1 -E -fmodules -x objective-c -fmodule-cache-path %t %s | FileCheck -check-prefix CHECK-PREPROCESSED %s
9// FIXME: When we have a syntax for modules in C, use that.
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000010// These notes come from headers in modules, and are bogus.
Douglas Gregore8219a62012-10-11 21:07:39 +000011
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000012// FIXME: expected-note{{previous definition is here}}
Douglas Gregore8219a62012-10-11 21:07:39 +000013// expected-note{{other definition of 'LEFT_RIGHT_DIFFERENT'}}
14// expected-note{{expanding this definition of 'TOP_RIGHT_REDEF'}}
15// FIXME: expected-note{{previous definition is here}} \
16// expected-note{{expanding this definition of 'LEFT_RIGHT_DIFFERENT'}}
17
18// expected-note{{other definition of 'TOP_RIGHT_REDEF'}}
Douglas Gregor7143aab2011-09-01 17:04:32 +000019
Douglas Gregor1b257af2012-12-11 22:11:52 +000020@import macros;
Douglas Gregor7143aab2011-09-01 17:04:32 +000021
22#ifndef INTEGER
23# error INTEGER macro should be visible
24#endif
25
26#ifdef FLOAT
27# error FLOAT macro should not be visible
28#endif
29
30#ifdef MODULE
31# error MODULE macro should not be visible
32#endif
33
Douglas Gregorde8a9052011-09-14 23:13:09 +000034// CHECK-PREPROCESSED: double d
Douglas Gregor7143aab2011-09-01 17:04:32 +000035double d;
36DOUBLE *dp = &d;
37
Douglas Gregor1ac13c32012-01-03 19:48:16 +000038#__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}}
Douglas Gregor7143aab2011-09-01 17:04:32 +000039
Douglas Gregorce835df2011-09-14 22:14:14 +000040void f() {
Douglas Gregorde8a9052011-09-14 23:13:09 +000041 // CHECK-PREPROCESSED: int i = INTEGER;
Douglas Gregorce835df2011-09-14 22:14:14 +000042 int i = INTEGER; // the value was exported, the macro was not.
Douglas Gregorb09de512012-09-25 15:44:52 +000043 i += macros; // expanded from __MODULE__ within the 'macros' module.
Douglas Gregorce835df2011-09-14 22:14:14 +000044}
Douglas Gregorb09de512012-09-25 15:44:52 +000045
46#ifdef __MODULE__
47# error Not building a module!
48#endif
49
50#if __building_module(macros)
51# error Not building a module
52#endif
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000053
54// None of the modules we depend on have been imported, and therefore
55// their macros should not be visible.
56#ifdef LEFT
57# error LEFT should not be visible
58#endif
59
60#ifdef RIGHT
61# error RIGHT should not be visible
62#endif
63
64#ifdef TOP
65# error TOP should not be visible
66#endif
67
68// Import left module (which also imports top)
Douglas Gregor1b257af2012-12-11 22:11:52 +000069@import macros_left;
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000070
71#ifndef LEFT
72# error LEFT should be visible
73#endif
74
75#ifdef RIGHT
76# error RIGHT should not be visible
77#endif
78
79#ifndef TOP
80# error TOP should be visible
81#endif
82
83#ifdef TOP_LEFT_UNDEF
84# error TOP_LEFT_UNDEF should not be visible
85#endif
86
87void test1() {
88 int i;
89 TOP_RIGHT_REDEF *ip = &i;
90}
91
92#define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}}
93
94// Import right module (which also imports top)
Douglas Gregor1b257af2012-12-11 22:11:52 +000095@import macros_right;
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000096
97#undef LEFT_RIGHT_DIFFERENT3
98
99#ifndef LEFT
100# error LEFT should be visible
101#endif
102
103#ifndef RIGHT
104# error RIGHT should be visible
105#endif
106
107#ifndef TOP
108# error TOP should be visible
109#endif
110
Douglas Gregor6c6c54a2012-10-11 00:46:49 +0000111void test2() {
112 int i;
113 float f;
114 double d;
Douglas Gregore8219a62012-10-11 21:07:39 +0000115 TOP_RIGHT_REDEF *ip = &i; // expected-warning{{ambiguous expansion of macro 'TOP_RIGHT_REDEF'}}
Douglas Gregor6c6c54a2012-10-11 00:46:49 +0000116
117 LEFT_RIGHT_IDENTICAL *ip2 = &i;
Douglas Gregore8219a62012-10-11 21:07:39 +0000118 LEFT_RIGHT_DIFFERENT *fp = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}}
119 LEFT_RIGHT_DIFFERENT2 *dp = &d;
Douglas Gregor6c6c54a2012-10-11 00:46:49 +0000120 int LEFT_RIGHT_DIFFERENT3;
121}
122
123#define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}}
124
125void test3() {
126 double d;
127 LEFT_RIGHT_DIFFERENT *dp = &d; // okay
128}
Douglas Gregor54c8a402012-10-12 00:16:50 +0000129
130#ifndef TOP_RIGHT_UNDEF
131# error TOP_RIGHT_UNDEF should still be defined
132#endif
133
Douglas Gregor1b257af2012-12-11 22:11:52 +0000134@import macros_right.undef;
Douglas Gregor54c8a402012-10-12 00:16:50 +0000135
136#ifdef TOP_RIGHT_UNDEF
137# error TOP_RIGHT_UNDEF should not be defined
138#endif