ugh, signed >> on negative values is implementation-defined
(but, at least, not undefined, and usually right; regress-test for it)
This commit is contained in:
25
check.t
25
check.t
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/check.t,v 1.603 2013/03/30 23:31:01 tg Exp $
|
# $MirOS: src/bin/mksh/check.t,v 1.604 2013/04/01 01:16:34 tg Exp $
|
||||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||||
@ -363,30 +363,32 @@ expected-stdout:
|
|||||||
---
|
---
|
||||||
name: arith-mandatory
|
name: arith-mandatory
|
||||||
description:
|
description:
|
||||||
If MKSH_GCC55009 is set when compiling, passing of
|
Passing of this test is *mandatory* for a valid mksh executable!
|
||||||
this test is *mandatory* for a valid mksh executable!
|
|
||||||
category: shell:legacy-no
|
category: shell:legacy-no
|
||||||
stdin:
|
stdin:
|
||||||
typeset -i sari=0
|
typeset -i sari=0
|
||||||
typeset -Ui uari=0
|
typeset -Ui uari=0
|
||||||
typeset -i x=0
|
typeset -i x=0
|
||||||
print -r -- $((x++)):$sari=$uari.
|
print -r -- $((x++)):$sari=$uari. #0
|
||||||
let --sari --uari
|
let --sari --uari
|
||||||
print -r -- $((x++)):$sari=$uari.
|
print -r -- $((x++)):$sari=$uari. #1
|
||||||
sari=2147483647 uari=2147483647
|
sari=2147483647 uari=2147483647
|
||||||
print -r -- $((x++)):$sari=$uari.
|
print -r -- $((x++)):$sari=$uari. #2
|
||||||
let ++sari ++uari
|
let ++sari ++uari
|
||||||
print -r -- $((x++)):$sari=$uari.
|
print -r -- $((x++)):$sari=$uari. #3
|
||||||
let --sari --uari
|
let --sari --uari
|
||||||
let 'sari *= 2' 'uari *= 2'
|
let 'sari *= 2' 'uari *= 2'
|
||||||
let ++sari ++uari
|
let ++sari ++uari
|
||||||
print -r -- $((x++)):$sari=$uari.
|
print -r -- $((x++)):$sari=$uari. #4
|
||||||
let ++sari ++uari
|
let ++sari ++uari
|
||||||
print -r -- $((x++)):$sari=$uari.
|
print -r -- $((x++)):$sari=$uari. #5
|
||||||
sari=-2147483648 uari=-2147483648
|
sari=-2147483648 uari=-2147483648
|
||||||
print -r -- $((x++)):$sari=$uari.
|
print -r -- $((x++)):$sari=$uari. #6
|
||||||
let --sari --uari
|
let --sari --uari
|
||||||
print -r -- $((x++)):$sari=$uari.
|
print -r -- $((x++)):$sari=$uari. #7
|
||||||
|
(( sari = -5 >> 1 ))
|
||||||
|
((# uari = -5 >> 1 ))
|
||||||
|
print -r -- $((x++)):$sari=$uari. #8
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
0:0=0.
|
0:0=0.
|
||||||
1:-1=4294967295.
|
1:-1=4294967295.
|
||||||
@ -396,6 +398,7 @@ expected-stdout:
|
|||||||
5:0=0.
|
5:0=0.
|
||||||
6:-2147483648=2147483648.
|
6:-2147483648=2147483648.
|
||||||
7:2147483647=2147483647.
|
7:2147483647=2147483647.
|
||||||
|
8:-3=2147483645.
|
||||||
---
|
---
|
||||||
name: arith-unsigned-1
|
name: arith-unsigned-1
|
||||||
description:
|
description:
|
||||||
|
18
expr.c
18
expr.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.64 2013/04/01 01:02:09 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.65 2013/04/01 01:16:37 tg Exp $");
|
||||||
|
|
||||||
#if !HAVE_SILENT_IDIVWRAPV
|
#if !HAVE_SILENT_IDIVWRAPV
|
||||||
#if !defined(MKSH_LEGACY_MODE) || HAVE_LONG_32BIT
|
#if !defined(MKSH_LEGACY_MODE) || HAVE_LONG_32BIT
|
||||||
@ -493,11 +493,23 @@ evalexpr(Expr_state *es, int prec)
|
|||||||
break;
|
break;
|
||||||
case O_RSHIFT:
|
case O_RSHIFT:
|
||||||
case O_RSHIFTASN:
|
case O_RSHIFTASN:
|
||||||
/* all bivui users need special handling */
|
if (es->natural)
|
||||||
res = bivui(vl, >>, vr);
|
res = vl->val.u >> vr->val.u;
|
||||||
|
else {
|
||||||
|
/*
|
||||||
|
* This is implementation-defined in ISO C,
|
||||||
|
* though not undefined, and all known twos
|
||||||
|
* complement implementations make an arith
|
||||||
|
* shift-right out of this, and open-coding
|
||||||
|
* it would probably hurt massively.
|
||||||
|
*/
|
||||||
|
/* how about ANDing? use vr->val.u? */
|
||||||
|
res = (mksh_uari_t)(vl->val.i >> vr->val.i);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
/* how about rotation? */
|
/* how about rotation? */
|
||||||
case O_LT:
|
case O_LT:
|
||||||
|
/* all bivui users need special handling */
|
||||||
res = bivui(vl, <, vr);
|
res = bivui(vl, <, vr);
|
||||||
break;
|
break;
|
||||||
case O_LE:
|
case O_LE:
|
||||||
|
Reference in New Issue
Block a user