llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)

<details>
<summary>Changes</summary>

Using `ModuleToImport` when deciding whether to turn a repeated include into an 
import, or whether to skip it, isn't right. We have `ModuleToImport` even 
without `-fmodules`. This PR starts checking `UsableClangHeaderModule`, 
matching what we do for the first inclusion of that header.

rdar://184549117

---
Full diff: https://github.com/llvm/llvm-project/pull/216704.diff


2 Files Affected:

- (modified) clang/lib/Lex/PPDirectives.cpp (+2-1) 
- (added) clang/test/Modules/non-modular-with-module-file.c (+31) 


``````````diff
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"

``````````

</details>


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

Reply via email to