summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <efriedma@quicinc.com>2022-05-13 13:36:16 -0700
committerTom Stellard <tstellar@redhat.com>2022-05-18 20:09:32 -0700
commitc65b0cd2421d722d3f2b1eb78dd91d758db5049a (patch)
tree78a02384d1f12cf2a255c0d84f1635ace742a093
parentcda300eab8ddb9fb90859014ec3721567fec727c (diff)
downloadllvm-c65b0cd2421d722d3f2b1eb78dd91d758db5049a.tar.gz
[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 96c2a0c9fff24803be14bfaa579e4f230763d3cc)
-rw-r--r--llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp7
-rw-r--r--llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-protector-windows.ll38
2 files changed, 44 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 6d415c9c7f90..847df84afba6 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -3469,8 +3469,13 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
return false;
}
- if (!finalizeBasicBlock(*BB, MBB))
+ if (!finalizeBasicBlock(*BB, MBB)) {
+ OptimizationRemarkMissed R("gisel-irtranslator", "GISelFailure",
+ BB->getTerminator()->getDebugLoc(), BB);
+ R << "unable to translate basic block";
+ reportTranslationError(*MF, *TPC, *ORE, R);
return false;
+ }
}
#ifndef NDEBUG
WrapperObserver.removeObserver(&Verifier);
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-protector-windows.ll b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-protector-windows.ll
new file mode 100644
index 000000000000..7ce80afb8c7f
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-protector-windows.ll
@@ -0,0 +1,38 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=aarch64-pc-windows-msvc %s -o - -global-isel -global-isel-abort=0 | FileCheck %s
+
+; Make sure we correctly fall back to SelectionDAG isel for unsupported stack protectors.
+
+define void @caller() sspreq {
+; CHECK-LABEL: caller:
+; CHECK: .seh_proc caller
+; CHECK-NEXT: // %bb.0: // %entry
+; CHECK-NEXT: sub sp, sp, #32
+; CHECK-NEXT: .seh_stackalloc 32
+; CHECK-NEXT: str x30, [sp, #16] // 8-byte Folded Spill
+; CHECK-NEXT: .seh_save_reg x30, 16
+; CHECK-NEXT: .seh_endprologue
+; CHECK-NEXT: adrp x8, __security_cookie
+; CHECK-NEXT: add x0, sp, #4
+; CHECK-NEXT: ldr x8, [x8, :lo12:__security_cookie]
+; CHECK-NEXT: str x8, [sp, #8]
+; CHECK-NEXT: bl callee
+; CHECK-NEXT: ldr x0, [sp, #8]
+; CHECK-NEXT: bl __security_check_cookie
+; CHECK-NEXT: .seh_startepilogue
+; CHECK-NEXT: ldr x30, [sp, #16] // 8-byte Folded Reload
+; CHECK-NEXT: .seh_save_reg x30, 16
+; CHECK-NEXT: add sp, sp, #32
+; CHECK-NEXT: .seh_stackalloc 32
+; CHECK-NEXT: .seh_endepilogue
+; CHECK-NEXT: ret
+; CHECK-NEXT: .seh_endfunclet
+; CHECK-NEXT: .seh_endproc
+entry:
+ %x = alloca i32, align 4
+ %0 = bitcast i32* %x to i8*
+ call void @callee(i32* nonnull %x)
+ ret void
+}
+
+declare void @callee(i32*)