[clang] [modules] Fix assert on Clang module import from the global module fragment. (PR #159771)

Koby Kahane via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 19 12:02:21 PDT 2025


================
@@ -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");
----------------
kobykahane wrote:

```suggestion
           "was expecting a module if building a Clang module");
```

https://github.com/llvm/llvm-project/pull/159771


More information about the cfe-commits mailing list