Douglas Gregor | 4258332 | 2011-11-16 05:16:30 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Douglas Gregor | 953a61f | 2013-02-07 19:01:24 +0000 | [diff] [blame] | 2 | // 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 Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 6 | // 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 Gregor | c13a34b | 2012-01-03 19:32:59 +0000 | [diff] [blame] | 8 | // FIXME: When we have a syntax for modules in C, use that. |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 9 | // These notes come from headers in modules, and are bogus. |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 10 | |
Andy Gibbs | b42f200 | 2013-04-17 08:06:46 +0000 | [diff] [blame] | 11 | // 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 Gibbs | b42f200 | 2013-04-17 08:06:46 +0000 | [diff] [blame] | 14 | // 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 Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 16 | |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 17 | @import macros; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 18 | |
| 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 Gregor | de8a905 | 2011-09-14 23:13:09 +0000 | [diff] [blame] | 31 | // CHECK-PREPROCESSED: double d |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 32 | double d; |
| 33 | DOUBLE *dp = &d; |
| 34 | |
Douglas Gregor | 1ac13c3 | 2012-01-03 19:48:16 +0000 | [diff] [blame] | 35 | #__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}} |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 36 | |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 37 | void f() { |
Douglas Gregor | de8a905 | 2011-09-14 23:13:09 +0000 | [diff] [blame] | 38 | // CHECK-PREPROCESSED: int i = INTEGER; |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 39 | int i = INTEGER; // the value was exported, the macro was not. |
Douglas Gregor | b09de51 | 2012-09-25 15:44:52 +0000 | [diff] [blame] | 40 | i += macros; // expanded from __MODULE__ within the 'macros' module. |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 41 | } |
Douglas Gregor | b09de51 | 2012-09-25 15:44:52 +0000 | [diff] [blame] | 42 | |
| 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 Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 50 | |
| 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 Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 66 | @import macros_left; |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 67 | |
| 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 Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 80 | #ifdef TOP_LEFT_UNDEF |
| 81 | # error TOP_LEFT_UNDEF should not be defined |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 82 | #endif |
| 83 | |
| 84 | void test1() { |
| 85 | int i; |
| 86 | TOP_RIGHT_REDEF *ip = &i; |
| 87 | } |
| 88 | |
Argyrios Kyrtzidis | 3580328 | 2013-03-27 01:25:19 +0000 | [diff] [blame] | 89 | #define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}} \ |
| 90 | // expected-note{{other definition of 'LEFT_RIGHT_DIFFERENT2'}} |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 91 | |
| 92 | // Import right module (which also imports top) |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 93 | @import macros_right; |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 94 | |
| 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 Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 109 | void test2() { |
| 110 | int i; |
| 111 | float f; |
| 112 | double d; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 113 | TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 114 | |
Argyrios Kyrtzidis | 3580328 | 2013-03-27 01:25:19 +0000 | [diff] [blame] | 115 | 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 Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 118 | int LEFT_RIGHT_DIFFERENT3; |
| 119 | } |
| 120 | |
| 121 | #define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}} |
| 122 | |
| 123 | void test3() { |
| 124 | double d; |
| 125 | LEFT_RIGHT_DIFFERENT *dp = &d; // okay |
Argyrios Kyrtzidis | bd25ff8 | 2013-04-03 17:39:30 +0000 | [diff] [blame] | 126 | int x = FN_ADD(1,2); |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 127 | } |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 128 | |
| 129 | #ifndef TOP_RIGHT_UNDEF |
| 130 | # error TOP_RIGHT_UNDEF should still be defined |
| 131 | #endif |
| 132 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 133 | @import macros_bottom; |
| 134 | |
| 135 | TOP_DEF_RIGHT_UNDEF *TDRUf() { return TDRUp; } |
| 136 | |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 137 | @import macros_right.undef; |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 138 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 139 | int TOP_DEF_RIGHT_UNDEF; // ok, no longer defined |
| 140 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 141 | // 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 Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 146 | #endif |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 147 | |
| 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 |
| 161 | int 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 |
| 168 | int n2 = TOP_OTHER_REDEF2; // ok |
| 169 | |
| 170 | int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok |