aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2022-10-08 16:38:19 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2022-10-08 16:44:51 +0800
commit9974ed804995d2e34be69404e9904c7e03cfbda4 (patch)
tree743108d7d75d590515529d3bd124f21d668130a6
parent566c277c64f8f76d8911aa5fd931903a357ed7be (diff)
downloadllvm-9974ed804995d2e34be69404e9904c7e03cfbda4.zip
llvm-9974ed804995d2e34be69404e9904c7e03cfbda4.tar.gz
llvm-9974ed804995d2e34be69404e9904c7e03cfbda4.tar.bz2
[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.
-rw-r--r--clang/lib/Sema/SemaModule.cpp5
-rw-r--r--clang/test/Modules/missing-module-declaration.cppm13
2 files changed, 13 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index b205fd9..4b01f10 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 0000000..d52f663
--- /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;