Skip to content

Commit 2cf04e5

Browse files
committed
[clang] Always select ud2 instruction for trap
Patch selects ud2 (undefined instruction) for LLVM IR unreachable under X86. The guarantees that a noreturn function never returns.
1 parent d989c24 commit 2cf04e5

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
470470
Options.JMCInstrument = CodeGenOpts.JMCInstrument;
471471
Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
472472

473+
if (LangOpts.Kernel)
474+
Options.TrapUnreachable = true;
475+
473476
switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
474477
case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
475478
Options.SwiftAsyncFramePointer =
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// REQUIRES: x86-registered-target
2+
// RUN: %clang_cc1 -fms-kernel -fms-extensions -triple x86_64-windows-msvc -O2 -S %s -o - | FileCheck %s
3+
4+
// CHECK-LABEL: my_noreturn_func:
5+
// CHECK: callq bugcheck
6+
// CHECK-NEXT: ud2
7+
8+
// CHECK-LABEL: my_noreturn_func2:
9+
// CHECK: movl $0, (%rax)
10+
// CHECK-NEXT: ud2
11+
12+
void bugcheck(int code);
13+
14+
extern long volatile *gtrap;
15+
16+
__declspec(noreturn) void my_noreturn_func(void) {
17+
bugcheck(0x42);
18+
}
19+
20+
21+
__declspec(noreturn) void my_noreturn_func2(void) {
22+
*gtrap = 0;
23+
}
24+

0 commit comments

Comments
 (0)