Richard Kenner wrote:
Why doesn't it work? Can it be made to work relatively easily? Do we
need functionality like this for Ada or Java?
Ada currently has to do this itself, precisely because -ftrapv doesn't
work, so it's not the case that Ada "needs" it.
Well no one "needs" anything in this sense, any interfaced is Turing
complete so there is *always* a work around deficiencies in the back
end. But right now, the "do this itself" is really horribly inefficient:
procedure k (x : out integer; y,z : integer) is
begin
x := y + z;
end;
procedure k (x : out integer; y : integer; z : integer) is
begin
[constraint_error when
not (long_long_integer?(y) + long_long_integer?(z) in
-16#8000_0000# .. 16#7FFF_FFFF#)
"overflow check failed"]
x := integer?(long_long_integer?(y) + long_long_integer?(z));
return;
end k;
assembly language (-O2) with -gnato to enable overflow checking
__ada_k:
LFB3:
pushl %ebp
LCFI0:
movl %esp, %ebp
LCFI1:
pushl %ebx
LCFI2:
subl $4, %esp
LCFI3:
movl 8(%ebp), %eax
movl 12(%ebp), %ecx
movl %eax, %edx
movl %ecx, %ebx
sarl $31, %edx
sarl $31, %ebx
addl %eax, %ecx
adcl %edx, %ebx
movl %ecx, %eax
addl $-2147483648, %eax
movl %ebx, %edx
adcl $0, %edx
cmpl $0, %edx
jbe L6
pushl %eax
pushl %eax
pushl $3
pushl $LC0
LCFI4:
call ___gnat_rcheck_10
.p2align 4,,7
L6:
movl %ecx, %eax
movl -4(%ebp), %ebx
leave
ret
pretty gruesome :-(