7 ms·
On https://godbolt.org/ https://godbolt.org/ select Ada and compiler option "-O2" function Square(num : Integer) return Integer is tab : array (0..
by guerby 4mo ago
On https://godbolt.org/ https://godbolt.org/ select Ada and compiler option "-O2"
function Square(num : Integer) return Integer is
tab : array (0..100) of integer;
begin
for i in 0..101 loop
tab(i):=i;
end loop;
return tab(100);
end Square;
The assembly code generated is :
sub rsp, 8 #,
mov esi, 11 #,
mov edi, OFFSET FLAT:.LC0 #,
call "__gnat_rcheck_CE_Index_Check" #
Loop is not run and exeption handler is called directly.
Link : https://godbolt.org/z/qT4TsKPxz https://godbolt.org/z/qT4TsKPxz
- Animats 4mo agoRight, that's the extreme case, where the problem is detected at compile time. Unfortunately, it's not a user-visible error message at compile time. Need to try an example where the size isn't known until run time.