https://github.com/qiongsiwu created 
https://github.com/llvm/llvm-project/pull/176499

…nd a module with config macros (#174034)"

This reverts commit 71925cbdf80d4fc88ef844e726f89aa71c64bceb.

The test case is causing test failures on downstream Swift forks. This PR 
reverts the commit to avoid failing the test case on Linux.

rdar://168174041

>From c17714789bf9ead12ec35236bc4acc3adbec9f03 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu <[email protected]>
Date: Fri, 16 Jan 2026 15:53:09 -0800
Subject: [PATCH] Revert "[clang][Modules] Fix unexpected warnings triggered by
 a PCH and a module with config macros (#174034)"

This reverts commit 71925cbdf80d4fc88ef844e726f89aa71c64bceb.
---
 clang/include/clang/Lex/Preprocessor.h        | 11 -----
 clang/lib/Frontend/CompilerInstance.cpp       |  4 +-
 clang/lib/Lex/PPMacroExpansion.cpp            | 29 -----------
 .../Inputs/pch-config-macros/include/Mod1.h   |  5 --
 .../include/module.modulemap                  |  4 --
 clang/test/Modules/pch-config-macros.c        | 48 -------------------
 6 files changed, 1 insertion(+), 100 deletions(-)
 delete mode 100644 clang/test/Modules/Inputs/pch-config-macros/include/Mod1.h
 delete mode 100644 
clang/test/Modules/Inputs/pch-config-macros/include/module.modulemap
 delete mode 100644 clang/test/Modules/pch-config-macros.c

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4bff1b395b5fc..b1c648e647f41 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1119,10 +1119,6 @@ class Preprocessor {
   /// The file ID for the PCH through header.
   FileID PCHThroughHeaderFileID;
 
-  /// The file ID for the predefines that come from the PCH.
-  /// This is only set when modules are in effect.
-  FileID PCHPredefinesFileID;
-
   /// Whether tokens are being skipped until a #pragma hdrstop is seen.
   bool SkippingUntilPragmaHdrStop = false;
 
@@ -1319,13 +1315,6 @@ class Preprocessor {
   /// Returns the FileID for the preprocessor predefines.
   FileID getPredefinesFileID() const { return PredefinesFileID; }
 
-  /// Returns the FileID for the predefines loaded from the PCH.
-  FileID getPCHPredefinesFileID() const {
-    assert(getLangOpts().Modules &&
-           "PCHPredefinedFileID is only set when modules is in effect!");
-    return PCHPredefinesFileID;
-  }
-
   /// \{
   /// Accessors for preprocessor callbacks.
   ///
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 2cd7888b0d192..e52f237fc5df2 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1563,9 +1563,7 @@ static void checkConfigMacro(Preprocessor &PP, StringRef 
ConfigMacro,
   for (auto *MD = LatestLocalMD; MD; MD = MD->getPrevious()) {
     // We only care about the predefines buffer.
     FileID FID = SourceMgr.getFileID(MD->getLocation());
-    if (FID.isInvalid())
-      continue;
-    if (FID != PP.getPredefinesFileID() && FID != PP.getPCHPredefinesFileID())
+    if (FID.isInvalid() || FID != PP.getPredefinesFileID())
       continue;
     if (auto *DMD = dyn_cast<DefMacroDirective>(MD))
       CmdLineDefinition = DMD->getMacroInfo();
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 09cf778938427..5efa4b5b3f872 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -125,35 +125,6 @@ void Preprocessor::setLoadedMacroDirective(IdentifierInfo 
*II,
   II->setHasMacroDefinition(true);
   if (!MD->isDefined() && !LeafModuleMacros.contains(II))
     II->setHasMacroDefinition(false);
-
-  if (getLangOpts().Modules) {
-    // When both modules and a PCH are used, we may run into the following
-    // situation:
-    //  - the PCH is compiled with macro definitions on the command line.
-    //  - the modules are compiled with the same set of macros on the command
-    // line.
-    // In this case, clang needs to know that some predefined macros exist
-    // over the command line transitively through the PCH and some are passed
-    // directly over the command line. The preprocessor stores
-    // PCHPredefinesFileID so later it is aware of macros defined transitively
-    // through the PCH's compilation.
-    auto MDLoc = MD->getLocation();
-
-    if (SourceMgr.isWrittenInCommandLineFile(MDLoc)) {
-      auto MDFileID = SourceMgr.getFileID(MDLoc);
-      if (PCHPredefinesFileID.isInvalid())
-        PCHPredefinesFileID = MDFileID;
-      else {
-        // The PCH and all the chain of headers it includes must be
-        // compiled with the exact same set of macros defined over the
-        // command line. No different macros should be defined over
-        // different command line invocations. This means that all the macros'
-        // source locations should have the same MDFileID.
-        assert(MDFileID == PCHPredefinesFileID &&
-               "PCHBuiltinFileID must be consistent!");
-      }
-    }
-  }
 }
 
 ModuleMacro *Preprocessor::addModuleMacro(Module *Mod, IdentifierInfo *II,
diff --git a/clang/test/Modules/Inputs/pch-config-macros/include/Mod1.h 
b/clang/test/Modules/Inputs/pch-config-macros/include/Mod1.h
deleted file mode 100644
index 3b8f33877dcd2..0000000000000
--- a/clang/test/Modules/Inputs/pch-config-macros/include/Mod1.h
+++ /dev/null
@@ -1,5 +0,0 @@
-#if CONFIG1
-int foo() { return 42; }
-#else
-int foo() { return 43; }
-#endif
diff --git 
a/clang/test/Modules/Inputs/pch-config-macros/include/module.modulemap 
b/clang/test/Modules/Inputs/pch-config-macros/include/module.modulemap
deleted file mode 100644
index 9d5f2e714ec88..0000000000000
--- a/clang/test/Modules/Inputs/pch-config-macros/include/module.modulemap
+++ /dev/null
@@ -1,4 +0,0 @@
-module Mod1 {
-  header "Mod1.h"
-  config_macros CONFIG1,CONFIG2
-}
diff --git a/clang/test/Modules/pch-config-macros.c 
b/clang/test/Modules/pch-config-macros.c
deleted file mode 100644
index 1cf7f60eea11a..0000000000000
--- a/clang/test/Modules/pch-config-macros.c
+++ /dev/null
@@ -1,48 +0,0 @@
-// RUN: rm -rf %t
-// RUN: split-file %s %t
-// RUN: cd %t
-
-// This test builds two PCHs. bridging.h.pch depends on h1.h.pch.
-// Then the test uses bridiging.h.pch in a source file that imports
-// a module with config macros.
-// This is a normal use case and no warnings should be issued.
-// RUN: %clang_cc1 -fmodules \
-// RUN:   
-fmodule-map-file=%S/Inputs/pch-config-macros/include/module.modulemap \
-// RUN:   -fmodules-cache-path=%t/cache -I %S/Inputs/pch-config-macros/include 
\
-// RUN:   h1.h -emit-pch -o h1.h.pch -DCONFIG1 -DCONFIG2
-// RUN: %clang_cc1 -fmodules \
-// RUN:   
-fmodule-map-file=%S/Inputs/pch-config-macros/include/module.modulemap \
-// RUN:   -fmodules-cache-path=%t/cache -I %S/Inputs/pch-config-macros/include 
\
-// RUN:   -include-pch h1.h.pch bridging.h -emit-pch -o bridging.h.pch \
-// RUN:   -DCONFIG1 -DCONFIG2
-// RUN: %clang_cc1 -fmodules \
-// RUN:   
-fmodule-map-file=%S/Inputs/pch-config-macros/include/module.modulemap \
-// RUN:   -fmodules-cache-path=%t/cache -I %S/Inputs/pch-config-macros/include 
\
-// RUN:   -emit-obj -o main.o main.c -include-pch bridging.h.pch \
-// RUN:   -DCONFIG1 -DCONFIG2 -verify
-
-//--- h1.h
-#if CONFIG1
-int bar1() { return 42; }
-#else
-int bar2() { return 43; }
-#endif
-
-//--- bridging.h
-#if CONFIG1
-int bar() { return bar1(); }
-#else
-int bar() { return bar2(); }
-#endif
-
-#if CONFIG2
-int baz() { return 77; }
-#endif
-
-//--- main.c
-#include "Mod1.h"
-// expected-no-diagnostics
-
-int main_func() {
-    return foo() + bar(); 
-}

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

Reply via email to