[PATCH] D126719: [clang-cl] Add support for /kernel
Stephen Long via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 31 13:50:40 PDT 2022
steplong created this revision.
Herald added a project: All.
steplong requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.
MSVC defines _KERNEL_MODE when /kernel is passed.
Also, /kernel disables RTTI and C++ exception handling.
https://docs.microsoft.com/en-us/cpp/build/reference/kernel-create-kernel-mode-binary?view=msvc-170
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D126719
Files:
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/OSTargets.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-zc.cpp
Index: clang/test/Driver/cl-zc.cpp
===================================================================
--- clang/test/Driver/cl-zc.cpp
+++ 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
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ 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
Index: clang/lib/Basic/Targets/OSTargets.cpp
===================================================================
--- clang/lib/Basic/Targets/OSTargets.cpp
+++ 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__");
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2178,6 +2178,8 @@
NormalizedValues<["PPTMK_FullGeneralitySingleInheritance", "PPTMK_FullGeneralityMultipleInheritance",
"PPTMK_FullGeneralityVirtualInheritance"]>,
MarshallingInfoEnum<LangOpts<"MSPointerToMemberRepresentationMethod">, "PPTMK_BestCase">;
+def fms_kernel : Flag<["-"], "fms-kernel">, Group<f_Group>, Flags<[CC1Option, NoDriverOption]>,
+ MarshallingInfoFlag<LangOpts<"Kernel">>;
// __declspec is enabled by default for the PS4 by the driver, and also
// enabled for Microsoft Extensions or Borland Extensions, here.
//
Index: clang/include/clang/Basic/LangOptions.def
===================================================================
--- clang/include/clang/Basic/LangOptions.def
+++ 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")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126719.433175.patch
Type: text/x-patch
Size: 3686 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220531/41ce5f75/attachment-0001.bin>
More information about the cfe-commits
mailing list