followup for cid 1004EE408E1382C1752 and 1004EE40DDD498FBB0D:

do a mirtoconf run-time check (ugh) to see whether the CPU designers
smoked/were brain-dead or if we don’t actually need the manual check
This commit is contained in:
tg 2011-12-31 02:04:18 +00:00
parent 25f413bf7d
commit 7ec1ae3771
3 changed files with 69 additions and 5 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.500 2011/12/31 00:31:25 tg Exp $' srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.501 2011/12/31 02:04:16 tg Exp $'
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
# Thorsten Glaser <tg@mirbsd.org> # Thorsten Glaser <tg@mirbsd.org>
@ -147,7 +147,7 @@ ac_testinit() {
} }
# pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput # pipe .c | ac_test[n] [!] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
ac_testn() { ac_testnnd() {
if test x"$1" = x"!"; then if test x"$1" = x"!"; then
fr=1 fr=1
shift shift
@ -173,6 +173,9 @@ ac_testn() {
test $ct = sunpro && vscan='-e ignored -e turned.off' test $ct = sunpro && vscan='-e ignored -e turned.off'
fi fi
test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr test -n "$vscan" && grep $vscan vv.out >/dev/null 2>&1 && fv=$fr
}
ac_testn() {
ac_testnnd "$@"
rmf conftest.c conftest.o ${tcfn}* vv.out rmf conftest.c conftest.o ${tcfn}* vv.out
ac_testdone ac_testdone
} }
@ -1171,7 +1174,7 @@ else
#define EXTERN #define EXTERN
#define MKSH_INCLUDES_ONLY #define MKSH_INCLUDES_ONLY
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.500 2011/12/31 00:31:25 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.501 2011/12/31 02:04:16 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); } int main(void) { printf("Hello, World!\n"); return (0); }
EOF EOF
case $cm in case $cm in
@ -1535,6 +1538,61 @@ EOF
CFLAGS=$save_CFLAGS CFLAGS=$save_CFLAGS
eval test 1 = \$HAVE_COMPILE_TIME_ASSERTS_$$ || exit 1 eval test 1 = \$HAVE_COMPILE_TIME_ASSERTS_$$ || exit 1
#
# runtime checks
# once this is more than one, check if we can do runtime
# checks (not cross-compiling) first to save on warnings
#
$e "${bi}run-time checks follow$ao, please ignore any weird errors"
ac_testnnd silent_idivwrapv '' '(run-time) whether signed integer division overflows wrap silently' <<-'EOF'
#define MKSH_INCLUDES_ONLY
#include "sh.h"
#ifdef SIGFPE
static void fpe_catcher(int) MKSH_A_NORETURN;
#endif
int main(int ac, char **av) {
mksh_ari_t o1, o2, r1, r2;
#ifdef SIGFPE
signal(SIGFPE, fpe_catcher);
#endif
o1 = ((mksh_ari_t)1 << 31);
o2 = -ac;
r1 = o1 / o2;
r2 = o1 % o2;
if (r1 == o1 && r2 == 0) {
printf("si");
return (0);
}
printf("no %d %d %d %d %s", o1, o2, r1, r2, av[0]);
return (1);
}
#ifdef SIGFPE
static const char fpe_msg[] = "no, got SIGFPE, what were they smoking?";
static void fpe_catcher(int sig MKSH_A_UNUSED) {
write(1, fpe_msg, sizeof(fpe_msg) - 1);
_exit(2);
}
#endif
EOF
if test $fv = 0; then
echo "| hrm, compiling this failed, but we will just failback"
else
echo "| running test programme; this will fail if cross-compiling"
echo "| in which case we will gracefully degrade to the default"
./$tcfn >vv.out 2>&1
rv=$?
echo "| result: `cat vv.out`"
fv=0
test $rv = 0 && test x"`cat vv.out`" = x"si" && fv=1
fi
rmf conftest.c conftest.o ${tcfn}* vv.out
ac_testdone
ac_cppflags
$e "${bi}end of run-time checks$ao"
# #
# Compiler: Praeprocessor (only if needed) # Compiler: Praeprocessor (only if needed)
# #

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.91 2011/12/08 22:19:16 tg Exp $ # $MirOS: src/bin/mksh/Makefile,v 1.92 2011/12/31 02:04:17 tg Exp $
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
# Thorsten Glaser <tg@mirbsd.org> # Thorsten Glaser <tg@mirbsd.org>
@ -46,6 +46,8 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
-DHAVE_STRCASESTR=1 -DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 \ -DHAVE_STRCASESTR=1 -DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 \
-DHAVE_REVOKE_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \ -DHAVE_REVOKE_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
-DHAVE_PERSISTENT_HISTORY=1 -DHAVE_PERSISTENT_HISTORY=1
# probably differs between i386 and sparc
CPPFLAGS+= -DHAVE_SILENT_IDIVWRAPV=0
COPTS+= -std=gnu99 -Wall COPTS+= -std=gnu99 -Wall
.endif .endif

6
expr.c
View File

@ -22,7 +22,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.52 2011/12/16 20:03:02 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/expr.c,v 1.53 2011/12/31 02:04:18 tg Exp $");
/* The order of these enums is constrained by the order of opinfo[] */ /* The order of these enums is constrained by the order of opinfo[] */
enum token { enum token {
@ -366,21 +366,25 @@ evalexpr(Expr_state *es, int prec)
break; break;
case O_DIV: case O_DIV:
case O_DIVASN: case O_DIVASN:
#if !HAVE_SILENT_IDIVWRAPV
if (!es->natural && vr->val.i == -1 && if (!es->natural && vr->val.i == -1 &&
vl->val.i == ((mksh_ari_t)1 << 31)) { vl->val.i == ((mksh_ari_t)1 << 31)) {
/* -2147483648 / -1 = 2147483648 */ /* -2147483648 / -1 = 2147483648 */
/* 80000000 / FFFFFFFF = 80000000 */ /* 80000000 / FFFFFFFF = 80000000 */
res = ((mksh_ari_t)1 << 31); res = ((mksh_ari_t)1 << 31);
} else } else
#endif
res = bivui(vl, /, vr); res = bivui(vl, /, vr);
break; break;
case O_MOD: case O_MOD:
case O_MODASN: case O_MODASN:
#if !HAVE_SILENT_IDIVWRAPV
if (!es->natural && vr->val.i == -1 && if (!es->natural && vr->val.i == -1 &&
vl->val.i == ((mksh_ari_t)1 << 31)) { vl->val.i == ((mksh_ari_t)1 << 31)) {
/* -2147483648 % -1 = 0 */ /* -2147483648 % -1 = 0 */
res = 0; res = 0;
} else } else
#endif
res = bivui(vl, %, vr); res = bivui(vl, %, vr);
break; break;
case O_PLUS: case O_PLUS: