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