[llvm] 63150f4 - Revert "Enhance stack protector for calling no return function"
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 2 04:58:57 PST 2022
Author: Florian Hahn
Date: 2022-12-02T12:58:46Z
New Revision: 63150f463934bcf3a6d2945efea478d2e3250db1
URL: https://github.com/llvm/llvm-project/commit/63150f463934bcf3a6d2945efea478d2e3250db1
DIFF: https://github.com/llvm/llvm-project/commit/63150f463934bcf3a6d2945efea478d2e3250db1.diff
LOG: Revert "Enhance stack protector for calling no return function"
This reverts commit 416e8c6ad529c57f21f46c6f52ded96d3ed239fb.
This commit causes a test failure with expensive checks due to a DT
verification failure. Revert to bring bot back to green:
https://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-expensive/24249/testReport/junit/LLVM/CodeGen_X86/stack_protector_no_return_ll/
+ /Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-expensive/clang-build/bin/llc /Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-expensive/llvm-project/llvm/test/CodeGen/X86/stack-protector-no-return.ll -mtriple=x86_64-unknown-linux-gnu -o -
+ /Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-expensive/clang-build/bin/FileCheck /Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-expensive/llvm-project/llvm/test/CodeGen/X86/stack-protector-no-return.ll
DominatorTree is different than a freshly computed one!
Current:
=============================--------------------------------
Inorder Dominator Tree: DFSNumbers invalid: 0 slow queries.
[1] %entry {4294967295,4294967295} [0]
[2] %unreachable {4294967295,4294967295} [1]
[2] %lpad {4294967295,4294967295} [1]
[3] %invoke.cont {4294967295,4294967295} [2]
[4] %invoke.cont2 {4294967295,4294967295} [3]
[4] %SP_return3 {4294967295,4294967295} [3]
[4] %CallStackCheckFailBlk2 {4294967295,4294967295} [3]
[3] %lpad1 {4294967295,4294967295} [2]
[4] %eh.resume {4294967295,4294967295} [3]
[5] %SP_return6 {4294967295,4294967295} [4]
[5] %CallStackCheckFailBlk5 {4294967295,4294967295} [4]
[4] %terminate.lpad {4294967295,4294967295} [3]
[5] %SP_return9 {4294967295,4294967295} [4]
[5] %CallStackCheckFailBlk8 {4294967295,4294967295} [4]
[2] %SP_return {4294967295,4294967295} [1]
[2] %CallStackCheckFailBlk {4294967295,4294967295} [1]
Roots: %entry
Added:
Modified:
llvm/lib/CodeGen/StackProtector.cpp
llvm/test/CodeGen/X86/stack-protector-2.ll
llvm/test/CodeGen/X86/stack-protector-no-return.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp
index 2f0056f125ca6..f974bb67e440a 100644
--- a/llvm/lib/CodeGen/StackProtector.cpp
+++ b/llvm/lib/CodeGen/StackProtector.cpp
@@ -415,11 +415,11 @@ static Value *getStackGuard(const TargetLoweringBase *TLI, Module *M,
///
/// Returns true if the platform/triple supports the stackprotectorcreate pseudo
/// node.
-static bool CreatePrologue(Function *F, Module *M, Instruction *CheckLoc,
+static bool CreatePrologue(Function *F, Module *M, ReturnInst *RI,
const TargetLoweringBase *TLI, AllocaInst *&AI) {
bool SupportsSelectionDAGSP = false;
IRBuilder<> B(&F->getEntryBlock().front());
- PointerType *PtrTy = Type::getInt8PtrTy(CheckLoc->getContext());
+ PointerType *PtrTy = Type::getInt8PtrTy(RI->getContext());
AI = B.CreateAlloca(PtrTy, nullptr, "StackGuardSlot");
Value *GuardSlot = getStackGuard(TLI, M, B, &SupportsSelectionDAGSP);
@@ -444,27 +444,14 @@ bool StackProtector::InsertStackProtectors() {
AllocaInst *AI = nullptr; // Place on stack that stores the stack guard.
for (BasicBlock &BB : llvm::make_early_inc_range(*F)) {
- Instruction *CheckLoc = dyn_cast<ReturnInst>(BB.getTerminator());
- if (!CheckLoc) {
- for (auto &Inst : BB) {
- auto *CB = dyn_cast<CallBase>(&Inst);
- if (!CB)
- continue;
- if (!CB->doesNotReturn())
- continue;
- // Do stack check before non-return calls (e.g: __cxa_throw)
- CheckLoc = CB;
- break;
- }
- }
-
- if (!CheckLoc)
+ ReturnInst *RI = dyn_cast<ReturnInst>(BB.getTerminator());
+ if (!RI)
continue;
// Generate prologue instrumentation if not already generated.
if (!HasPrologue) {
HasPrologue = true;
- SupportsSelectionDAGSP &= CreatePrologue(F, M, CheckLoc, TLI, AI);
+ SupportsSelectionDAGSP &= CreatePrologue(F, M, RI, TLI, AI);
}
// SelectionDAG based code generation. Nothing else needs to be done here.
@@ -490,7 +477,8 @@ bool StackProtector::InsertStackProtectors() {
// verifier guarantees that a tail call is either directly before the
// return or with a single correct bitcast of the return value in between so
// we don't need to worry about many situations here.
- Instruction *Prev = CheckLoc->getPrevNonDebugInstruction();
+ Instruction *CheckLoc = RI;
+ Instruction *Prev = RI->getPrevNonDebugInstruction();
if (Prev && isa<CallInst>(Prev) && cast<CallInst>(Prev)->isTailCall())
CheckLoc = Prev;
else if (Prev) {
diff --git a/llvm/test/CodeGen/X86/stack-protector-2.ll b/llvm/test/CodeGen/X86/stack-protector-2.ll
index f2fc64ab0c866..c6971a59f813f 100644
--- a/llvm/test/CodeGen/X86/stack-protector-2.ll
+++ b/llvm/test/CodeGen/X86/stack-protector-2.ll
@@ -192,34 +192,4 @@ define dso_local void @bar_nossp(i64 %0) {
ret void
}
-; Check stack protect for noreturn call
-define dso_local i32 @foo_no_return(i32 %0) #1 {
-; CHECK-LABEL: @foo_no_return
-entry:
- %cmp = icmp sgt i32 %0, 4
- br i1 %cmp, label %if.then, label %if.end
-
-; CHECK: if.then: ; preds = %entry
-; CHECK-NEXT: %StackGuard1 = load volatile i8*, i8* addrspace(257)* inttoptr (i32 40 to i8* addrspace(257)*), align 8
-; CHECK-NEXT: %1 = load volatile i8*, i8** %StackGuardSlot, align 8
-; CHECK-NEXT: %2 = icmp eq i8* %StackGuard1, %1
-; CHECK-NEXT: br i1 %2, label %SP_return, label %CallStackCheckFailBlk
-; CHECK: SP_return: ; preds = %if.then
-; CHECK-NEXT: %call = call i32 @foo_no_return(i32 1)
-; CHECK-NEXT: br label %return
-; CHECK: if.end: ; preds = %entry
-; CHECK-NEXT: br label %return
-
-if.then: ; preds = %entry
- %call = call i32 @foo_no_return(i32 1)
- br label %return
-
-if.end: ; preds = %entry
- br label %return
-
-return: ; preds = %if.end, %if.then
- ret i32 0
-}
-
attributes #0 = { sspstrong }
-attributes #1 = { noreturn sspreq}
diff --git a/llvm/test/CodeGen/X86/stack-protector-no-return.ll b/llvm/test/CodeGen/X86/stack-protector-no-return.ll
index ce78b2b7fe759..b8ea5bd07ee5e 100644
--- a/llvm/test/CodeGen/X86/stack-protector-no-return.ll
+++ b/llvm/test/CodeGen/X86/stack-protector-no-return.ll
@@ -1,4 +1,5 @@
-; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu -o - | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu -o - -verify-dom-info | FileCheck %s
$__clang_call_terminate = comdat any
@@ -7,10 +8,6 @@ $__clang_call_terminate = comdat any
; Function Attrs: mustprogress noreturn sspreq uwtable
define dso_local void @_Z7catchesv() local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
-; CHECK-LABEL: _Z7catchesv:
-; CHECK: # %bb.0: # %entry
-; CHECK: movq %fs:40, %rax
-; CHECK-NEXT: movq %rax, 8(%rsp)
entry:
%exception = tail call i8* @__cxa_allocate_exception(i64 4) #8
%0 = bitcast i8* %exception to i32*
@@ -18,17 +15,6 @@ entry:
invoke void @__cxa_throw(i8* nonnull %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #9
to label %unreachable unwind label %lpad
-; CHECK: callq __cxa_allocate_exception
-; CHECK-NEXT: movl $1, (%rax)
-; CHECK-NEXT: movq %fs:40, %rcx
-; CHECK-NEXT: cmpq 8(%rsp), %rcx
-; CHECK-NEXT: jne .LBB0_12
-; CHECK-NEXT: # %bb.1: # %SP_return
-; CHECK-NEXT: .Ltmp0:
-; CHECK-NEXT: movl $_ZTIi, %esi
-; CHECK-NEXT: movq %rax, %rdi
-; CHECK-NEXT: xorl %edx, %edx
-; CHECK-NEXT: callq __cxa_throw
lpad: ; preds = %entry
%1 = landingpad { i8*, i32 }
@@ -37,25 +23,11 @@ lpad: ; preds = %entry
%3 = tail call i8* @__cxa_begin_catch(i8* %2) #8
%call = invoke i64 @write(i32 noundef 1, i8* noundef getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 noundef 4)
to label %invoke.cont unwind label %lpad1
-; CHECK: callq __cxa_begin_catch
-; CHECK-NEXT: .Ltmp3:
-; CHECK-NEXT: movl $.L.str, %esi
-; CHECK-NEXT: movl $4, %edx
-; CHECK-NEXT: movl $1, %edi
-; CHECK-NEXT: callq write
invoke.cont: ; preds = %lpad
invoke void @_exit(i32 noundef 1) #9
to label %invoke.cont2 unwind label %lpad1
-; CHECK: # %bb.3: # %invoke.cont
-; CHECK-NEXT: movq %fs:40, %rax
-; CHECK-NEXT: cmpq 8(%rsp), %rax
-; CHECK-NEXT: jne .LBB0_12
-; CHECK-NEXT: # %bb.4: # %SP_return3
-; CHECK-NEXT: .Ltmp5:
-; CHECK-NEXT: movl $1, %edi
-; CHECK-NEXT: callq _exit
invoke.cont2: ; preds = %invoke.cont
unreachable
@@ -65,21 +37,9 @@ lpad1: ; preds = %invoke.cont, %lpad
cleanup
invoke void @__cxa_end_catch()
to label %eh.resume unwind label %terminate.lpad
-; CHECK: .LBB0_6: # %lpad1
-; CHECK-NEXT: .Ltmp7:
-; CHECK-NEXT: movq %rax, %rbx
-; CHECK-NEXT: .Ltmp8:
-; CHECK-NEXT: callq __cxa_end_catch
eh.resume: ; preds = %lpad1
resume { i8*, i32 } %4
-; CHECK: # %bb.7: # %eh.resume
-; CHECK-NEXT: movq %fs:40, %rax
-; CHECK-NEXT: cmpq 8(%rsp), %rax
-; CHECK-NEXT: jne .LBB0_12
-; CHECK-NEXT: # %bb.8: # %SP_return6
-; CHECK-NEXT: movq %rbx, %rdi
-; CHECK-NEXT: callq _Unwind_Resume at PLT
terminate.lpad: ; preds = %lpad1
%5 = landingpad { i8*, i32 }
@@ -88,16 +48,7 @@ terminate.lpad: ; preds = %lpad1
tail call void @__clang_call_terminate(i8* %6) #10
unreachable
-; CHECK: .LBB0_9: # %terminate.lpad
-; CHECK: movq %fs:40, %rcx
-; CHECK-NEXT: cmpq 8(%rsp), %rcx
-; CHECK-NEXT: jne .LBB0_12
-; CHECK-NEXT: # %bb.10: # %SP_return9
-; CHECK-NEXT: movq %rax, %rdi
-; CHECK-NEXT: callq __clang_call_terminate
-; CHECK: .LBB0_12: # %CallStackCheckFailBlk
-; CHECK-NEXT: callq __stack_chk_fail at PLT
unreachable: ; preds = %entry
unreachable
@@ -125,6 +76,11 @@ declare dso_local void @__cxa_end_catch() local_unnamed_addr #1
; Function Attrs: noinline noreturn nounwind
define linkonce_odr hidden void @__clang_call_terminate(i8* %0) local_unnamed_addr #5 comdat {
+; CHECK-LABEL: __clang_call_terminate:
+; CHECK: # %bb.0:
+; CHECK-NEXT: pushq %rax
+; CHECK-NEXT: callq __cxa_begin_catch
+; CHECK-NEXT: callq _ZSt9terminatev
%2 = tail call i8* @__cxa_begin_catch(i8* %0) #8
tail call void @_ZSt9terminatev() #10
unreachable
@@ -142,29 +98,25 @@ define dso_local void @_Z4vulni(i32 noundef %op) local_unnamed_addr #7 {
; CHECK-NEXT: movq %fs:40, %rax
; CHECK-NEXT: movq %rax, (%rsp)
; CHECK-NEXT: cmpl $1, %edi
-; CHECK-NEXT: je .LBB2_1
-; CHECK-NEXT: # %bb.3: # %if.end
+; CHECK-NEXT: je .LBB2_3
+; CHECK-NEXT: # %bb.1: # %if.end
; CHECK-NEXT: movq %fs:40, %rax
; CHECK-NEXT: cmpq (%rsp), %rax
-; CHECK-NEXT: jne .LBB2_5
-; CHECK-NEXT: # %bb.4: # %SP_return3
+; CHECK-NEXT: jne .LBB2_2
+; CHECK-NEXT: # %bb.4: # %SP_return
; CHECK-NEXT: popq %rax
; CHECK-NEXT: .cfi_def_cfa_offset 8
; CHECK-NEXT: retq
-; CHECK-NEXT: .LBB2_1: # %if.then
+; CHECK-NEXT: .LBB2_3: # %if.then
; CHECK-NEXT: .cfi_def_cfa_offset 16
; CHECK-NEXT: movl $4, %edi
; CHECK-NEXT: callq __cxa_allocate_exception
; CHECK-NEXT: movl $1, (%rax)
-; CHECK-NEXT: movq %fs:40, %rcx
-; CHECK-NEXT: cmpq (%rsp), %rcx
-; CHECK-NEXT: jne .LBB2_5
-; CHECK-NEXT: # %bb.2: # %SP_return
; CHECK-NEXT: movl $_ZTIi, %esi
; CHECK-NEXT: movq %rax, %rdi
; CHECK-NEXT: xorl %edx, %edx
; CHECK-NEXT: callq __cxa_throw
-; CHECK-NEXT: .LBB2_5: # %CallStackCheckFailBlk2
+; CHECK-NEXT: .LBB2_2: # %CallStackCheckFailBlk
; CHECK-NEXT: callq __stack_chk_fail at PLT
entry:
%cmp = icmp eq i32 %op, 1
More information about the llvm-commits
mailing list