-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[CodeGen][ARM] Bug fix InsertStackProtectors with EH_SJ_LJ #147411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AbhayKanhere
wants to merge
1
commit into
llvm:main
Choose a base branch
from
AbhayKanhere:dev/abhay/ehsjlj-stackprotect-bug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -588,14 +588,22 @@ bool InsertStackProtectors(const TargetMachine *TM, Function *F, | |||||
continue; | ||||||
Instruction *CheckLoc = dyn_cast<ReturnInst>(BB.getTerminator()); | ||||||
if (!CheckLoc && !DisableCheckNoReturn) | ||||||
for (auto &Inst : BB) | ||||||
for (auto &Inst : BB) { | ||||||
if(auto *IB = dyn_cast<IntrinsicInst>(&Inst) ) | ||||||
if(IB->getIntrinsicID()==Intrinsic::eh_sjlj_callsite) { | ||||||
// eh_sjlj_callsite has to be in same BB as the | ||||||
// bb terminator. Dont insert within this range. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
CheckLoc = IB; | ||||||
break; | ||||||
} | ||||||
if (auto *CB = dyn_cast<CallBase>(&Inst)) | ||||||
// Do stack check before noreturn calls that aren't nounwind (e.g: | ||||||
// __cxa_throw). | ||||||
if (CB->doesNotReturn() && !CB->doesNotThrow()) { | ||||||
CheckLoc = CB; | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
||||||
if (!CheckLoc) | ||||||
continue; | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc -O0 -mtriple=thumbv7s-apple-darwin < %s | FileCheck %s | ||
target datalayout = "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32" | ||
|
||
; Function Attrs: mustprogress noinline optnone ssp | ||
define ptr @foo() #0 personality ptr @__gxx_personality_sj0 { | ||
; CHECK-LABEL: foo: | ||
; CHECK: Lfunc_begin0: | ||
; CHECK-NEXT: @ %bb.0: | ||
; CHECK-NEXT: push {r4, r5, r6, r7, lr} | ||
; CHECK-NEXT: add r7, sp, #12 | ||
; CHECK-NEXT: push.w {r8, r10, r11} | ||
; CHECK-NEXT: sub.w r4, sp, #64 | ||
; CHECK-NEXT: bfc r4, #0, #4 | ||
; CHECK-NEXT: mov sp, r4 | ||
; CHECK-NEXT: vst1.64 {d8, d9, d10, d11}, [r4:128]! | ||
; CHECK-NEXT: vst1.64 {d12, d13, d14, d15}, [r4:128] | ||
; CHECK-NEXT: sub sp, #96 | ||
; CHECK-NEXT: movw r0, :lower16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_2+4)) | ||
; CHECK-NEXT: movt r0, :upper16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_2+4)) | ||
; CHECK-NEXT: LPC0_2: | ||
; CHECK-NEXT: add r0, pc | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: movw r0, :lower16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_3+4)) | ||
; CHECK-NEXT: movt r0, :upper16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_3+4)) | ||
; CHECK-NEXT: LPC0_3: | ||
; CHECK-NEXT: add r0, pc | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: str r0, [sp, #92] | ||
; CHECK-NEXT: movw r0, :lower16:(L___gxx_personality_sj0$non_lazy_ptr-(LPC0_4+4)) | ||
; CHECK-NEXT: movt r0, :upper16:(L___gxx_personality_sj0$non_lazy_ptr-(LPC0_4+4)) | ||
; CHECK-NEXT: LPC0_4: | ||
; CHECK-NEXT: add r0, pc | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: str r0, [sp, #36] | ||
; CHECK-NEXT: ldr r0, LCPI0_0 | ||
; CHECK-NEXT: LPC0_0: | ||
; CHECK-NEXT: add r0, pc | ||
; CHECK-NEXT: str r0, [sp, #40] | ||
; CHECK-NEXT: str r7, [sp, #44] | ||
; CHECK-NEXT: mov r0, sp | ||
; CHECK-NEXT: str r0, [sp, #52] | ||
; CHECK-NEXT: ldr r0, LCPI0_1 | ||
; CHECK-NEXT: orr r0, r0, #1 | ||
; CHECK-NEXT: LPC0_1: | ||
; CHECK-NEXT: add r0, pc | ||
; CHECK-NEXT: str r0, [sp, #48] | ||
; CHECK-NEXT: add r0, sp, #12 | ||
; CHECK-NEXT: bl __Unwind_SjLj_Register | ||
; CHECK-NEXT: movs r0, #1 | ||
; CHECK-NEXT: str r0, [sp, #16] | ||
; CHECK-NEXT: movw r0, :lower16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_5+4)) | ||
; CHECK-NEXT: movt r0, :upper16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_5+4)) | ||
; CHECK-NEXT: LPC0_5: | ||
; CHECK-NEXT: add r0, pc | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: ldr r1, [sp, #92] | ||
; CHECK-NEXT: cmp r0, r1 | ||
; CHECK-NEXT: bne LBB0_7 | ||
; CHECK-NEXT: @ %bb.1: @ %SP_return | ||
; CHECK-NEXT: Ltmp0: | ||
; CHECK-NEXT: movs r1, #0 | ||
; CHECK-NEXT: mov r0, r1 | ||
; CHECK-NEXT: bl _foo2 | ||
; CHECK-NEXT: Ltmp1: | ||
; CHECK-NEXT: b LBB0_2 | ||
; CHECK-NEXT: LBB0_2: | ||
; CHECK-NEXT: movs r0, #2 | ||
; CHECK-NEXT: str r0, [sp, #16] | ||
; CHECK-NEXT: movw r0, :lower16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_6+4)) | ||
; CHECK-NEXT: movt r0, :upper16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_6+4)) | ||
; CHECK-NEXT: LPC0_6: | ||
; CHECK-NEXT: add r0, pc | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: ldr r1, [sp, #92] | ||
; CHECK-NEXT: cmp r0, r1 | ||
; CHECK-NEXT: bne LBB0_7 | ||
; CHECK-NEXT: @ %bb.3: @ %SP_return2 | ||
; CHECK-NEXT: Ltmp2: | ||
; CHECK-NEXT: movs r2, #0 | ||
; CHECK-NEXT: mov r0, r2 | ||
; CHECK-NEXT: mov r1, r2 | ||
; CHECK-NEXT: bl _foo3 | ||
; CHECK-NEXT: Ltmp3: | ||
; CHECK-NEXT: b LBB0_6 | ||
; CHECK-NEXT: LBB0_4: | ||
; CHECK-NEXT: Ltmp4: | ||
; CHECK-NEXT: ldr r0, [sp, #20] | ||
; CHECK-NEXT: ldr r0, [sp, #24] | ||
; CHECK-NEXT: add r0, sp, #12 | ||
; CHECK-NEXT: bl __Unwind_SjLj_Unregister | ||
; CHECK-NEXT: movw r0, :lower16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_7+4)) | ||
; CHECK-NEXT: movt r0, :upper16:(L___stack_chk_guard$non_lazy_ptr-(LPC0_7+4)) | ||
; CHECK-NEXT: LPC0_7: | ||
; CHECK-NEXT: add r0, pc | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: ldr r0, [r0] | ||
; CHECK-NEXT: ldr r1, [sp, #92] | ||
; CHECK-NEXT: cmp r0, r1 | ||
; CHECK-NEXT: bne LBB0_7 | ||
; CHECK-NEXT: @ %bb.5: @ %SP_return3 | ||
; CHECK-NEXT: movs r0, #0 | ||
; CHECK-NEXT: add r4, sp, #96 | ||
; CHECK-NEXT: vld1.64 {d8, d9, d10, d11}, [r4:128]! | ||
; CHECK-NEXT: vld1.64 {d12, d13, d14, d15}, [r4:128] | ||
; CHECK-NEXT: sub.w r4, r7, #24 | ||
; CHECK-NEXT: mov sp, r4 | ||
; CHECK-NEXT: pop.w {r8, r10, r11} | ||
; CHECK-NEXT: pop {r4, r5, r6, r7, pc} | ||
; CHECK-NEXT: LBB0_6: | ||
; CHECK-NEXT: trap | ||
; CHECK-NEXT: LBB0_7: @ %CallStackCheckFailBlk | ||
; CHECK-NEXT: bl ___stack_chk_fail | ||
; CHECK-NEXT: LBB0_8: | ||
; CHECK-NEXT: ldr r0, [sp, #16] | ||
; CHECK-NEXT: str r0, [sp, #8] @ 4-byte Spill | ||
; CHECK-NEXT: cmp r0, #2 | ||
; CHECK-NEXT: bhi LBB0_12 | ||
; CHECK-NEXT: @ %bb.9: | ||
; CHECK-NEXT: ldr r1, [sp, #8] @ 4-byte Reload | ||
; CHECK-NEXT: LCPI0_2: | ||
; CHECK-NEXT: tbb [pc, r1] | ||
; CHECK-NEXT: @ %bb.10: | ||
; CHECK-NEXT: LJTI0_0: | ||
; CHECK-NEXT: .data_region jt8 | ||
; CHECK-NEXT: .byte (LBB0_11-(LCPI0_2+4))/2 | ||
; CHECK-NEXT: .byte (LBB0_11-(LCPI0_2+4))/2 | ||
; CHECK-NEXT: .end_data_region | ||
; CHECK-NEXT: .p2align 1 | ||
; CHECK-NEXT: LBB0_11: | ||
; CHECK-NEXT: b LBB0_4 | ||
; CHECK-NEXT: LBB0_12: | ||
; CHECK-NEXT: trap | ||
; CHECK-NEXT: .p2align 2 | ||
; CHECK-NEXT: @ %bb.13: | ||
%1 = alloca [14 x i8], align 16 | ||
%2 = invoke i32 @"foo2"(ptr noundef null, ptr noundef null) #1 | ||
to label %3 unwind label %4 | ||
|
||
3: ; preds = %0 | ||
invoke void @"foo3"(ptr null, ptr null, ptr null) #2 | ||
to label %6 unwind label %4 | ||
|
||
4: ; preds = %3, %0 | ||
%5 = landingpad { ptr, i32 } | ||
cleanup | ||
ret ptr null | ||
|
||
6: ; preds = %3 | ||
unreachable | ||
} | ||
|
||
declare i32 @__gxx_personality_sj0(...) | ||
declare i32 @foo2(ptr,ptr) | ||
declare void @foo3(ptr,ptr,ptr) | ||
; uselistorder directives | ||
uselistorder ptr null, { 2, 3, 4, 5, 0, 6, 7, 1, 8, 9 } | ||
|
||
attributes #0 = { mustprogress ssp "frame-pointer"="all" "no-builtin-calloc" "no-builtin-stpcpy" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #2 = { noreturn } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clang-format bot is complaining about the spacing of things here. You should apply the diff it gave you in this comment: #147411 (comment)