Fix UBSan error with overflowing exponent operator (#1727)

This commit is contained in:
Rangi
2025-07-07 19:08:26 -04:00
committed by GitHub
parent c9765ec158
commit 1a77667409
5 changed files with 27 additions and 11 deletions

11
test/asm/exponent.asm Normal file
View File

@@ -0,0 +1,11 @@
def n = 30
for x, -n, n
for p, n
def v1 = x ** p
def v2 = 1
for i, p
def v2 *= x
endr
assert v1 == v2, "{d:x}**{d:p} = {d:v1} or {d:v2}?"
endr
endr

View File

@@ -34,6 +34,12 @@ def x = x << 1
dl -1 << 1
print_x
def x = 2 ** 31
print_x
def x = 5 ** 29
print_x
def x = 4294967295
def x = 4294967296

View File

@@ -2,7 +2,7 @@ warning: overflow.asm(23): [-Wdiv]
Division of -2147483648 by -1 yields -2147483648
warning: overflow.asm(24): [-Wdiv]
Division of -2147483648 by -1 yields -2147483648
warning: overflow.asm(38): [-Wlarge-constant]
warning: overflow.asm(44): [-Wlarge-constant]
Integer constant is too large
warning: overflow.asm(41): [-Wlarge-constant]
warning: overflow.asm(47): [-Wlarge-constant]
Graphics constant is too long, only first 8 pixels considered

View File

@@ -4,3 +4,5 @@ $80000000
$80000000
$0
$FFFFFFFE
$80000000
$6B90BE55