diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-07-15 12:45:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-15 12:45:09 -0700 |
commit | c592b61fc82c79366216ae12b25b0130359b0a26 (patch) | |
tree | 66b671ae5fdaaf321a94a9378b1af3b957586060 /clang/lib/Frontend/InitPreprocessor.cpp | |
parent | fccae859bc949ba390184614e07234267a734b86 (diff) | |
download | llvm-c592b61fc82c79366216ae12b25b0130359b0a26.zip llvm-c592b61fc82c79366216ae12b25b0130359b0a26.tar.gz llvm-c592b61fc82c79366216ae12b25b0130359b0a26.tar.bz2 |
[clang][modules] Serialize `CodeGenOptions` (#146422)
Some `LangOptions` duplicate their `CodeGenOptions` counterparts. My
understanding is that this was done solely because some infrastructure
(like preprocessor initialization, serialization, module compatibility
checks, etc.) were only possible/convenient for `LangOptions`. This PR
implements the missing support for `CodeGenOptions`, which makes it
possible to remove some duplicate `LangOptions` fields and simplify the
logic. Motivated by https://github.com/llvm/llvm-project/pull/146342.
Diffstat (limited to 'clang/lib/Frontend/InitPreprocessor.cpp')
-rw-r--r-- | clang/lib/Frontend/InitPreprocessor.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 34fb825..136bc55 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -862,6 +862,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, const LangOptions &LangOpts, const FrontendOptions &FEOpts, const PreprocessorOptions &PPOpts, + const CodeGenOptions &CGOpts, MacroBuilder &Builder) { // Compiler version introspection macros. Builder.defineMacro("__llvm__"); // LLVM Backend @@ -1070,9 +1071,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI, Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-16\""); } - if (LangOpts.Optimize) + if (CGOpts.OptimizationLevel != 0) Builder.defineMacro("__OPTIMIZE__"); - if (LangOpts.OptimizeSize) + if (CGOpts.OptimizeSize != 0) Builder.defineMacro("__OPTIMIZE_SIZE__"); if (LangOpts.FastMath) @@ -1393,7 +1394,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, if (LangOpts.GNUCVersion) addLockFreeMacros("__GCC_ATOMIC_"); - if (LangOpts.NoInlineDefine) + if (CGOpts.getInlining() == CodeGenOptions::OnlyAlwaysInlining) Builder.defineMacro("__NO_INLINE__"); if (unsigned PICLevel = LangOpts.PICLevel) { @@ -1572,10 +1573,11 @@ void clang::InitializePreprocessor(Preprocessor &PP, // macros. This is not the right way to handle this. if ((LangOpts.CUDA || LangOpts.isTargetDevice()) && PP.getAuxTargetInfo()) InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts, - PP.getPreprocessorOpts(), Builder); + PP.getPreprocessorOpts(), CodeGenOpts, + Builder); InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, - PP.getPreprocessorOpts(), Builder); + PP.getPreprocessorOpts(), CodeGenOpts, Builder); // Install definitions to make Objective-C++ ARC work well with various // C++ Standard Library implementations. |