[clang] [Clang] ASTUnit should use the CompilerInstance's CodeGenOptions (PR #195338)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 4 10:00:47 PDT 2026


================
@@ -1679,6 +1679,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
   // Create the AST unit.
   std::unique_ptr<ASTUnit> AST(new ASTUnit(false));
   ConfigureDiags(Diags, *AST, CaptureDiagnostics);
+  *AST->CodeGenOpts = CI->getCodeGenOpts();
----------------
Sirraide wrote:

Hmm, no idea candidly; all I know is I tried serialising an `ASTUnit` and passing the result to another `ASTUnit` as a pch, which resulted in an error during deserialisation because the `CodeGenOpts` were different (even though I created both `ASTUnit`s in the same process). After I applied this fixed it worked.

So far I’ve also been able to find 3 different places in the `ASTUnit` code where we do `std::make_unique<CodeGenOptions>()`, so I feel like to some extent the answer is that this part of the code base is just a bit of a mess and I’m not sure anyone is actually using any of these fields (iirc the `CodeGenOpts` of the `ASTUnit` didn’t even have a getter until I added one not to long ago...)

https://github.com/llvm/llvm-project/pull/195338


More information about the cfe-commits mailing list