[clang] [clang][Modules] Don't treat recovered module-end at EOF as an included header (PR #225099)

Aleksandr Platonov via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 27 23:03:25 PDT 2026


================
@@ -815,13 +815,16 @@ void Sema::ActOnAnnotModuleEnd(SourceLocation EomLoc, Module *Mod) {
   // ImportDecl as we would for an imported module.
   FileID File = getSourceManager().getFileID(EomLoc);
   SourceLocation DirectiveLoc;
-  if (EomLoc == getSourceManager().getLocForEndOfFile(File)) {
+  SourceLocation IncludeLoc = getSourceManager().getIncludeLoc(File);
+  if (EomLoc == getSourceManager().getLocForEndOfFile(File) &&
+      IncludeLoc.isValid()) {
----------------
ArcsinX wrote:

What if we have `#pragma clang module build N`/`#pragma clang module begin N`  inside a header and include this header from the main file?
It seems that for this case `IncludeLoc.isValid()` is true (for this header inclusion). I don't know can this lead to some problems, but maybe we need a test for such a case.

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


More information about the cfe-commits mailing list