diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2f7bd9e552e165..3722192c7eee48 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5207,12 +5207,13 @@ def fdefault_calling_conv_EQ : Joined<["-"], "fdefault-calling-conv=">, NormalizedValuesScope<"LangOptions">, NormalizedValues<["DCC_CDecl", "DCC_FastCall", "DCC_StdCall", "DCC_VectorCall", "DCC_RegCall"]>, MarshallingInfoString, "DCC_None">, AutoNormalizeEnum; + +// These options cannot be marshalled, because they are used to set up the LangOptions defaults. def finclude_default_header : Flag<["-"], "finclude-default-header">, - HelpText<"Include default header file for OpenCL">, - MarshallingInfoFlag>; + HelpText<"Include default header file for OpenCL">; def fdeclare_opencl_builtins : Flag<["-"], "fdeclare-opencl-builtins">, - HelpText<"Add OpenCL builtin function declarations (experimental)">, - MarshallingInfoFlag>; + HelpText<"Add OpenCL builtin function declarations (experimental)">; + def fpreserve_vec3_type : Flag<["-"], "fpreserve-vec3-type">, HelpText<"Preserve 3-component vector type">, MarshallingInfoFlag>; diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 37d7f6f3f0fac8..c85b0f9d65cfab 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -491,6 +491,11 @@ static unsigned getOptimizationLevelSize(ArgList &Args) { return 0; } +static std::string GetOptName(llvm::opt::OptSpecifier OptSpecifier) { + static const OptTable &OptTable = getDriverOptTable(); + return OptTable.getOption(OptSpecifier).getPrefixedName(); +} + static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group, OptSpecifier GroupWithValue, std::vector &Diagnostics) { @@ -2137,6 +2142,15 @@ static const StringRef GetInputKindName(InputKind IK) { llvm_unreachable("unknown input language"); } +static void GenerateLangArgs(const LangOptions &Opts, + SmallVectorImpl &Args, + CompilerInvocation::StringAllocator SA) { + if (Opts.IncludeDefaultHeader) + Args.push_back(SA(GetOptName(OPT_finclude_default_header))); + if (Opts.DeclareOpenCLBuiltins) + Args.push_back(SA(GetOptName(OPT_fdeclare_opencl_builtins))); +} + static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, const llvm::Triple &T, std::vector &Includes, @@ -2212,6 +2226,10 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device); + // These need to be parsed now. They are used to set OpenCL defaults. + Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header); + Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins); + CompilerInvocation::setLangDefaults(Opts, IK, T, Includes, LangStd); // -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0. @@ -3163,6 +3181,8 @@ void CompilerInvocation::generateCC1CommandLine( #undef DIAG_OPTION_WITH_MARSHALLING #undef OPTION_WITH_MARSHALLING #undef GENERATE_OPTION_WITH_MARSHALLING + + GenerateLangArgs(*LangOpts, Args, SA); } IntrusiveRefCntPtr