================
@@ -125,6 +125,38 @@ 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();
+
+    // The PCH loads the command line macros into the <built-in> buffer.
+    // This is not the same as SourceMgr.isWrittenInBuiltinFile(MDLoc),
+    // since we are not looking at the Presumed location.
+    if (SourceMgr.getBufferName(MDLoc) == "<built-in>") {
----------------
ian-twilightcoder wrote:

Is there really not a better way to check this than the buffer name? This seems 
fragile.

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

Reply via email to