diff --git a/AUTHORS b/AUTHORS index 36b0d5e7f..0078955d0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -34,6 +34,7 @@ Lucas Tabary-Maujean Manuel Barbosa Maxime Dénès Miguel Quaresma +Onyeka Obi Parmida Javadian Peter Schwabe Philipp G. Haselwarter diff --git a/changes/02-bugfix/1532-vector-shift-sign.md b/changes/02-bugfix/1532-vector-shift-sign.md new file mode 100644 index 000000000..218bdd395 --- /dev/null +++ b/changes/02-bugfix/1532-vector-shift-sign.md @@ -0,0 +1,5 @@ +- The type checker rejects a vector shift whose sign prefix conflicts with the + sign in the vector suffix (for instance `>>s4u32`). The scalar form + (`>>s32u`) was already rejected + ([PR #1532](https://github.com/jasmin-lang/jasmin/pull/1532); + fixes [#1441](https://github.com/jasmin-lang/jasmin/issues/1441)). diff --git a/compiler/src/pretyping.ml b/compiler/src/pretyping.ml index 287b6e0ed..1feec9ac1 100644 --- a/compiler/src/pretyping.ml +++ b/compiler/src/pretyping.ml @@ -829,8 +829,13 @@ let op_info exn op (s : W.signedness option) (castop:S.castop) ty ws_cmp vs_cmp in check_op_w loc op ty s ws_cmp - | CVS(vs,s,ve) -> - let s = tt_sign s in + | CVS(vs,sg,ve) -> + let s1 = tt_sign sg in + let s = + Option.map_default + (fun s -> if s = s1 then s1 else rs_tyerror ~loc (InvalidOperator op)) + s1 s + in let ve, ws = tt_vsize_op loc op vs ve in check_op_vec loc op vs_cmp (W.wsize_of_velem ve); OpKV(s, ve, ws) diff --git a/compiler/tests/fail/typing/x86-64/vector_shift_sign_mismatch.jazz b/compiler/tests/fail/typing/x86-64/vector_shift_sign_mismatch.jazz new file mode 100644 index 000000000..aeb814ca0 --- /dev/null +++ b/compiler/tests/fail/typing/x86-64/vector_shift_sign_mismatch.jazz @@ -0,0 +1,9 @@ +export +fn toto () -> reg u64 { + reg u128 v; + reg u64 r; + v = 1; + v = v >>s4u32 1; + r = 0; + return r; +} diff --git a/compiler/tests/negative.expected b/compiler/tests/negative.expected index 85530e64b..49634afa0 100644 --- a/compiler/tests/negative.expected +++ b/compiler/tests/negative.expected @@ -1558,6 +1558,10 @@ fail/typing/x86-64/vector_expr.jazz: "fail/typing/x86-64/vector_expr.jazz", line 8 (15-16): can not implicitly cast u128 into u256 +fail/typing/x86-64/vector_shift_sign_mismatch.jazz: + +"fail/typing/x86-64/vector_shift_sign_mismatch.jazz", line 6 (12-16): invalid operator >>s 4u32 + fail/typing/x86-64/write_constant_pointer_direct_array.jazz: "fail/typing/x86-64/write_constant_pointer_direct_array.jazz", line 6 (2-3): @@ -1750,7 +1754,7 @@ Allowed args are: Statistics: Annots: 4 - Pretyping: 49 + Pretyping: 50 Parsing: 4 Typing: 5 Compile: 218 diff --git a/compiler/tests/success/x86-64/vector_expression.jazz b/compiler/tests/success/x86-64/vector_expression.jazz index 478c222bf..97d2b73ef 100644 --- a/compiler/tests/success/x86-64/vector_expression.jazz +++ b/compiler/tests/success/x86-64/vector_expression.jazz @@ -25,6 +25,9 @@ fn toto () -> reg u64 { x = x <<4s64 32; x = x >>8s32 32; + x = x >>s8s32 32; + x = x >>u4u64 32; + x >>8s32= 27; v = #set0_128();