[clang] fc89e90 - [C++20] [Modules] Emit an warning for experimental header units

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Thu May 18 01:13:03 PDT 2023


Author: Chuanqi Xu
Date: 2023-05-18T16:12:41+08:00
New Revision: fc89e9044d0b37dcd4e3f085f21bef1b21d2ab8d

URL: https://github.com/llvm/llvm-project/commit/fc89e9044d0b37dcd4e3f085f21bef1b21d2ab8d
DIFF: https://github.com/llvm/llvm-project/commit/fc89e9044d0b37dcd4e3f085f21bef1b21d2ab8d.diff

LOG: [C++20] [Modules] Emit an warning for experimental header units

Currently, the header units are rarely used and it is not well tested.
To avoid further misunderstandings, let's mark it as experimental and
emit a warning when users wants to import it.

This is discussed in modules developers meeting.

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/lib/Sema/SemaModule.cpp
    clang/test/CXX/module/module.interface/p2.cpp
    clang/test/Modules/cxx20-10-2-ex2.cpp
    clang/test/Modules/cxx20-hu-04.cpp
    clang/test/Modules/cxx20-include-translation.cpp
    clang/test/Modules/merge-concepts.cppm

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0d93727ccc7b3..54671bfe4e943 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11279,6 +11279,10 @@ def err_invalid_module_name : Error<"%0 is an invalid name for a module">;
 def err_extern_def_in_header_unit : Error<
   "non-inline external definitions are not permitted in C++ header units">;
 
+def warn_experimental_header_unit : Warning<
+  "the implementation of header units is in an experimental phase">,
+  InGroup<DiagGroup<"experimental-header-units">>;
+
 def ext_equivalent_internal_linkage_decl_in_modules : ExtWarn<
   "ambiguous use of internal linkage declaration %0 defined in multiple modules">,
   InGroup<DiagGroup<"modules-ambiguous-internal-linkage">>;

diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index e1d7c290effe4..a1ab013fcf5e8 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -544,6 +544,9 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
                                    SourceLocation ExportLoc,
                                    SourceLocation ImportLoc, Module *Mod,
                                    ModuleIdPath Path) {
+  if (Mod->isHeaderUnit())
+    Diag(ImportLoc, diag::warn_experimental_header_unit);
+
   VisibleModules.setVisible(Mod, ImportLoc);
 
   checkModuleImportContext(*this, Mod, ImportLoc, CurContext);

diff  --git a/clang/test/CXX/module/module.interface/p2.cpp b/clang/test/CXX/module/module.interface/p2.cpp
index 0cb6514cd3345..bf4e3f9650fd4 100644
--- a/clang/test/CXX/module/module.interface/p2.cpp
+++ b/clang/test/CXX/module/module.interface/p2.cpp
@@ -5,9 +5,10 @@
 // RUN: %clang_cc1 -std=c++20 %s -DY_INTERFACE -emit-module-interface -o %t/y.pcm
 // RUN: %clang_cc1 -std=c++20 %s -DINTERFACE -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -emit-module-interface -o %t/m.pcm
 // RUN: %clang_cc1 -std=c++20 %s -DIMPLEMENTATION -I%S/Inputs -fmodule-file=%t/h.pcm \
-// RUN:   -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -fmodule-file=p2=%t/m.pcm -verify
+// RUN:   -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -fmodule-file=p2=%t/m.pcm -verify \
+// RUN:   -Wno-experimental-header-units
 // RUN: %clang_cc1 -std=c++20 %s -DUSER -I%S/Inputs -fmodule-file=%t/h.pcm -fmodule-file=p2=%t/m.pcm \
-// RUN:   -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -verify
+// RUN:   -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -Wno-experimental-header-units -verify
 
 #if defined(X_INTERFACE)
 export module X;

diff  --git a/clang/test/Modules/cxx20-10-2-ex2.cpp b/clang/test/Modules/cxx20-10-2-ex2.cpp
index 659e4fe937e17..bc66d6a2ec1a9 100644
--- a/clang/test/Modules/cxx20-10-2-ex2.cpp
+++ b/clang/test/Modules/cxx20-10-2-ex2.cpp
@@ -29,7 +29,7 @@ module;
 #include "std-10-2-ex2-b.h"
 
 export module M;
-import "std-10-2-ex2-c.h";
+import "std-10-2-ex2-c.h";  // expected-warning {{the implementation of header units is in an experimental phase}}
 import X;
 export using ::f, ::g, ::h; // OK
 struct S;                   // expected-note {{target of using declaration}}

diff  --git a/clang/test/Modules/cxx20-hu-04.cpp b/clang/test/Modules/cxx20-hu-04.cpp
index da6056d4d47ed..aed1bdb875ec9 100644
--- a/clang/test/Modules/cxx20-hu-04.cpp
+++ b/clang/test/Modules/cxx20-hu-04.cpp
@@ -42,7 +42,7 @@ int baz(int);
 // CHECK-HU-NEXT:  Header Unit './hu-01.h' is the Primary Module at index #1
 
 //--- hu-02.h
-export import "hu-01.h";
+export import "hu-01.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
 #if !defined(FORTYTWO) || FORTYTWO != 42
 #error FORTYTWO missing in hu-02
 #endif
@@ -82,7 +82,7 @@ inline int bar(int x) {
 
 //--- importer-01.cpp
 export module B;
-import "hu-02.h";
+import "hu-02.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
 
 int success(int x) {
   return foo(FORTYTWO + x + KAP);
@@ -95,7 +95,7 @@ int fail(int x) {
 
 //--- importer-02.cpp
 export module C;
-import "hu-02.h";
+import "hu-02.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
 
 int success(int x) {
   return foo(FORTYTWO + x + KAP);

diff  --git a/clang/test/Modules/cxx20-include-translation.cpp b/clang/test/Modules/cxx20-include-translation.cpp
index 32c7439224573..2528e831d8088 100644
--- a/clang/test/Modules/cxx20-include-translation.cpp
+++ b/clang/test/Modules/cxx20-include-translation.cpp
@@ -80,16 +80,17 @@ void five();
 module /*nothing here*/;
 
 // This should be include-translated, when the header unit for h1 is available.
+ // expected-warning at +1 {{the implementation of header units is in an experimental phase}}
 #include "h1.h" // expected-remark {{treating #include as an import of module './h1.h'}}
 // Import of a header unit is allowed, named modules are not.
-import "h2.h";
+import "h2.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
 // A regular, untranslated, header
 #include "h5.h"
 
 export module Xlate;
 
 // This is OK, the import immediately follows the module decl.
-import "h3.h";
+import "h3.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
 
 // This should *not* be include-translated, even if header unit for h4 is
 // available.

diff  --git a/clang/test/Modules/merge-concepts.cppm b/clang/test/Modules/merge-concepts.cppm
index ca4877bfd7949..9b611bc2f1b5e 100644
--- a/clang/test/Modules/merge-concepts.cppm
+++ b/clang/test/Modules/merge-concepts.cppm
@@ -143,8 +143,7 @@ concept same_as = __is_same(T, U);
 // expected-note@* 1+{{previous definition is here}}
 
 //--- Use5.cpp
-// expected-no-diagnostics
-import "foo.h";
+import "foo.h";  // expected-warning {{the implementation of header units is in an experimental phase}}
 import A;
 
 template <class T> void foo()
@@ -152,9 +151,8 @@ template <class T> void foo()
 {}
 
 //--- Use6.cpp
-// expected-no-diagnostics
 import A;
-import "foo.h";
+import "foo.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
 
 template <class T> void foo()
   requires same_as<T, int>


        


More information about the cfe-commits mailing list