1 // Test check that consuming -E -fdirectives-only output produces the expected 2 // header unit. 3 4 // RUN: rm -rf %t 5 // RUN: mkdir -p %t 6 // RUN: split-file %s %t 7 // RUN: cd %t 8 9 // RUN: %clang_cc1 -std=c++20 -E -fdirectives-only -xc++-user-header hu-01.h \ 10 // RUN: -o hu-01.iih 11 12 // RUN: %clang_cc1 -std=c++20 -emit-header-unit \ 13 // RUN: -xc++-user-header-cpp-output hu-01.iih -o hu-01.pcm 14 15 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \ 16 // RUN: -DFOO -fmodule-file=hu-01.pcm -o hu-02.pcm -Rmodule-import 2>&1 | \ 17 // RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t 18 19 //--- hu-01.h 20 #ifndef __GUARD 21 #define __GUARD 22 23 int baz(int); 24 #define FORTYTWO 42 25 26 #define SHOULD_NOT_BE_DEFINED -1 27 #undef SHOULD_NOT_BE_DEFINED 28 29 #endif // __GUARD 30 // expected-no-diagnostics 31 32 //--- hu-02.h 33 export import "hu-01.h"; 34 #if !defined(FORTYTWO) || FORTYTWO != 42 35 #error FORTYTWO missing in hu-02 36 #endif 37 38 #ifndef __GUARD 39 #error __GUARD missing in hu-02 40 #endif 41 42 #ifdef SHOULD_NOT_BE_DEFINED 43 #error SHOULD_NOT_BE_DEFINED is visible 44 #endif 45 46 // Make sure that we have not discarded macros from the builtin file. 47 #ifndef __cplusplus 48 #error we dropped a defined macro 49 #endif 50 51 #define KAP 6174 52 53 #ifdef FOO 54 #define FOO_BRANCH(X) (X) + 1 foo(int x)55inline int foo(int x) { 56 if (x == FORTYTWO) 57 return FOO_BRANCH(x); 58 return FORTYTWO; 59 } 60 #else 61 #define BAR_BRANCH(X) (X) + 2 62 inline int bar(int x) { 63 if (x == FORTYTWO) 64 return BAR_BRANCH(x); 65 return FORTYTWO; 66 } 67 #endif 68 // CHECK-IMP: remark: importing module '.{{/|\\\\?}}hu-01.h' from 'hu-01.pcm' 69