Douglas Gregor | 4258332 | 2011-11-16 05:16:30 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_top %S/Inputs/module.map |
| 3 | // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_left %S/Inputs/module.map |
| 4 | // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros_right %S/Inputs/module.map |
Douglas Gregor | c13a34b | 2012-01-03 19:32:59 +0000 | [diff] [blame] | 5 | // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-cache-path %t -fmodule-name=macros %S/Inputs/module.map |
| 6 | // RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodule-cache-path %t %s |
| 7 | // RUN: %clang_cc1 -E -fmodules -x objective-c -fmodule-cache-path %t %s | FileCheck -check-prefix CHECK-PREPROCESSED %s |
| 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 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 11 | // FIXME: expected-note{{previous definition is here}} |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 12 | // expected-note{{other definition of 'LEFT_RIGHT_DIFFERENT'}} |
| 13 | // expected-note{{expanding this definition of 'TOP_RIGHT_REDEF'}} |
| 14 | // FIXME: expected-note{{previous definition is here}} \ |
| 15 | // expected-note{{expanding this definition of 'LEFT_RIGHT_DIFFERENT'}} |
| 16 | |
| 17 | // expected-note{{other definition of 'TOP_RIGHT_REDEF'}} |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 18 | |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame^] | 19 | @import macros; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 20 | |
| 21 | #ifndef INTEGER |
| 22 | # error INTEGER macro should be visible |
| 23 | #endif |
| 24 | |
| 25 | #ifdef FLOAT |
| 26 | # error FLOAT macro should not be visible |
| 27 | #endif |
| 28 | |
| 29 | #ifdef MODULE |
| 30 | # error MODULE macro should not be visible |
| 31 | #endif |
| 32 | |
Douglas Gregor | de8a905 | 2011-09-14 23:13:09 +0000 | [diff] [blame] | 33 | // CHECK-PREPROCESSED: double d |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 34 | double d; |
| 35 | DOUBLE *dp = &d; |
| 36 | |
Douglas Gregor | 1ac13c3 | 2012-01-03 19:48:16 +0000 | [diff] [blame] | 37 | #__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}} |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 38 | |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 39 | void f() { |
Douglas Gregor | de8a905 | 2011-09-14 23:13:09 +0000 | [diff] [blame] | 40 | // CHECK-PREPROCESSED: int i = INTEGER; |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 41 | int i = INTEGER; // the value was exported, the macro was not. |
Douglas Gregor | b09de51 | 2012-09-25 15:44:52 +0000 | [diff] [blame] | 42 | i += macros; // expanded from __MODULE__ within the 'macros' module. |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 43 | } |
Douglas Gregor | b09de51 | 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 | 6c6c54a | 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 | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame^] | 68 | @import macros_left; |
Douglas Gregor | 6c6c54a | 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 | |
| 82 | #ifdef TOP_LEFT_UNDEF |
| 83 | # error TOP_LEFT_UNDEF should not be visible |
| 84 | #endif |
| 85 | |
| 86 | void test1() { |
| 87 | int i; |
| 88 | TOP_RIGHT_REDEF *ip = &i; |
| 89 | } |
| 90 | |
| 91 | #define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}} |
| 92 | |
| 93 | // Import right module (which also imports top) |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame^] | 94 | @import macros_right; |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 95 | |
| 96 | #undef LEFT_RIGHT_DIFFERENT3 |
| 97 | |
| 98 | #ifndef LEFT |
| 99 | # error LEFT should be visible |
| 100 | #endif |
| 101 | |
| 102 | #ifndef RIGHT |
| 103 | # error RIGHT should be visible |
| 104 | #endif |
| 105 | |
| 106 | #ifndef TOP |
| 107 | # error TOP should be visible |
| 108 | #endif |
| 109 | |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 110 | void test2() { |
| 111 | int i; |
| 112 | float f; |
| 113 | double d; |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 114 | TOP_RIGHT_REDEF *ip = &i; // expected-warning{{ambiguous expansion of macro 'TOP_RIGHT_REDEF'}} |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 115 | |
| 116 | LEFT_RIGHT_IDENTICAL *ip2 = &i; |
Douglas Gregor | e8219a6 | 2012-10-11 21:07:39 +0000 | [diff] [blame] | 117 | LEFT_RIGHT_DIFFERENT *fp = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}} |
| 118 | LEFT_RIGHT_DIFFERENT2 *dp = &d; |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 119 | int LEFT_RIGHT_DIFFERENT3; |
| 120 | } |
| 121 | |
| 122 | #define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}} |
| 123 | |
| 124 | void test3() { |
| 125 | double d; |
| 126 | LEFT_RIGHT_DIFFERENT *dp = &d; // okay |
| 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 | |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame^] | 133 | @import macros_right.undef; |
Douglas Gregor | 54c8a40 | 2012-10-12 00:16:50 +0000 | [diff] [blame] | 134 | |
| 135 | #ifdef TOP_RIGHT_UNDEF |
| 136 | # error TOP_RIGHT_UNDEF should not be defined |
| 137 | #endif |