Skip to content

Commit c65b0cd

Browse files
efriedma-quictstellar
authored andcommitted
[GlobalIsel] Fix fallback if stack protector isn't supported.
When GlobalISel fails, we need to report the error, and we need to set the FailedISel property. We skipped those steps if stack protector insertion failed, which led to a very strange miscompile. Differential Revision: https://reviews.llvm.org/D125584 (cherry picked from commit 96c2a0c)
1 parent cda300e commit c65b0cd

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3469,8 +3469,13 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
34693469
return false;
34703470
}
34713471

3472-
if (!finalizeBasicBlock(*BB, MBB))
3472+
if (!finalizeBasicBlock(*BB, MBB)) {
3473+
OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
3474+
BB->getTerminator()->getDebugLoc(), BB);
3475+
R << "unable to translate basic block";
3476+
reportTranslationError(*MF, *TPC, *ORE, R);
34733477
return false;
3478+
}
34743479
}
34753480
#ifndef NDEBUG
34763481
WrapperObserver.removeObserver(&Verifier);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -verify-machineinstrs -mtriple=aarch64-pc-windows-msvc %s -o - -global-isel -global-isel-abort=0 | FileCheck %s
3+
4+
; Make sure we correctly fall back to SelectionDAG isel for unsupported stack protectors.
5+
6+
define void @caller() sspreq {
7+
; CHECK-LABEL: caller:
8+
; CHECK: .seh_proc caller
9+
; CHECK-NEXT: // %bb.0: // %entry
10+
; CHECK-NEXT: sub sp, sp, #32
11+
; CHECK-NEXT: .seh_stackalloc 32
12+
; CHECK-NEXT: str x30, [sp, #16] // 8-byte Folded Spill
13+
; CHECK-NEXT: .seh_save_reg x30, 16
14+
; CHECK-NEXT: .seh_endprologue
15+
; CHECK-NEXT: adrp x8, __security_cookie
16+
; CHECK-NEXT: add x0, sp, #4
17+
; CHECK-NEXT: ldr x8, [x8, :lo12:__security_cookie]
18+
; CHECK-NEXT: str x8, [sp, #8]
19+
; CHECK-NEXT: bl callee
20+
; CHECK-NEXT: ldr x0, [sp, #8]
21+
; CHECK-NEXT: bl __security_check_cookie
22+
; CHECK-NEXT: .seh_startepilogue
23+
; CHECK-NEXT: ldr x30, [sp, #16] // 8-byte Folded Reload
24+
; CHECK-NEXT: .seh_save_reg x30, 16
25+
; CHECK-NEXT: add sp, sp, #32
26+
; CHECK-NEXT: .seh_stackalloc 32
27+
; CHECK-NEXT: .seh_endepilogue
28+
; CHECK-NEXT: ret
29+
; CHECK-NEXT: .seh_endfunclet
30+
; CHECK-NEXT: .seh_endproc
31+
entry:
32+
%x = alloca i32, align 4
33+
%0 = bitcast i32* %x to i8*
34+
call void @callee(i32* nonnull %x)
35+
ret void
36+
}
37+
38+
declare void @callee(i32*)

0 commit comments

Comments
 (0)