https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/216704

>From 01a6e88c475a269a633cd3c00e50c0d25f46e130 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <[email protected]>
Date: Mon, 17 Aug 2026 13:45:08 +0200
Subject: [PATCH 1/4] [clang][lex] Do not translate repeated include into
 import

---
 clang/lib/Lex/PPDirectives.cpp                |  3 +-
 .../Modules/non-modular-with-module-file.c    | 31 +++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Modules/non-modular-with-module-file.c

diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index ec387a4d582fc..24e63b8bae711 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2590,7 +2590,8 @@ Preprocessor::ImportAction 
Preprocessor::HandleHeaderIncludeOrImport(
     if (UsableHeaderUnit && !getLangOpts().CompilingPCH)
       Action = TrackGMFState.inGMF() ? Import : Skip;
     else
-      Action = (ModuleToImport && !getLangOpts().CompilingPCH) ? Import : Skip;
+      Action = (UsableClangHeaderModule && !getLangOpts().CompilingPCH) ? 
Import
+                                                                        : Skip;
   }
 
   // Check for circular inclusion of the main file.
diff --git a/clang/test/Modules/non-modular-with-module-file.c 
b/clang/test/Modules/non-modular-with-module-file.c
new file mode 100644
index 0000000000000..f486d9564c2d0
--- /dev/null
+++ b/clang/test/Modules/non-modular-with-module-file.c
@@ -0,0 +1,31 @@
+// Check that repeated inclusion of a modular header doesn't get translated
+// into an import in textual compilation.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -E %t/tu.c -o %t/tu.ii -I %t 
-fmodule-map-file=%t/module.modulemap
+
+// RUN: FileCheck --input-file=%t/tu.ii %s -DPREFIX=%/t
+
+// CHECK:      # 1 "[[PREFIX]]/tu.c"
+// CHECK-NEXT: # 1 "<built-in>" 1
+// CHECK-NEXT: # 1 "<built-in>" 3
+// CHECK-NEXT: # {{[0-9]+}} "<built-in>" 3
+// CHECK-NEXT: # 1 "<command line>" 1
+// CHECK-NEXT: # 1 "<built-in>" 2
+// CHECK-NEXT: # 1 "[[PREFIX]]/tu.c" 2
+// CHECK-NEXT: # 1 "[[PREFIX]]/Mod.h" 1
+// CHECK-NEXT: #pragma clang module begin Mod
+// CHECK-NEXT: # 2 "[[PREFIX]]/tu.c" 2
+// CHECK-NEXT: # 1 "[[PREFIX]]/tu.c"
+// CHECK-NEXT: #pragma clang module end /*Mod*/
+// CHECK-NOT:  #pragma clang module import
+
+//--- module.modulemap
+module Mod { header "Mod.h" }
+//--- Mod.h
+#pragma once
+//--- tu.c
+#include "Mod.h"
+#include "Mod.h"

>From 72617f825c707c187495562f7a9378e0d5e7f73e Mon Sep 17 00:00:00 2001
From: Jan Svoboda <[email protected]>
Date: Mon, 17 Aug 2026 21:08:48 +0200
Subject: [PATCH 2/4] Path separators in test

---
 clang/test/Modules/non-modular-with-module-file.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/test/Modules/non-modular-with-module-file.c 
b/clang/test/Modules/non-modular-with-module-file.c
index f486d9564c2d0..bcbaa89e56b19 100644
--- a/clang/test/Modules/non-modular-with-module-file.c
+++ b/clang/test/Modules/non-modular-with-module-file.c
@@ -8,17 +8,17 @@
 
 // RUN: FileCheck --input-file=%t/tu.ii %s -DPREFIX=%/t
 
-// CHECK:      # 1 "[[PREFIX]]/tu.c"
+// CHECK:      # 1 "[[PREFIX]]{{/|\\}}tu.c"
 // CHECK-NEXT: # 1 "<built-in>" 1
 // CHECK-NEXT: # 1 "<built-in>" 3
 // CHECK-NEXT: # {{[0-9]+}} "<built-in>" 3
 // CHECK-NEXT: # 1 "<command line>" 1
 // CHECK-NEXT: # 1 "<built-in>" 2
-// CHECK-NEXT: # 1 "[[PREFIX]]/tu.c" 2
-// CHECK-NEXT: # 1 "[[PREFIX]]/Mod.h" 1
+// CHECK-NEXT: # 1 "[[PREFIX]]{{/|\\}}tu.c" 2
+// CHECK-NEXT: # 1 "[[PREFIX]]{{/|\\}}Mod.h" 1
 // CHECK-NEXT: #pragma clang module begin Mod
-// CHECK-NEXT: # 2 "[[PREFIX]]/tu.c" 2
-// CHECK-NEXT: # 1 "[[PREFIX]]/tu.c"
+// CHECK-NEXT: # 2 "[[PREFIX]]{{/|\\}}tu.c" 2
+// CHECK-NEXT: # 1 "[[PREFIX]]{{/|\\}}tu.c"
 // CHECK-NEXT: #pragma clang module end /*Mod*/
 // CHECK-NOT:  #pragma clang module import
 

>From 9e73d997850aba47e772c5c1e31f4337caad5f17 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <[email protected]>
Date: Mon, 17 Aug 2026 21:46:52 +0200
Subject: [PATCH 3/4] Path separators in test

---
 clang/test/Modules/non-modular-with-module-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Modules/non-modular-with-module-file.c 
b/clang/test/Modules/non-modular-with-module-file.c
index bcbaa89e56b19..ac2f761e85013 100644
--- a/clang/test/Modules/non-modular-with-module-file.c
+++ b/clang/test/Modules/non-modular-with-module-file.c
@@ -6,7 +6,7 @@
 
 // RUN: %clang_cc1 -E %t/tu.c -o %t/tu.ii -I %t 
-fmodule-map-file=%t/module.modulemap
 
-// RUN: FileCheck --input-file=%t/tu.ii %s -DPREFIX=%/t
+// RUN: FileCheck --input-file=%t/tu.ii %s -DPREFIX=%t
 
 // CHECK:      # 1 "[[PREFIX]]{{/|\\}}tu.c"
 // CHECK-NEXT: # 1 "<built-in>" 1

>From f7fc35811e80e25dfd77c9c66391661bdcbede81 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <[email protected]>
Date: Tue, 18 Aug 2026 08:09:22 +0200
Subject: [PATCH 4/4] Release note

---
 clang/docs/ReleaseNotes.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 272227b1cdf1e..f5f9958543e34 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -416,6 +416,7 @@ features cannot lower the translation-unit ABI level;
 - Fixed an ICE that occurred when a structured binding pack is expanded 
outside the lambda where it was declared. (#GH214160)
 - Fixed a bug where a stray closing curley brace in an OpenMP/OpenACC pragma 
could cause pragma parsing issues when inside of a member function. (#GH214195)
 - Fixed a bug where preprocessor directives following comments were not 
correctly recognized when using -C. (#GH48361)
+- Fixed a bug where repeated #imports of modular headers in non-modular 
compilation were translated to #pragma clang module import. (#GH216924)
 
 #### Bug Fixes to Compiler Builtins
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to