aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaModule.cpp
diff options
context:
space:
mode:
authorNaveen Seth Hanig <naveen.hanig@outlook.com>2025-09-20 05:49:56 +0530
committerGitHub <noreply@github.com>2025-09-20 00:19:56 +0000
commit4554cdf6cfd1745ecdbad6665b17913c4af9c1b2 (patch)
tree0cb45e3a49af7967518cbe0cdb72da5eebf23cde /clang/lib/Sema/SemaModule.cpp
parent9b3e2f53eb219e7ed2f0a761bad2fa3bd396a57c (diff)
downloadllvm-4554cdf6cfd1745ecdbad6665b17913c4af9c1b2.zip
llvm-4554cdf6cfd1745ecdbad6665b17913c4af9c1b2.tar.gz
llvm-4554cdf6cfd1745ecdbad6665b17913c4af9c1b2.tar.bz2
[modules] Fix assert on Clang module import from the global module fragment. (#159771)
Fixes #159768. When building a named module interface with `-fmodules` enabled, importing a Clang module from inside the global module fragment causes Clang to crash only on assertion builds. This fixes the assert and extends the test coverage.
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r--clang/lib/Sema/SemaModule.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 773bcb2..a2aa3ea 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -772,7 +772,12 @@ void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
Module *ThisModule = PP.getHeaderSearchInfo().lookupModule(
getLangOpts().CurrentModule, DirectiveLoc, false, false);
(void)ThisModule;
- assert(ThisModule && "was expecting a module if building one");
+ // For named modules, the current module name is not known while parsing the
+ // global module fragment and lookupModule may return null.
+ assert((getLangOpts().getCompilingModule() ==
+ LangOptionsBase::CMK_ModuleInterface ||
+ ThisModule) &&
+ "was expecting a module if building a Clang module");
}
}