1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4 // RUN: cd %t
5 //
6 // RUN: %clang_cc1 -std=c++20 -xc++-user-header h1.h -emit-header-unit -o h1.pcm
7 // RUN: %clang_cc1 -std=c++20 -xc++-user-header h2.h -emit-header-unit -o h2.pcm
8 // RUN: %clang_cc1 -std=c++20 -xc++-user-header h3.h -emit-header-unit -o h3.pcm
9 // RUN: %clang_cc1 -std=c++20 -xc++-user-header h4.h -emit-header-unit -o h4.pcm
10 
11 // RUN: %clang_cc1 -std=c++20 Xlate.cpp -emit-module-interface -o Xlate.pcm \
12 // RUN: -fmodule-file=h1.pcm -fmodule-file=h2.pcm -fmodule-file=h3.pcm \
13 // RUN: -fmodule-file=h4.pcm -fsyntax-only -Rmodule-include-translation -verify
14 
15 // Check that we do the intended translation and not more.
16 // RUN: %clang_cc1 -std=c++20 Xlate.cpp \
17 // RUN: -fmodule-file=h1.pcm -fmodule-file=h2.pcm -fmodule-file=h3.pcm \
18 // RUN: -fmodule-file=h4.pcm  -E -undef | FileCheck %s
19 
20 // We expect no diagnostics here, the used functions should all be available.
21 // RUN: %clang_cc1 -std=c++20 Xlate.cpp -emit-module-interface \
22 // RUN: -fmodule-file=h1.pcm -fmodule-file=h2.pcm -fmodule-file=h3.pcm \
23 // RUN: -fmodule-file=h4.pcm -fsyntax-only
24 
25 // The content of the headers is not terribly important, we just want to check
26 // whether they are textually included or include-translated.
27 //--- h1.h
28 #ifndef H1_GUARD
29 #define H1_GUARD
30 
31 #define ONE 1
32 
33 void foo();
34 
35 #endif // H1_GUARD
36 
37 //--- h2.h
38 #ifndef H2_GUARD
39 #define H2_GUARD
40 
41 #define TWO 2
42 
43 void bar();
44 
45 #endif // H2_GUARD
46 
47 //--- h3.h
48 #ifndef H3_GUARD
49 #define H3_GUARD
50 
51 #define THREE 3
52 
53 void baz();
54 
55 #endif // H3_GUARD
56 
57 //--- h4.h
58 #ifndef H4_GUARD
59 #define H4_GUARD
60 
61 #define FOUR 4
62 
63 void boo();
64 
65 #endif // H4_GUARD
66 
67 //--- h5.h
68 #ifndef H5_GUARD
69 #define H5_GUARD
70 
71 #define FIVE 5
72 
73 void five();
74 
75 #endif // H4_GUARD
76 
77 //--- Xlate.cpp
78 /* some comment ...
79   ... */
80 module /*nothing here*/;
81 
82 // This should be include-translated, when the header unit for h1 is available.
83 #include "h1.h" // expected-remark {{treating #include as an import of module './h1.h'}}
84 // Import of a header unit is allowed, named modules are not.
85 import "h2.h";
86 // A regular, untranslated, header
87 #include "h5.h"
88 
89 export module Xlate;
90 
91 // This is OK, the import immediately follows the module decl.
92 import "h3.h";
93 
94 // This should *not* be include-translated, even if header unit for h4 is
95 // available.
96 #include "h4.h"
97 
charlie()98 export void charlie() {
99   foo();
100   bar();
101   baz();
102   boo();
103   five();
104 }
105 
106 // CHECK: #pragma clang module import "./h1.h"
107 // CHECK: import ./h2.h
108 // CHECK: import ./h3.h
109 // CHECK-NOT: #pragma clang module import "./h4.h"
110