llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: eleviant

<details>
<summary>Changes</summary>

Patch lowers unreachable to the trap (ud2) when `-fms-kernel` is provided to 
ensure kernel trap handler is invoked in case something goes wrong, instead of 
falling through.

---
Full diff: https://github.com/llvm/llvm-project/pull/196550.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+3) 
- (added) clang/test/CodeGen/MSKernel/noreturn.c (+13) 


``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a46a25c4492f2..6b2a81f100d7a 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -477,6 +477,9 @@ static bool initTargetOptions(const CompilerInstance &CI,
   Options.VecLib =
       convertDriverVectorLibraryToVectorLibrary(CodeGenOpts.getVecLib());
 
+  if (LangOpts.Kernel)
+    Options.TrapUnreachable = true;
+
   switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
   case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
     Options.SwiftAsyncFramePointer =
diff --git a/clang/test/CodeGen/MSKernel/noreturn.c 
b/clang/test/CodeGen/MSKernel/noreturn.c
new file mode 100644
index 0000000000000..4a5eae3472b48
--- /dev/null
+++ b/clang/test/CodeGen/MSKernel/noreturn.c
@@ -0,0 +1,13 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -fms-kernel -fms-extensions -triple x86_64-windows-msvc -O2 
-S %s -o - | FileCheck %s
+
+// CHECK-LABEL: my_noreturn_func:
+// CHECK:       movl $0, (%rax)
+// CHECK-NEXT:  ud2
+
+extern long volatile *gtrap;
+
+__declspec(noreturn) void my_noreturn_func(void) {
+    *gtrap = 0;
+}
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/196550
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to