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. |
| 10 | // FIXME: expected-note{{previous definition is here}} |
| 11 | // FIXME: expected-note{{previous definition is here}} |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 12 | |
Ted Kremenek | 32ad2ee | 2012-03-01 22:07:04 +0000 | [diff] [blame] | 13 | @__experimental_modules_import macros; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 14 | |
| 15 | #ifndef INTEGER |
| 16 | # error INTEGER macro should be visible |
| 17 | #endif |
| 18 | |
| 19 | #ifdef FLOAT |
| 20 | # error FLOAT macro should not be visible |
| 21 | #endif |
| 22 | |
| 23 | #ifdef MODULE |
| 24 | # error MODULE macro should not be visible |
| 25 | #endif |
| 26 | |
Douglas Gregor | de8a905 | 2011-09-14 23:13:09 +0000 | [diff] [blame] | 27 | // CHECK-PREPROCESSED: double d |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 28 | double d; |
| 29 | DOUBLE *dp = &d; |
| 30 | |
Douglas Gregor | 1ac13c3 | 2012-01-03 19:48:16 +0000 | [diff] [blame] | 31 | #__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}} |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 32 | |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 33 | void f() { |
Douglas Gregor | de8a905 | 2011-09-14 23:13:09 +0000 | [diff] [blame] | 34 | // CHECK-PREPROCESSED: int i = INTEGER; |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 35 | int i = INTEGER; // the value was exported, the macro was not. |
Douglas Gregor | b09de51 | 2012-09-25 15:44:52 +0000 | [diff] [blame] | 36 | i += macros; // expanded from __MODULE__ within the 'macros' module. |
Douglas Gregor | ce835df | 2011-09-14 22:14:14 +0000 | [diff] [blame] | 37 | } |
Douglas Gregor | b09de51 | 2012-09-25 15:44:52 +0000 | [diff] [blame] | 38 | |
| 39 | #ifdef __MODULE__ |
| 40 | # error Not building a module! |
| 41 | #endif |
| 42 | |
| 43 | #if __building_module(macros) |
| 44 | # error Not building a module |
| 45 | #endif |
Douglas Gregor | 6c6c54a | 2012-10-11 00:46:49 +0000 | [diff] [blame] | 46 | |
| 47 | // None of the modules we depend on have been imported, and therefore |
| 48 | // their macros should not be visible. |
| 49 | #ifdef LEFT |
| 50 | # error LEFT should not be visible |
| 51 | #endif |
| 52 | |
| 53 | #ifdef RIGHT |
| 54 | # error RIGHT should not be visible |
| 55 | #endif |
| 56 | |
| 57 | #ifdef TOP |
| 58 | # error TOP should not be visible |
| 59 | #endif |
| 60 | |
| 61 | // Import left module (which also imports top) |
| 62 | @__experimental_modules_import macros_left; |
| 63 | |
| 64 | #ifndef LEFT |
| 65 | # error LEFT should be visible |
| 66 | #endif |
| 67 | |
| 68 | #ifdef RIGHT |
| 69 | # error RIGHT should not be visible |
| 70 | #endif |
| 71 | |
| 72 | #ifndef TOP |
| 73 | # error TOP should be visible |
| 74 | #endif |
| 75 | |
| 76 | #ifdef TOP_LEFT_UNDEF |
| 77 | # error TOP_LEFT_UNDEF should not be visible |
| 78 | #endif |
| 79 | |
| 80 | void test1() { |
| 81 | int i; |
| 82 | TOP_RIGHT_REDEF *ip = &i; |
| 83 | } |
| 84 | |
| 85 | #define LEFT_RIGHT_DIFFERENT2 double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT2' macro redefined}} |
| 86 | |
| 87 | // Import right module (which also imports top) |
| 88 | @__experimental_modules_import macros_right; |
| 89 | |
| 90 | #undef LEFT_RIGHT_DIFFERENT3 |
| 91 | |
| 92 | #ifndef LEFT |
| 93 | # error LEFT should be visible |
| 94 | #endif |
| 95 | |
| 96 | #ifndef RIGHT |
| 97 | # error RIGHT should be visible |
| 98 | #endif |
| 99 | |
| 100 | #ifndef TOP |
| 101 | # error TOP should be visible |
| 102 | #endif |
| 103 | |
| 104 | #ifndef TOP_LEFT_UNDEF |
| 105 | # error TOP_LEFT_UNDEF should be visible |
| 106 | #endif |
| 107 | |
| 108 | void test2() { |
| 109 | int i; |
| 110 | float f; |
| 111 | double d; |
| 112 | TOP_RIGHT_REDEF *ip = &i; // FIXME: warning |
| 113 | |
| 114 | LEFT_RIGHT_IDENTICAL *ip2 = &i; |
| 115 | LEFT_RIGHT_DIFFERENT *fp = &f; // FIXME: warning |
| 116 | LEFT_RIGHT_DIFFERENT2 *dp = &d; // okay |
| 117 | int LEFT_RIGHT_DIFFERENT3; |
| 118 | } |
| 119 | |
| 120 | #define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}} |
| 121 | |
| 122 | void test3() { |
| 123 | double d; |
| 124 | LEFT_RIGHT_DIFFERENT *dp = &d; // okay |
| 125 | } |