Douglas Gregor | 84febf4 | 2011-11-16 05:16:30 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Richard Smith | 47972af | 2015-06-16 00:08:24 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s |
Richard Smith | a7c535b | 2015-07-22 01:28:05 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s -DALT |
Richard Smith | 47972af | 2015-06-16 00:08:24 +0000 | [diff] [blame] | 4 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s -detailed-preprocessing-record |
Richard Smith | 47972af | 2015-06-16 00:08:24 +0000 | [diff] [blame] | 5 | // RUN: not %clang_cc1 -E -fmodules -fimplicit-module-maps -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix CHECK-PREPROCESSED %s |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 6 | // |
| 7 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s |
| 8 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s -DALT |
| 9 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s -detailed-preprocessing-record |
| 10 | // RUN: not %clang_cc1 -E -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix CHECK-PREPROCESSED %s |
| 11 | // |
| 12 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -DLOCAL_VISIBILITY -fmodules-local-submodule-visibility -x objective-c++ -verify -fmodules-cache-path=%t -I %S/Inputs %s |
Douglas Gregor | da82e70 | 2012-01-03 19:32:59 +0000 | [diff] [blame] | 13 | // FIXME: When we have a syntax for modules in C, use that. |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 14 | // These notes come from headers in modules, and are bogus. |
Douglas Gregor | 5968b1b | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 15 | |
Andy Gibbs | fcc699a | 2013-04-17 08:06:46 +0000 | [diff] [blame] | 16 | // FIXME: expected-note@Inputs/macros_left.h:11{{previous definition is here}} |
| 17 | // FIXME: expected-note@Inputs/macros_right.h:12{{previous definition is here}} |
| 18 | // expected-note@Inputs/macros_right.h:12{{expanding this definition of 'LEFT_RIGHT_DIFFERENT'}} |
Andy Gibbs | fcc699a | 2013-04-17 08:06:46 +0000 | [diff] [blame] | 19 | // expected-note@Inputs/macros_right.h:13{{expanding this definition of 'LEFT_RIGHT_DIFFERENT2'}} |
| 20 | // expected-note@Inputs/macros_left.h:14{{other definition of 'LEFT_RIGHT_DIFFERENT'}} |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 21 | |
Douglas Gregor | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 22 | @import macros; |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 23 | |
| 24 | #ifndef INTEGER |
| 25 | # error INTEGER macro should be visible |
| 26 | #endif |
| 27 | |
| 28 | #ifdef FLOAT |
| 29 | # error FLOAT macro should not be visible |
| 30 | #endif |
| 31 | |
| 32 | #ifdef MODULE |
| 33 | # error MODULE macro should not be visible |
| 34 | #endif |
| 35 | |
Richard Smith | 2a55308 | 2015-04-23 22:58:06 +0000 | [diff] [blame] | 36 | #ifndef INDIRECTLY_IN_MACROS |
| 37 | # error INDIRECTLY_IN_MACROS should be visible |
| 38 | #endif |
| 39 | |
Douglas Gregor | 21931ef | 2011-09-14 23:13:09 +0000 | [diff] [blame] | 40 | // CHECK-PREPROCESSED: double d |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 41 | double d; |
| 42 | DOUBLE *dp = &d; |
| 43 | |
Douglas Gregor | 663b48f | 2012-01-03 19:48:16 +0000 | [diff] [blame] | 44 | #__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}} |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 45 | |
Douglas Gregor | d7910e9 | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 46 | void f() { |
Douglas Gregor | 21931ef | 2011-09-14 23:13:09 +0000 | [diff] [blame] | 47 | // CHECK-PREPROCESSED: int i = INTEGER; |
Douglas Gregor | d7910e9 | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 48 | int i = INTEGER; // the value was exported, the macro was not. |
Douglas Gregor | c83de30 | 2012-09-25 15:44:52 +0000 | [diff] [blame] | 49 | i += macros; // expanded from __MODULE__ within the 'macros' module. |
Douglas Gregor | d7910e9 | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 50 | } |
Douglas Gregor | c83de30 | 2012-09-25 15:44:52 +0000 | [diff] [blame] | 51 | |
| 52 | #ifdef __MODULE__ |
| 53 | # error Not building a module! |
| 54 | #endif |
| 55 | |
| 56 | #if __building_module(macros) |
| 57 | # error Not building a module |
| 58 | #endif |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 59 | |
| 60 | // None of the modules we depend on have been imported, and therefore |
| 61 | // their macros should not be visible. |
| 62 | #ifdef LEFT |
| 63 | # error LEFT should not be visible |
| 64 | #endif |
| 65 | |
| 66 | #ifdef RIGHT |
| 67 | # error RIGHT should not be visible |
| 68 | #endif |
| 69 | |
| 70 | #ifdef TOP |
| 71 | # error TOP should not be visible |
| 72 | #endif |
| 73 | |
Richard Smith | 938d701 | 2015-09-16 00:55:50 +0000 | [diff] [blame] | 74 | #undef INTEGER |
| 75 | #define INTEGER int |
| 76 | |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 77 | // Import left module (which also imports top) |
Douglas Gregor | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 78 | @import macros_left; |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 79 | |
Richard Smith | 938d701 | 2015-09-16 00:55:50 +0000 | [diff] [blame] | 80 | INTEGER my_integer = 0; |
| 81 | |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 82 | #ifndef LEFT |
| 83 | # error LEFT should be visible |
| 84 | #endif |
| 85 | |
| 86 | #ifdef RIGHT |
| 87 | # error RIGHT should not be visible |
| 88 | #endif |
| 89 | |
| 90 | #ifndef TOP |
| 91 | # error TOP should be visible |
| 92 | #endif |
| 93 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 94 | #ifdef TOP_LEFT_UNDEF |
| 95 | # error TOP_LEFT_UNDEF should not be defined |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 96 | #endif |
| 97 | |
| 98 | void test1() { |
| 99 | int i; |
| 100 | TOP_RIGHT_REDEF *ip = &i; |
| 101 | } |
| 102 | |
Argyrios Kyrtzidis | 09796b9 | 2013-03-27 01:25:19 +0000 | [diff] [blame] | 103 | #define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}} \ |
| 104 | // expected-note{{other definition of 'LEFT_RIGHT_DIFFERENT2'}} |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 105 | |
| 106 | // Import right module (which also imports top) |
Douglas Gregor | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 107 | @import macros_right; |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 108 | |
| 109 | #undef LEFT_RIGHT_DIFFERENT3 |
| 110 | |
| 111 | #ifndef LEFT |
| 112 | # error LEFT should be visible |
| 113 | #endif |
| 114 | |
| 115 | #ifndef RIGHT |
| 116 | # error RIGHT should be visible |
| 117 | #endif |
| 118 | |
| 119 | #ifndef TOP |
| 120 | # error TOP should be visible |
| 121 | #endif |
| 122 | |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 123 | void test2() { |
| 124 | int i; |
| 125 | float f; |
| 126 | double d; |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 127 | TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 128 | |
Argyrios Kyrtzidis | 09796b9 | 2013-03-27 01:25:19 +0000 | [diff] [blame] | 129 | LEFT_RIGHT_IDENTICAL *ip = &i; |
| 130 | LEFT_RIGHT_DIFFERENT *ip2 = &i; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}} |
| 131 | LEFT_RIGHT_DIFFERENT2 *ip3 = &i; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT2}} |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 132 | int LEFT_RIGHT_DIFFERENT3; |
| 133 | } |
| 134 | |
| 135 | #define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}} |
| 136 | |
| 137 | void test3() { |
| 138 | double d; |
| 139 | LEFT_RIGHT_DIFFERENT *dp = &d; // okay |
Argyrios Kyrtzidis | 0c2f30b | 2013-04-03 17:39:30 +0000 | [diff] [blame] | 140 | int x = FN_ADD(1,2); |
Douglas Gregor | 5a4649b | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 141 | } |
Douglas Gregor | cfa46a8 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 142 | |
| 143 | #ifndef TOP_RIGHT_UNDEF |
| 144 | # error TOP_RIGHT_UNDEF should still be defined |
| 145 | #endif |
| 146 | |
Richard Smith | 49faf9f | 2014-08-09 01:24:07 +0000 | [diff] [blame] | 147 | @import macros_bottom; |
| 148 | |
| 149 | TOP_DEF_RIGHT_UNDEF *TDRUf() { return TDRUp; } |
| 150 | |
Douglas Gregor | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 151 | @import macros_right.undef; |
Douglas Gregor | cfa46a8 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 152 | |
Richard Smith | 49faf9f | 2014-08-09 01:24:07 +0000 | [diff] [blame] | 153 | int TOP_DEF_RIGHT_UNDEF; // ok, no longer defined |
| 154 | |
Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 155 | #ifdef LOCAL_VISIBILITY |
| 156 | // TOP_RIGHT_UNDEF should not be undefined, because macros_right.undef does |
| 157 | // not undefine macros_right's macro. |
| 158 | # ifndef TOP_RIGHT_UNDEF |
| 159 | # error TOP_RIGHT_UNDEF should still be defined |
| 160 | # endif |
| 161 | #else |
| 162 | // When macros_right.undef is built and local submodule visibility is not |
| 163 | // enabled, macros_top is visible because the state from building |
| 164 | // macros_right leaks through, so macros_right.undef undefines macros_top's |
| 165 | // macro. |
| 166 | # ifdef TOP_RIGHT_UNDEF |
| 167 | # error TOP_RIGHT_UNDEF should not be defined |
| 168 | # endif |
Douglas Gregor | cfa46a8 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 169 | #endif |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 170 | |
Richard Smith | a7c535b | 2015-07-22 01:28:05 +0000 | [diff] [blame] | 171 | #ifdef ALT |
| 172 | int tmp = TOP_OTHER_REDEF1; |
| 173 | #endif |
| 174 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 175 | @import macros_other; |
| 176 | |
| 177 | #ifndef TOP_OTHER_UNDEF1 |
| 178 | # error TOP_OTHER_UNDEF1 should still be defined |
| 179 | #endif |
| 180 | |
| 181 | #ifndef TOP_OTHER_UNDEF2 |
| 182 | # error TOP_OTHER_UNDEF2 should still be defined |
| 183 | #endif |
Richard Smith | a7c535b | 2015-07-22 01:28:05 +0000 | [diff] [blame] | 184 | #pragma clang __debug macro TOP_OTHER_REDEF1 |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 185 | #ifndef TOP_OTHER_REDEF1 |
| 186 | # error TOP_OTHER_REDEF1 should still be defined |
| 187 | #endif |
| 188 | int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}} |
Richard Smith | a7c535b | 2015-07-22 01:28:05 +0000 | [diff] [blame] | 189 | // expected-note@macros_other.h:4 {{expanding this definition}} |
| 190 | // expected-note@macros_top.h:19 {{other definition}} |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 191 | |
| 192 | #ifndef TOP_OTHER_REDEF2 |
| 193 | # error TOP_OTHER_REDEF2 should still be defined |
| 194 | #endif |
| 195 | int n2 = TOP_OTHER_REDEF2; // ok |
| 196 | |
| 197 | int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok |