summaryrefslogtreecommitdiff
path: root/t/opbasic
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2014-12-22 16:25:59 +0000
committerDavid Mitchell <davem@iabyn.com>2014-12-31 11:28:51 +0000
commit02b08bbcbd0ac87188306a567fc071bbfd134777 (patch)
tree4976a3981a61ed8bb506cf95047907b0bf22a877 /t/opbasic
parent919894b775f42c5afd2195b1a5240e66205560d1 (diff)
downloadperl-02b08bbcbd0ac87188306a567fc071bbfd134777.tar.gz
fix more -IV_MIN negations
Doing uv = -iv is undefined behaviour if iv happens to be IV_MIN. This occurs in several places in the perl sources. These ones were found by visual code inspection rather than using -fsanitize=undefined, but I've added extra tests so that -fsanitize could find them now.
Diffstat (limited to 't/opbasic')
-rw-r--r--t/opbasic/arith.t10
1 files changed, 9 insertions, 1 deletions
diff --git a/t/opbasic/arith.t b/t/opbasic/arith.t
index 10efe86fb8..3493968425 100644
--- a/t/opbasic/arith.t
+++ b/t/opbasic/arith.t
@@ -9,7 +9,7 @@ BEGIN {
# functions imported from t/test.pl or Test::More, as those programs/libraries
# use operators which are what is being tested in this file.
-print "1..181\n";
+print "1..186\n";
sub try ($$$) {
print +($_[1] ? "ok" : "not ok"), " $_[0] - $_[2]\n";
@@ -476,3 +476,11 @@ try $T++, "1.23 " + 0 == 1.23, '1.23 with trailing space';
try $T++, "+1.23" + 0 == 1.23, '1.23 with unary plus';
try $T++, "-1.23" + 0 == -1.23, '1.23 with unary minus';
try $T++, "1.23e4" + 0 == 12300, '1.23e4';
+
+# trigger various attempts to negate IV_MIN
+
+tryeq $T++, 0x80000000 / -0x80000000, -1, '(IV_MAX+1) / IV_MIN';
+tryeq $T++, -0x80000000 / 0x80000000, -1, 'IV_MIN / (IV_MAX+1)';
+tryeq $T++, 0x80000000 / -1, -0x80000000, '(IV_MAX+1) / -1';
+tryeq $T++, 0 % -0x80000000, 0, '0 % IV_MIN';
+tryeq $T++, -0x80000000 % -0x80000000, 0, 'IV_MIN % IV_MIN';