Skip to content

Commit a8be55d

Browse files
committed
fix abort case
Created using spr 1.3.7
1 parent afe3a26 commit a8be55d

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,17 +3791,20 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
37913791
bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime;
37923792
bool HandlerPreserveAllRegs =
37933793
CGF.CGM.getCodeGenOpts().SanitizeHandlerPreserveAllRegs;
3794+
bool UsePreserveFn = false;
37943795
const SanitizerHandlerInfo &CheckInfo = SanitizerHandlers[CheckHandler];
37953796
const StringRef CheckName = CheckInfo.Name;
37963797
std::string FnName = "__ubsan_handle_" + CheckName.str();
37973798
if (CheckInfo.Version && !MinimalRuntime)
37983799
FnName += "_v" + llvm::utostr(CheckInfo.Version);
37993800
if (MinimalRuntime)
38003801
FnName += "_minimal";
3801-
if (NeedsAbortSuffix)
3802+
if (NeedsAbortSuffix) {
38023803
FnName += "_abort";
3803-
else if (MinimalRuntime && HandlerPreserveAllRegs)
3804+
} else if (MinimalRuntime && HandlerPreserveAllRegs) {
38043805
FnName += "_preserve";
3806+
UsePreserveFn = true;
3807+
}
38053808
bool MayReturn =
38063809
!IsFatal || RecoverKind == CheckRecoverableKind::AlwaysRecoverable;
38073810

@@ -3822,7 +3825,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
38223825
(CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr<OptimizeNoneAttr>());
38233826
if (NoMerge)
38243827
HandlerCall->addFnAttr(llvm::Attribute::NoMerge);
3825-
if (MinimalRuntime && HandlerPreserveAllRegs) {
3828+
if (UsePreserveFn) {
38263829
// N.B. there is also a clang::CallingConv which is not what we want here.
38273830
HandlerCall->setCallingConv(llvm::CallingConv::PreserveAll);
38283831
}

clang/test/CodeGen/cfi-icall-trap-recover-runtime.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
// RUN: %clang_cc1 -fsanitize=cfi-icall -fno-sanitize-trap=cfi-icall -fsanitize-recover=cfi-icall -fsanitize-minimal-runtime -fsanitize-handler-preserve-all-regs -flto -fvisibility=hidden -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=PRESERVE_MIN %s
1313

14+
// RUN: %clang_cc1 -fsanitize=cfi-icall -fno-sanitize-trap=cfi-icall -fsanitize-minimal-runtime -fsanitize-handler-preserve-all-regs -flto -fvisibility=hidden -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=PRESERVE_ABORT_MIN %s
15+
1416

1517
// TRAP-LABEL: define hidden void @f(
1618
// TRAP-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
@@ -42,6 +44,11 @@
4244
// PRESERVE_MIN-NEXT: [[ENTRY:.*:]]
4345
// PRESERVE_MIN-NEXT: ret void
4446
//
47+
// PRESERVE_ABORT_MIN-LABEL: define hidden void @f(
48+
// PRESERVE_ABORT_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
49+
// PRESERVE_ABORT_MIN-NEXT: [[ENTRY:.*:]]
50+
// PRESERVE_ABORT_MIN-NEXT: ret void
51+
//
4552
void f() {
4653
}
4754

@@ -175,6 +182,27 @@ void xf();
175182
// PRESERVE_MIN-NEXT: call void (...) [[TMP2]]()
176183
// PRESERVE_MIN-NEXT: ret void
177184
//
185+
// PRESERVE_ABORT_MIN-LABEL: define hidden void @g(
186+
// PRESERVE_ABORT_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
187+
// PRESERVE_ABORT_MIN-NEXT: [[ENTRY:.*:]]
188+
// PRESERVE_ABORT_MIN-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
189+
// PRESERVE_ABORT_MIN-NEXT: [[FP:%.*]] = alloca ptr, align 8
190+
// PRESERVE_ABORT_MIN-NEXT: store i32 [[B]], ptr [[B_ADDR]], align 4
191+
// PRESERVE_ABORT_MIN-NEXT: [[TMP0:%.*]] = load i32, ptr [[B_ADDR]], align 4
192+
// PRESERVE_ABORT_MIN-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[TMP0]], 0
193+
// PRESERVE_ABORT_MIN-NEXT: [[TMP1:%.*]] = zext i1 [[TOBOOL]] to i64
194+
// PRESERVE_ABORT_MIN-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], ptr @f, ptr @xf
195+
// PRESERVE_ABORT_MIN-NEXT: store ptr [[COND]], ptr [[FP]], align 8
196+
// PRESERVE_ABORT_MIN-NEXT: [[TMP2:%.*]] = load ptr, ptr [[FP]], align 8
197+
// PRESERVE_ABORT_MIN-NEXT: [[TMP3:%.*]] = call i1 @llvm.type.test(ptr [[TMP2]], metadata !"_ZTSFvE"), !nosanitize [[META10:![0-9]+]]
198+
// PRESERVE_ABORT_MIN-NEXT: br i1 [[TMP3]], label %[[CONT:.*]], label %[[HANDLER_CFI_CHECK_FAIL:.*]], !prof [[PROF11:![0-9]+]], !nosanitize [[META10]]
199+
// PRESERVE_ABORT_MIN: [[HANDLER_CFI_CHECK_FAIL]]:
200+
// PRESERVE_ABORT_MIN-NEXT: call void @__ubsan_handle_cfi_check_fail_minimal_abort() #[[ATTR4:[0-9]+]], !nosanitize [[META10]]
201+
// PRESERVE_ABORT_MIN-NEXT: unreachable, !nosanitize [[META10]]
202+
// PRESERVE_ABORT_MIN: [[CONT]]:
203+
// PRESERVE_ABORT_MIN-NEXT: call void (...) [[TMP2]]()
204+
// PRESERVE_ABORT_MIN-NEXT: ret void
205+
//
178206
void g(int b) {
179207
void (*fp)() = b ? f : xf;
180208
fp();
@@ -222,3 +250,10 @@ void g(int b) {
222250
// PRESERVE_MIN: [[META10]] = !{}
223251
// PRESERVE_MIN: [[PROF11]] = !{!"branch_weights", i32 1048575, i32 1}
224252
//.
253+
// PRESERVE_ABORT_MIN: [[META6]] = !{i64 0, !"_ZTSFvE"}
254+
// PRESERVE_ABORT_MIN: [[META7]] = !{i64 0, !"_ZTSFvE.generalized"}
255+
// PRESERVE_ABORT_MIN: [[META8]] = !{i64 0, !"_ZTSFviE"}
256+
// PRESERVE_ABORT_MIN: [[META9]] = !{i64 0, !"_ZTSFviE.generalized"}
257+
// PRESERVE_ABORT_MIN: [[META10]] = !{}
258+
// PRESERVE_ABORT_MIN: [[PROF11]] = !{!"branch_weights", i32 1048575, i32 1}
259+
//.

clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
// RUN: %clang_cc1 -fsanitize=cfi-vcall -fno-sanitize-trap=cfi-vcall -fsanitize-recover=cfi-vcall -fsanitize-minimal-runtime -flto -fvisibility=hidden -triple x86_64-unknown-linux -fwhole-program-vtables -fsanitize-handler-preserve-all-regs -emit-llvm -o - %s | FileCheck --check-prefix=PRESERVE_MIN %s
1313

14+
// RUN: %clang_cc1 -fsanitize=cfi-vcall -fno-sanitize-trap=cfi-vcall -fsanitize-minimal-runtime -flto -fvisibility=hidden -triple x86_64-unknown-linux -fwhole-program-vtables -fsanitize-handler-preserve-all-regs -emit-llvm -o - %s | FileCheck --check-prefix=PRESERVE_ABORT_MIN %s
15+
16+
1417
struct S1 {
1518
virtual void f();
1619
};
@@ -132,6 +135,25 @@ struct S1 {
132135
// PRESERVE_MIN-NEXT: call void [[TMP3]](ptr noundef nonnull align 8 dereferenceable(8) [[TMP0]])
133136
// PRESERVE_MIN-NEXT: ret void
134137
//
138+
// PRESERVE_ABORT_MIN-LABEL: define hidden void @_Z3s1fP2S1(
139+
// PRESERVE_ABORT_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
140+
// PRESERVE_ABORT_MIN-NEXT: [[ENTRY:.*:]]
141+
// PRESERVE_ABORT_MIN-NEXT: [[S1_ADDR:%.*]] = alloca ptr, align 8
142+
// PRESERVE_ABORT_MIN-NEXT: store ptr [[S1]], ptr [[S1_ADDR]], align 8
143+
// PRESERVE_ABORT_MIN-NEXT: [[TMP0:%.*]] = load ptr, ptr [[S1_ADDR]], align 8
144+
// PRESERVE_ABORT_MIN-NEXT: [[VTABLE:%.*]] = load ptr, ptr [[TMP0]], align 8
145+
// PRESERVE_ABORT_MIN-NEXT: [[TMP1:%.*]] = call i1 @llvm.type.test(ptr [[VTABLE]], metadata !"_ZTS2S1"), !nosanitize [[META5:![0-9]+]]
146+
// PRESERVE_ABORT_MIN-NEXT: [[TMP2:%.*]] = call i1 @llvm.type.test(ptr [[VTABLE]], metadata !"all-vtables"), !nosanitize [[META5]]
147+
// PRESERVE_ABORT_MIN-NEXT: br i1 [[TMP1]], label %[[CONT:.*]], label %[[HANDLER_CFI_CHECK_FAIL:.*]], !prof [[PROF6:![0-9]+]], !nosanitize [[META5]]
148+
// PRESERVE_ABORT_MIN: [[HANDLER_CFI_CHECK_FAIL]]:
149+
// PRESERVE_ABORT_MIN-NEXT: call void @__ubsan_handle_cfi_check_fail_minimal_abort() #[[ATTR3:[0-9]+]], !nosanitize [[META5]]
150+
// PRESERVE_ABORT_MIN-NEXT: unreachable, !nosanitize [[META5]]
151+
// PRESERVE_ABORT_MIN: [[CONT]]:
152+
// PRESERVE_ABORT_MIN-NEXT: [[VFN:%.*]] = getelementptr inbounds ptr, ptr [[VTABLE]], i64 0
153+
// PRESERVE_ABORT_MIN-NEXT: [[TMP3:%.*]] = load ptr, ptr [[VFN]], align 8
154+
// PRESERVE_ABORT_MIN-NEXT: call void [[TMP3]](ptr noundef nonnull align 8 dereferenceable(8) [[TMP0]])
155+
// PRESERVE_ABORT_MIN-NEXT: ret void
156+
//
135157
void s1f(S1 *s1) {
136158
s1->f();
137159
}
@@ -154,3 +176,6 @@ void s1f(S1 *s1) {
154176
// PRESERVE_MIN: [[META5]] = !{}
155177
// PRESERVE_MIN: [[PROF6]] = !{!"branch_weights", i32 1048575, i32 1}
156178
//.
179+
// PRESERVE_ABORT_MIN: [[META5]] = !{}
180+
// PRESERVE_ABORT_MIN: [[PROF6]] = !{!"branch_weights", i32 1048575, i32 1}
181+
//.

0 commit comments

Comments
 (0)