https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128457
Bug ID: 128457
Summary: Membership test does not round a real named number to
the tested type
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: andreaboido.asti at gmail dot com
CC: dkm at gcc dot gnu.org
Target Milestone: ---
Created attachment 66088
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66088&action=edit
Minimal reproducer for the bug
AI disclosure: this bug was found with Opus 5.5 while diagnosing some sporadic
Ada unit tests.
A nonstatic membership test whose tested expression is a real named number
is evaluated with the bounds converted to universal_real, instead of
rounding the named number to the tested type as RM 4.9(38/2) requires. The
equivalent relational operator is evaluated correctly, so the two forms
disagree.
repro.adb:
with Ada.Text_IO; use Ada.Text_IO;
procedure Repro is
X : constant := 0.1; -- not exact in Float
F : Float := X; -- F = Float (X), rounded up to 0.100000001490116...
begin
Put_Line ("F <= X : " & Boolean'Image (F <= X));
Put_Line ("X in F .. 1.0 : " & Boolean'Image (X in F .. 1.0));
end Repro;
Commands:
$ gnatmake -f -v repro.adb
gcc -c repro.adb
gnatbind -x repro.ali
gnatlink repro.ali
$ ./repro
F <= X : TRUE
X in F .. 1.0 : FALSE
Expected:
F <= X : TRUE
X in F .. 1.0 : TRUE
The same output is produced with -O2. -gnatwa reports only "F" is not
modified, could be declared constant [-gnatwk]; declaring F constant makes
both expressions static, where FALSE is the correct result for both, so F
is deliberately a variable.
-gnatG shows the expansion:
(if 0.1 >= universal_real(f) then ...)
whereas F <= X expands to
(if f <= [13421773.0*2**(-27)] then ...)
Reproduced with:
- gcc version 17.0.0 20261101 (experimental) (GCC), snapshot
gcc-17-20261101, configured with: --enable-languages=c,ada
--disable-bootstrap --disable-multilib --disable-nls
- gcc version 16.2.1 20260929 (SUSE Linux) (linked with -largs -no-pie)
- gcc version 16.1.0 (GCC), configured with: ../gcc/configure
--enable-languages=c,c++,ada --enable-clocale=generic --enable-multilib
(plus --prefix and --with-{gmp,mpfr,mpc,isl} paths)
- gcc-15 (SUSE Linux) 15.2.1 20260202
- gcc-13 (SUSE Linux) 13.4.0 (linked with -largs -no-pie)
System: openSUSE Tumbleweed, Linux 6.18.6 x86_64.