[clang] 9974ed8 - [C++20] [Modules] Remove assertion of current module when acting on import

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 8 01:46:10 PDT 2022


Author: Chuanqi Xu
Date: 2022-10-08T16:44:51+08:00
New Revision: 9974ed804995d2e34be69404e9904c7e03cfbda4

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

LOG: [C++20] [Modules] Remove assertion of current module when acting on import

Closes https://github.com/llvm/llvm-project/issues/58199

Previously, when we act on a import statement, we'll assume there is a
module declaration in the current TU if the command line tells us we're
compiling a module unit. This makes since on valid codes. However, for
invalid codes, it is possible. See
https://github.com/llvm/llvm-project/issues/58199 for example.

This patch removes the assertion. And the assertion is a noop and it
should be safe to remove it.

Added: 
    clang/test/Modules/missing-module-declaration.cppm

Modified: 
    clang/lib/Sema/SemaModule.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index b205fd914f9d3..4b01f109fc881 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -561,11 +561,6 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
     Diag(ExportLoc, diag::err_export_not_in_module_interface)
         << (!ModuleScopes.empty() &&
             !ModuleScopes.back().ImplicitGlobalModuleFragment);
-  } else if (getLangOpts().isCompilingModule()) {
-    Module *ThisModule = PP.getHeaderSearchInfo().lookupModule(
-        getLangOpts().CurrentModule, ExportLoc, false, false);
-    (void)ThisModule;
-    assert(ThisModule && "was expecting a module if building one");
   }
 
   // In some cases we need to know if an entity was present in a directly-

diff  --git a/clang/test/Modules/missing-module-declaration.cppm b/clang/test/Modules/missing-module-declaration.cppm
new file mode 100644
index 0000000000000..d52f6639fe4f6
--- /dev/null
+++ b/clang/test/Modules/missing-module-declaration.cppm
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/B.cppm -I%t -emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -I%t -fprebuilt-module-path=%t -emit-module-interface -verify
+
+//--- A.cppm
+import B; // expected-error{{missing 'export module' declaration in module interface unit}}
+
+//--- B.cppm
+module;
+export module B;


        


More information about the cfe-commits mailing list