Bug 79710 - Assert of a static fixed point expression incorrectly fails
Summary: Assert of a static fixed point expression incorrectly fails
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: 12.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-25 12:17 UTC by Georg
Modified: 2023-05-11 17:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Georg 2017-02-25 12:17:16 UTC
The program below triggers an unexpected Assert failure of a static
expression. The same static expression occurs identically in the same
region and is accepted there (see Test constant).  The Assert failure
can, however, be "prevented" by uncommenting another Assert of another
static expression before it that involves the same type and number. The
diagnostic messages change accordingly, too.

with Ada.Text_IO;
procedure Bug_FxP is

   Shoe_Ounce : constant := 2.54/64.0;
   type FxP is delta Shoe_Ounce range 0.00 .. 0.32
   with
     Size => 16,
     Small => 2.0**(-15);

   --
   -- Remove the comments to make the Assert _after_ this one not
   -- raise (and no other Assert raise either, as expected):
   --
   -- pragma Assert
   --   (3276 * FxP'Small = 0.0999755859375);

   pragma Assert
      -- Fails .IFF. the assertion aboved it stays commented out!
     (FxP'(0.1) = 0.0999755859375);

   Test : constant :=
     (case True is
         when False => 0,
         when FxP'(0.1) = 0.0999755859375 => 1);

   package FIO is new Ada.Text_IO.Fixed_IO (Fxp);
begin
   Ada.Text_IO.Put (Test'Img);
   FIO.Put (Fxp'(0.1), Aft => 20);
end;


$ gnatmake -gnata -gnatwa -gnatv -f bug_fxp.adb 
gcc -c -gnata -gnatwa -gnatv bug_fxp.adb

GNAT 7.0.0 20161104 (experimental) [trunk revision 241862]
Copyright 1992-2016, Free Software Foundation, Inc.

Compiling: bug_fxp.adb
Source file time stamp: 2017-02-25 11:53:54
Compiled at: 2017-02-25 12:54:01

    19.      (FxP'(0.1) = 0.0999755859375); 
              1    2
        >>> warning: assertion will fail at run time
        >>> warning: static fixed-point value is not a multiple of Small

    24.          when FxP'(0.1) = 0.0999755859375 => 1);
                           |
        >>> warning: static fixed-point value is not a multiple of Small

    29.    FIO.Put (Fxp'(0.1), Aft => 20);
                         |
        >>> warning: static fixed-point value is not a multiple of Small

 30 lines: No errors, 4 warnings
gnatbind -x bug_fxp.ali
gnatlink bug_fxp.ali
$ ./bug_fxp 

raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : bug_fxp.adb:19
$

When I remove the comments from the first Assert on line 15,
the one before line 19, the program runs without failure:

$ ./bug_fxp 
 1 0.09997558593750000000
$
Comment 1 Eric Botcazou 2023-05-11 17:08:48 UTC
Fixed in GCC 12 and later.