[llvm-branch-commits] [llvm] c65b0cd - [GlobalIsel] Fix fallback if stack protector isn't supported.

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed May 18 20:11:58 PDT 2022


Author: Eli Friedman
Date: 2022-05-18T20:09:32-07:00
New Revision: c65b0cd2421d722d3f2b1eb78dd91d758db5049a

URL: https://github.com/llvm/llvm-project/commit/c65b0cd2421d722d3f2b1eb78dd91d758db5049a
DIFF: https://github.com/llvm/llvm-project/commit/c65b0cd2421d722d3f2b1eb78dd91d758db5049a.diff

LOG: [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)

Added: 
    llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-protector-windows.ll

Modified: 
    llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 6d415c9c7f90c..847df84afba6c 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 0000000000000..7ce80afb8c7f8
--- /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*)


        


More information about the llvm-branch-commits mailing list