1 // RUN: rm -rf %t 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 6 // RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t %s 7 // RUN: not %clang_cc1 -E -fmodules -x objective-c -fmodules-cache-path=%t %s | FileCheck -check-prefix CHECK-PREPROCESSED %s 8 // FIXME: When we have a syntax for modules in C, use that. 9 // These notes come from headers in modules, and are bogus. 10 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'}} 14 // expected-note@Inputs/macros_top.h:13{{other definition of 'TOP_RIGHT_REDEF'}} 15 // expected-note@Inputs/macros_right.h:13{{expanding this definition of 'LEFT_RIGHT_DIFFERENT2'}} 16 // expected-note@Inputs/macros_left.h:14{{other definition of 'LEFT_RIGHT_DIFFERENT'}} 17 // expected-note@Inputs/macros_right.h:17{{expanding this definition of 'TOP_RIGHT_REDEF'}} 18 19 @import macros; 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 33 // CHECK-PREPROCESSED: double d 34 double d; 35 DOUBLE *dp = &d; 36 37 #__public_macro WIBBLE // expected-error{{no macro named 'WIBBLE'}} 38 f()39void f() { 40 // CHECK-PREPROCESSED: int i = INTEGER; 41 int i = INTEGER; // the value was exported, the macro was not. 42 i += macros; // expanded from __MODULE__ within the 'macros' module. 43 } 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 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) 68 @import macros_left; 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 #ifndef TOP_LEFT_UNDEF 83 # error TOP_LEFT_UNDEF should still be defined 84 #endif 85 test1()86void 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 // expected-note{{other definition of 'LEFT_RIGHT_DIFFERENT2'}} 93 94 // Import right module (which also imports top) 95 @import macros_right; 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 test2()111void test2() { 112 int i; 113 float f; 114 double d; 115 TOP_RIGHT_REDEF *fp = &f; // expected-warning{{ambiguous expansion of macro 'TOP_RIGHT_REDEF'}} 116 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}} 120 int LEFT_RIGHT_DIFFERENT3; 121 } 122 123 #define LEFT_RIGHT_DIFFERENT double // FIXME: expected-warning{{'LEFT_RIGHT_DIFFERENT' macro redefined}} 124 test3()125void test3() { 126 double d; 127 LEFT_RIGHT_DIFFERENT *dp = &d; // okay 128 int x = FN_ADD(1,2); 129 } 130 131 #ifndef TOP_RIGHT_UNDEF 132 # error TOP_RIGHT_UNDEF should still be defined 133 #endif 134 135 @import macros_right.undef; 136 137 #ifndef TOP_RIGHT_UNDEF 138 # error TOP_RIGHT_UNDEF should still be defined 139 #endif 140