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