[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / cxx20-include-translation.cpp
bloba607e7c0373f814cef379a6467c5abfc1f93444c
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
11 // RUN: %clang_cc1 -std=c++20 Xlate.cpp -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
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
20 // We expect no diagnostics here, the used functions should all be available.
21 // RUN: %clang_cc1 -std=c++20 Xlate.cpp \
22 // RUN: -fmodule-file=h1.pcm -fmodule-file=h2.pcm -fmodule-file=h3.pcm \
23 // RUN: -fmodule-file=h4.pcm -fsyntax-only
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
31 #define ONE 1
33 void foo();
35 #endif // H1_GUARD
37 //--- h2.h
38 #ifndef H2_GUARD
39 #define H2_GUARD
41 #define TWO 2
43 void bar();
45 #endif // H2_GUARD
47 //--- h3.h
48 #ifndef H3_GUARD
49 #define H3_GUARD
51 #define THREE 3
53 void baz();
55 #endif // H3_GUARD
57 //--- h4.h
58 #ifndef H4_GUARD
59 #define H4_GUARD
61 #define FOUR 4
63 void boo();
65 #endif // H4_GUARD
67 //--- h5.h
68 #ifndef H5_GUARD
69 #define H5_GUARD
71 #define FIVE 5
73 void five();
75 #endif // H4_GUARD
77 //--- Xlate.cpp
78 /* some comment ...
79 ... */
80 module /*nothing here*/;
82 // This should be include-translated, when the header unit for h1 is available.
83 // expected-warning@+1 {{the implementation of header units is in an experimental phase}}
84 #include "h1.h" // expected-remark-re {{treating #include as an import of module '.{{/|\\\\?}}h1.h'}}
85 // Import of a header unit is allowed, named modules are not.
86 import "h2.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
87 // A regular, untranslated, header
88 #include "h5.h"
90 export module Xlate;
92 // This is OK, the import immediately follows the module decl.
93 import "h3.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
95 // This should *not* be include-translated, even if header unit for h4 is
96 // available.
97 #include "h4.h"
99 export void charlie() {
100 foo();
101 bar();
102 baz();
103 boo();
104 five();
107 // CHECK: #pragma clang module import ".{{/|\\\\?}}h1.h"
108 // CHECK: import ".{{/|\\\\?}}h2.h"
109 // CHECK: import ".{{/|\\\\?}}h3.h"
110 // CHECK-NOT: #pragma clang module import ".{{/|\\\\?}}h4.h"