Skip to content

Commit ba1e663

Browse files
authored
aarch64: Fix an overflowing shift panic (#10382)
Ensure that a compile-time-shift-amount is masked to avoid a debug assertion about an overflowing shift. Closes #10373
1 parent 944ae82 commit ba1e663

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

cranelift/codegen/src/isa/aarch64/inst.isle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,10 +3884,10 @@
38843884
;; extension must happen before the shift. This will pattern-match the shift
38853885
;; first and then if that succeeds afterwards try to find an extend.
38863886
(rule 6 (amode_no_more_iconst ty (iadd x (ishl y (iconst (u64_from_imm64 n)))) offset)
3887-
(if-let true (u64_eq (ty_bytes ty) (u64_shl 1 n)))
3887+
(if-let true (u64_eq (ty_bytes ty) (u64_shl 1 (shift_masked_imm ty n))))
38883888
(amode_reg_scaled (amode_add x offset) y))
38893889
(rule 7 (amode_no_more_iconst ty (iadd (ishl y (iconst (u64_from_imm64 n))) x) offset)
3890-
(if-let true (u64_eq (ty_bytes ty) (u64_shl 1 n)))
3890+
(if-let true (u64_eq (ty_bytes ty) (u64_shl 1 (shift_masked_imm ty n))))
38913891
(amode_reg_scaled (amode_add x offset) y))
38923892

38933893
(decl amode_reg_scaled (Reg Value) AMode)

cranelift/filetests/filetests/isa/aarch64/amodes.clif

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,3 +784,33 @@ block0(v0: i64, v1: i32):
784784
; ldr x0, [x0, w1, sxtw #3] ; trap: heap_oob
785785
; ret
786786

787+
function %no_panic(i64, i64) -> i64 {
788+
block0(v0: i64, v1: i64):
789+
v8 = ishl_imm v1, 100
790+
v9 = iadd v0, v8
791+
v10 = load.i64 v9
792+
793+
v5 = ishl_imm v1, 100
794+
v6 = iadd v5, v0
795+
v7 = load.i64 v6
796+
return v10
797+
}
798+
799+
; VCode:
800+
; block0:
801+
; lsl x6, x1, #36
802+
; ldr x6, [x0, x6]
803+
; lsl x7, x1, #36
804+
; ldr x7, [x7, x0]
805+
; mov x0, x6
806+
; ret
807+
;
808+
; Disassembled:
809+
; block0: ; offset 0x0
810+
; lsl x6, x1, #0x24
811+
; ldr x6, [x0, x6] ; trap: heap_oob
812+
; lsl x7, x1, #0x24
813+
; ldr x7, [x7, x0] ; trap: heap_oob
814+
; mov x0, x6
815+
; ret
816+

0 commit comments

Comments
 (0)