blob: 168e2c6fce6437b3183d427e7591d9cf899e9572 [file] [log] [blame]
Douglas Gregor42583322011-11-16 05:16:30 +00001// RUN: rm -rf %t
Douglas Gregor6c6c54a2012-10-11 00:46:49 +00002// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_top %S/Inputs/module.map
3// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_left %S/Inputs/module.map
4// 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 +00005// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros %S/Inputs/module.map
6// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodule-cache-path %t %s
7// RUN: %clang_cc1 -E -fmodules -x objective-c -fmodule-cache-path %t %s | FileCheck -check-prefix CHECK-PREPROCESSED %s
8// 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.
10// FIXME: expected-note{{previous definition is here}}
11// FIXME: expected-note{{previous definition is here}}
Douglas Gregor7143aab2011-09-01 17:04:32 +000012
Ted Kremenek32ad2ee2012-03-01 22:07:04 +000013@__experimental_modules_import macros;
Douglas Gregor7143aab2011-09-01 17:04:32 +000014
15#ifndef INTEGER
16# error INTEGER macro should be visible
17#endif
18
19#ifdef FLOAT
20# error FLOAT macro should not be visible
21#endif
22
23#ifdef MODULE
24# error MODULE macro should not be visible
25#endif
26
Douglas Gregorde8a9052011-09-14 23:13:09 +000027// CHECK-PREPROCESSED: double d
Douglas Gregor7143aab2011-09-01 17:04:32 +000028double d;
29DOUBLE *dp = &d;
30
Douglas Gregor1ac13c32012-01-03 19:48:16 +000031#__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}}
Douglas Gregor7143aab2011-09-01 17:04:32 +000032
Douglas Gregorce835df2011-09-14 22:14:14 +000033void f() {
Douglas Gregorde8a9052011-09-14 23:13:09 +000034 // CHECK-PREPROCESSED: int i = INTEGER;
Douglas Gregorce835df2011-09-14 22:14:14 +000035 int i = INTEGER; // the value was exported, the macro was not.
Douglas Gregorb09de512012-09-25 15:44:52 +000036 i += macros; // expanded from __MODULE__ within the 'macros' module.
Douglas Gregorce835df2011-09-14 22:14:14 +000037}
Douglas Gregorb09de512012-09-25 15:44:52 +000038
39#ifdef __MODULE__
40# error Not building a module!
41#endif
42
43#if __building_module(macros)
44# error Not building a module
45#endif
Douglas Gregor6c6c54a2012-10-11 00:46:49 +000046
47// None of the modules we depend on have been imported, and therefore
48// their macros should not be visible.
49#ifdef LEFT
50# error LEFT should not be visible
51#endif
52
53#ifdef RIGHT
54# error RIGHT should not be visible
55#endif
56
57#ifdef TOP
58# error TOP should not be visible
59#endif
60
61// Import left module (which also imports top)
62@__experimental_modules_import macros_left;
63
64#ifndef LEFT
65# error LEFT should be visible
66#endif
67
68#ifdef RIGHT
69# error RIGHT should not be visible
70#endif
71
72#ifndef TOP
73# error TOP should be visible
74#endif
75
76#ifdef TOP_LEFT_UNDEF
77# error TOP_LEFT_UNDEF should not be visible
78#endif
79
80void test1() {
81 int i;
82 TOP_RIGHT_REDEF *ip = &i;
83}
84
85#define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}}
86
87// Import right module (which also imports top)
88@__experimental_modules_import macros_right;
89
90#undef LEFT_RIGHT_DIFFERENT3
91
92#ifndef LEFT
93# error LEFT should be visible
94#endif
95
96#ifndef RIGHT
97# error RIGHT should be visible
98#endif
99
100#ifndef TOP
101# error TOP should be visible
102#endif
103
104#ifndef TOP_LEFT_UNDEF
105# error TOP_LEFT_UNDEF should be visible
106#endif
107
108void test2() {
109 int i;
110 float f;
111 double d;
112 TOP_RIGHT_REDEF *ip = &i; // FIXME: warning
113
114 LEFT_RIGHT_IDENTICAL *ip2 = &i;
115 LEFT_RIGHT_DIFFERENT *fp = &f; // FIXME: warning
116 LEFT_RIGHT_DIFFERENT2 *dp = &d; // okay
117 int LEFT_RIGHT_DIFFERENT3;
118}
119
120#define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}}
121
122void test3() {
123 double d;
124 LEFT_RIGHT_DIFFERENT *dp = &d; // okay
125}