aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/Sema.cpp
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-08-09 13:39:24 +0800
committerGitHub <noreply@github.com>2024-08-09 13:39:24 +0800
commitbe66c506c7fd6fdb7363f724075d02ca0d35713a (patch)
treefcf2821a10fcead503e51718bc8a2d0cd703819c /clang/lib/Sema/Sema.cpp
parent5297b750e54dafe16cc13f24b8d5478214e83682 (diff)
downloadllvm-be66c506c7fd6fdb7363f724075d02ca0d35713a.zip
llvm-be66c506c7fd6fdb7363f724075d02ca0d35713a.tar.gz
llvm-be66c506c7fd6fdb7363f724075d02ca0d35713a.tar.bz2
[C++20] [Modules] Emit Errors when compiling a non-module source as module (#102565)
Close https://github.com/llvm/llvm-project/issues/101398 The root cause of the issue is that I removed the codes before and failed to recognize it in time and this was not found for a long time due to it only crashes with invalid codes.
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r--clang/lib/Sema/Sema.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 19d8692..633b822 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1272,6 +1272,18 @@ void Sema::ActOnEndOfTranslationUnit() {
Module::ExplicitGlobalModuleFragment) {
Diag(ModuleScopes.back().BeginLoc,
diag::err_module_declaration_missing_after_global_module_introducer);
+ } else if (getLangOpts().getCompilingModule() ==
+ LangOptions::CMK_ModuleInterface &&
+ // We can't use ModuleScopes here since ModuleScopes is always
+ // empty if we're compiling the BMI.
+ !getASTContext().getCurrentNamedModule()) {
+ // If we are building a module interface unit, we should have seen the
+ // module declaration.
+ //
+ // FIXME: Make a better guess as to where to put the module declaration.
+ Diag(getSourceManager().getLocForStartOfFile(
+ getSourceManager().getMainFileID()),
+ diag::err_module_declaration_missing);
}
// Now we can decide whether the modules we're building need an initializer.