================
@@ -922,6 +922,16 @@ static bool checkPreprocessorOptions(
   }
 
   // Compute the #include and #include_macros lines we need.
+  for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) {
+    StringRef File = ExistingPPOpts.MacroIncludes[I];
+    if (llvm::is_contained(PPOpts.MacroIncludes, File))
+      continue;
+
+    SuggestedPredefines += "#__include_macros \"";
+    SuggestedPredefines += File;
+    SuggestedPredefines += "\"\n##\n";
+  }
----------------
yronglin wrote:

Good question! The `ASTReader` change is unrelated to module detection. It 
preserves the correct implicit-input order after loading a PCH.

Normal preprocessing order is:
```
-imacros
-include-pch
-include
```

After successfully loading a PCH, `ASTReader` replaces `Predefines` with 
`SuggestedPredefines`. Previously, it generated the remaining inputs in the 
opposite order:
```
-include
-imacros
```

Eg:

```
-imacros macros.h -include-pch pch.pch -include first.h
```

If macros.h defines a macro used by first.h, the old order processes first.h 
before that macro is defined.

The change only swaps the two loops so SuggestedPredefines matches normal 
preprocessing order:
```
-imacros
-include
```
This is required when implicit PCH, -imacros, and -include are used together. 
It also corrects the ordering for ordinary translation units, not only module 
units.

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

Reply via email to