From 6e1f19168bca7e3bd4eefda50ba03eac8441dbbf Mon Sep 17 00:00:00 2001 From: Zixu Wang <9819235+zixu-w@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:40:58 -0800 Subject: [clang][PP] Add extension to predefine target OS macros (#74676) Add an extension feature `define-target-os-macros` that enables clang to provide definitions of common TARGET_OS_* conditional macros. The extension is enabled in the Darwin toolchain driver. --- clang/lib/Frontend/CompilerInvocation.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 56de0f7..b33bdad 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4365,6 +4365,9 @@ static void GeneratePreprocessorArgs(const PreprocessorOptions &Opts, if (Opts.SourceDateEpoch) GenerateArg(Consumer, OPT_source_date_epoch, Twine(*Opts.SourceDateEpoch)); + if (Opts.DefineTargetOSMacros) + GenerateArg(Consumer, OPT_fdefine_target_os_macros); + // Don't handle LexEditorPlaceholders. It is implied by the action that is // generated elsewhere. } @@ -4463,6 +4466,10 @@ static bool ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, if (isStrictlyPreprocessorAction(Action)) Opts.LexEditorPlaceholders = false; + Opts.DefineTargetOSMacros = + Args.hasFlag(OPT_fdefine_target_os_macros, + OPT_fno_define_target_os_macros, Opts.DefineTargetOSMacros); + return Diags.getNumErrors() == NumErrorsBefore; } -- cgit v1.1