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