diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -88,6 +88,7 @@ LANGOPT(C17 , 1, 0, "C17") LANGOPT(C2x , 1, 0, "C2x") LANGOPT(MSVCCompat , 1, 0, "Microsoft Visual C++ full compatibility mode") +LANGOPT(Kernel , 1, 0, "Kernel mode") LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions") LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks") LANGOPT(Borland , 1, 0, "Borland extensions") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2178,6 +2178,8 @@ NormalizedValues<["PPTMK_FullGeneralitySingleInheritance", "PPTMK_FullGeneralityMultipleInheritance", "PPTMK_FullGeneralityVirtualInheritance"]>, MarshallingInfoEnum, "PPTMK_BestCase">; +def fms_kernel : Flag<["-"], "fms-kernel">, Group, Flags<[CC1Option, NoDriverOption]>, + MarshallingInfoFlag>; // __declspec is enabled by default for the PS4 by the driver, and also // enabled for Microsoft Extensions or Borland Extensions, here. // diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp --- a/clang/lib/Basic/Targets/OSTargets.cpp +++ b/clang/lib/Basic/Targets/OSTargets.cpp @@ -215,6 +215,9 @@ } } + if (Opts.Kernel) + Builder.defineMacro("_KERNEL_MODE"); + Builder.defineMacro("_INTEGRAL_MAX_BITS", "64"); Builder.defineMacro("__STDC_NO_THREADS__"); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7458,6 +7458,13 @@ EH.NoUnwindC = true; } + if (Args.hasFlag(options::OPT__SLASH_kernel, options::OPT__SLASH_kernel, + false)) { + EH.Synch = false; + EH.NoUnwindC = false; + EH.Asynch = false; + } + return EH; } @@ -7602,6 +7609,11 @@ CmdArgs.push_back("-fno-wchar"); } + if (Args.hasFlag(options::OPT__SLASH_kernel, options::OPT__SLASH_kernel, + false)) { + CmdArgs.push_back("-fno-rtti"); + } + Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg); Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb); if (MostGeneralArg && BestCaseArg) @@ -7671,6 +7683,9 @@ CmdArgs.push_back("msvc"); } + if (Args.hasArg(options::OPT__SLASH_kernel)) + CmdArgs.push_back("-fms-kernel"); + if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) { StringRef GuardArgs = A->getValue(); // The only valid options are "cf", "cf,nochecks", "cf-", "ehcont" and diff --git a/clang/test/Driver/cl-zc.cpp b/clang/test/Driver/cl-zc.cpp --- a/clang/test/Driver/cl-zc.cpp +++ b/clang/test/Driver/cl-zc.cpp @@ -24,6 +24,9 @@ // RUN: %clang_cl /c /std:c++17 -### /Zc:alignedNew- -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-OFF %s // ALIGNED-NEW-OFF-NOT: "-faligned-allocation" +// RUN: %clang_cl /c -### /kernel -- %s 2>&1 | FileCheck -check-prefix=KERNEL %s +// KERNEL: "-fno-rtti" + // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=STRICTSTRINGS-DEFAULT %s // STRICTSTRINGS-DEFAULT-NOT: -Werror=c++11-compat-deprecated-writable-strings // RUN: %clang_cl /c -### /Zc:strictStrings -- %s 2>&1 | FileCheck -check-prefix=STRICTSTRINGS-ON %s