https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92362

            Bug ID: 92362
           Summary: Compiler generates 2 function calls in a 'with
                    Address' aspect specification that uses a function
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cthowie at netzero dot net
  Target Milestone: ---

PLATFORM USED: GCC 9.2 toolchain on Windows 10 Intel x64 using MSYS2 (mingw64).
Note the GNAT FSF 8.2 compiler does NOT have the bug.

ISSUE: Multiple calls to a function that returns an address for use "with
Address".
Note that if you use the alternative (non-aspect) attribute definition clause,
the bug doesn't appear in 9.2, so a statement like:
   bar : Integer;
   for bar'Address use Get_Address;
is handled properly but:
   bar : Integer with Address => Get_Address;
is compiled defectively.

EXAMPLE PROGRAM DEMONSTRATING THE BUG:
      with Ada.Text_IO; use Ada.Text_IO;
      with System;

      procedure Main
      is
         foo : Integer := 0;

         function Get_Address return System.Address
         is
         begin
            Put_Line ("Get_Address called");
            return foo'Address;
         end Get_Address;

         bar : Integer with Address => Get_Address;  -- Get_Address called
TWICE = BUG!
      begin
         bar := 100;
         Put_Line ("foo = " & foo'Img);
      end Main;

BUILD INSTRUCTIONS:
Save the above example program to e.g., "main.adb" then run: gnatmake main.adb
then run the program "main.exe" and you'll see GCC GNAT FSF 9.2 output is
incorrect:
      Get_Address called
      Get_Address called
      foo =  100
whereas earlier version GNAT FSF 8.2 produces correct output:
      Get_Address called
      foo =  100
and so does current GNAT FSF 9.2 but only if you use the more verbose attribute
definition clause shown above.

Reply via email to