case ARITH_DIV:
if (!b)
yyerror("division by zero");
+ if (a == ARITH_MIN && b == -1)
+ yyerror("divide error");
return op == ARITH_REM ? a % b : a / b;
case ARITH_MUL:
return a * b;
#define ARITH_FORMAT_STR "%" PRIdMAX
#define atoarith_t(arg) strtoimax(arg, NULL, 0)
#define strtoarith_t(nptr, endptr, base) strtoimax(nptr, endptr, base)
+#define ARITH_MIN INTMAX_MIN
+#define ARITH_MAX INTMAX_MAX
typedef void *pointer;
#define MKINIT /* empty */
--- /dev/null
+# $FreeBSD: src/tools/regression/bin/sh/expansion/arith11.0,v 1.1 2011/02/12 23:44:05 jilles Exp $
+# Try to divide the smallest integer by -1.
+# On amd64 this causes SIGFPE, so make sure the shell checks.
+
+# Calculate the minimum possible value, assuming two's complement and
+# a certain interpretation of overflow when shifting left.
+minint=1
+while [ $((minint <<= 1)) -gt 0 ]; do
+ :
+done
+v=$( eval ': $((minint / -1))' 2>&1 >/dev/null)
+[ $? -ne 0 ] && [ -n "$v" ]