public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/113893] New: Finalization exception issue with anonymous access object.
@ 2024-02-12 20:35 p.p11 at orange dot fr
  2024-02-14 15:54 ` [Bug ada/113893] finalization issue with anonymous access object of local type ebotcazou at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: p.p11 at orange dot fr @ 2024-02-12 20:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113893
           Summary: Finalization exception issue with anonymous access
                    object.
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: p.p11 at orange dot fr
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 57403
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57403&action=edit
Reproducer.

In the source code, two procedures: Test01 which uses Ada.Finalization and
Test02 which doesn't.

When executing only Test01, the Finalize calls of 2 objects and 2 anonymous
access objects seem correct:
      overriding procedure Finalize (Object : in out Container) is
      begin
         Ada.Text_IO.Put_Line ("Current:" & Image (Object.Data));
      end Finalize;
$ ./bin/test_20210208_fin 
Test01:
Value: 2.64000E+01
Current: 8.80000E+00
Current: 2.64000E+01
Current: 6.60000E+00
Current: 7.70000E+00

When executing Test01 then Test02, all the Finalize calls aren't displayed but
an exception occurs:
$ ./bin/test_20210208_fin 
Test01:
Value: 2.64000E+01
Current: 8.80000E+00
Current: 2.64000E+01
Test02:
Value: 2.64000E+01
Execution of ./bin/test_20210208_fin terminated by unhandled exception
raised CONSTRAINT_ERROR : erroneous memory access

I understand the compiler warning:
test_20210208_fin.adb:29:09: warning: object designated by anonymous access
object might not be finalized until its enclosing library unit goes out of
scope [enabled by default]

But, what could be wrong with the exception?

(Full code in attachment)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug ada/113893] finalization issue with anonymous access object of local type
  2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
@ 2024-02-14 15:54 ` ebotcazou at gcc dot gnu.org
  2024-02-14 15:55 ` ebotcazou at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2024-02-14 15:54 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |ebotcazou at gcc dot gnu.org
            Summary|Finalization exception      |finalization issue with
                   |issue with anonymous access |anonymous access object of
                   |object.                     |local type
   Last reconfirmed|                            |2024-02-14
     Ever confirmed|0                           |1

--- Comment #1 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
The problem is that the finalization routine of Float_Sanitized.Container is
local to Test01 but is invoked indirectly from "its enclosing library unit"
when the dynamically allocated object is finalized, namely the enclosing
procedure.
So it's a plain dangling reference and its effects depend on the phase of the
moon, for example the mere presence of Test02.

The workaround is of course to follow the advice of the warning or else to move
the instantiation of Float_Sanitized to the enclosing procedure.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug ada/113893] finalization issue with anonymous access object of local type
  2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
  2024-02-14 15:54 ` [Bug ada/113893] finalization issue with anonymous access object of local type ebotcazou at gcc dot gnu.org
@ 2024-02-14 15:55 ` ebotcazou at gcc dot gnu.org
  2024-02-14 16:13 ` ebotcazou at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2024-02-14 15:55 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |SUSPENDED

--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
No plan to fix this in the short term.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug ada/113893] finalization issue with anonymous access object of local type
  2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
  2024-02-14 15:54 ` [Bug ada/113893] finalization issue with anonymous access object of local type ebotcazou at gcc dot gnu.org
  2024-02-14 15:55 ` ebotcazou at gcc dot gnu.org
@ 2024-02-14 16:13 ` ebotcazou at gcc dot gnu.org
  2024-02-14 17:36 ` ebotcazou at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2024-02-14 16:13 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|SUSPENDED                   |NEW

--- Comment #3 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
On second thoughts, some stopgap measure is probably in order.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug ada/113893] finalization issue with anonymous access object of local type
  2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
                   ` (2 preceding siblings ...)
  2024-02-14 16:13 ` ebotcazou at gcc dot gnu.org
@ 2024-02-14 17:36 ` ebotcazou at gcc dot gnu.org
  2024-02-26 12:20 ` [Bug ada/113893] finalization of object allocated by anonymous access type designating " cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2024-02-14 17:36 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ebotcazou at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug ada/113893] finalization of object allocated by anonymous access type designating local type
  2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
                   ` (3 preceding siblings ...)
  2024-02-14 17:36 ` ebotcazou at gcc dot gnu.org
@ 2024-02-26 12:20 ` cvs-commit at gcc dot gnu.org
  2024-02-26 12:22 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-26 12:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Eric Botcazou <ebotcazou@gcc.gnu.org>:

https://gcc.gnu.org/g:39c07c5a3bf4a865175727bf60d5758372543b87

commit r14-9179-g39c07c5a3bf4a865175727bf60d5758372543b87
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Mon Feb 26 13:13:34 2024 +0100

    Finalization of object allocated by anonymous access designating local type

    The finalization of objects dynamically allocated through an anonymous
    access type is deferred to the enclosing library unit in the current
    implementation and a warning is given on each of them.

    However this cannot be done if the designated type is local, because this
    would generate dangling references to the local finalization routine, so
    the finalization needs to be dropped in this case and the warning adjusted.

    gcc/ada/
            PR ada/113893
            * exp_ch7.adb (Build_Anonymous_Master): Do not build the master
            for a local designated type.
            * exp_util.adb (Build_Allocate_Deallocate_Proc): Force Needs_Fin
            to false if no finalization master is attached to an access type
            and assert that it is anonymous in this case.
            * sem_res.adb (Resolve_Allocator): Mention that the object might
            not be finalized at all in the warning given when the type is an
            anonymous access-to-controlled type.

    gcc/testsuite/
            * gnat.dg/access10.adb: New test.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug ada/113893] finalization of object allocated by anonymous access type designating local type
  2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
                   ` (4 preceding siblings ...)
  2024-02-26 12:20 ` [Bug ada/113893] finalization of object allocated by anonymous access type designating " cvs-commit at gcc dot gnu.org
@ 2024-02-26 12:22 ` cvs-commit at gcc dot gnu.org
  2024-02-26 12:23 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-26 12:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Eric Botcazou
<ebotcazou@gcc.gnu.org>:

https://gcc.gnu.org/g:88661078eac2440fbc2cd5b32ee31cec93f84d08

commit r13-8363-g88661078eac2440fbc2cd5b32ee31cec93f84d08
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Mon Feb 26 13:13:34 2024 +0100

    Finalization of object allocated by anonymous access designating local type

    The finalization of objects dynamically allocated through an anonymous
    access type is deferred to the enclosing library unit in the current
    implementation and a warning is given on each of them.

    However this cannot be done if the designated type is local, because this
    would generate dangling references to the local finalization routine, so
    the finalization needs to be dropped in this case and the warning adjusted.

    gcc/ada/
            PR ada/113893
            * exp_ch7.adb (Build_Anonymous_Master): Do not build the master
            for a local designated type.
            * exp_util.adb (Build_Allocate_Deallocate_Proc): Force Needs_Fin
            to false if no finalization master is attached to an access type
            and assert that it is anonymous in this case.
            * sem_res.adb (Resolve_Allocator): Mention that the object might
            not be finalized at all in the warning given when the type is an
            anonymous access-to-controlled type.

    gcc/testsuite/
            * gnat.dg/access10.adb: New test.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug ada/113893] finalization of object allocated by anonymous access type designating local type
  2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
                   ` (5 preceding siblings ...)
  2024-02-26 12:22 ` cvs-commit at gcc dot gnu.org
@ 2024-02-26 12:23 ` cvs-commit at gcc dot gnu.org
  2024-02-26 12:24 ` cvs-commit at gcc dot gnu.org
  2024-02-26 12:26 ` ebotcazou at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-26 12:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Eric Botcazou
<ebotcazou@gcc.gnu.org>:

https://gcc.gnu.org/g:1a915f6ab52eff19eb3c890a127c6693c8ce4f65

commit r12-10178-g1a915f6ab52eff19eb3c890a127c6693c8ce4f65
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Mon Feb 26 13:13:34 2024 +0100

    Finalization of object allocated by anonymous access designating local type

    The finalization of objects dynamically allocated through an anonymous
    access type is deferred to the enclosing library unit in the current
    implementation and a warning is given on each of them.

    However this cannot be done if the designated type is local, because this
    would generate dangling references to the local finalization routine, so
    the finalization needs to be dropped in this case and the warning adjusted.

    gcc/ada/
            PR ada/113893
            * exp_ch7.adb (Build_Anonymous_Master): Do not build the master
            for a local designated type.
            * exp_util.adb (Build_Allocate_Deallocate_Proc): Force Needs_Fin
            to false if no finalization master is attached to an access type
            and assert that it is anonymous in this case.
            * sem_res.adb (Resolve_Allocator): Mention that the object might
            not be finalized at all in the warning given when the type is an
            anonymous access-to-controlled type.

    gcc/testsuite/
            * gnat.dg/access10.adb: New test.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug ada/113893] finalization of object allocated by anonymous access type designating local type
  2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
                   ` (6 preceding siblings ...)
  2024-02-26 12:23 ` cvs-commit at gcc dot gnu.org
@ 2024-02-26 12:24 ` cvs-commit at gcc dot gnu.org
  2024-02-26 12:26 ` ebotcazou at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-26 12:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Eric Botcazou
<ebotcazou@gcc.gnu.org>:

https://gcc.gnu.org/g:bbf799a972201e82f54ee17dc3bf7a093a98077a

commit r11-11255-gbbf799a972201e82f54ee17dc3bf7a093a98077a
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Mon Feb 26 13:13:34 2024 +0100

    Finalization of object allocated by anonymous access designating local type

    The finalization of objects dynamically allocated through an anonymous
    access type is deferred to the enclosing library unit in the current
    implementation and a warning is given on each of them.

    However this cannot be done if the designated type is local, because this
    would generate dangling references to the local finalization routine, so
    the finalization needs to be dropped in this case and the warning adjusted.

    gcc/ada/
            PR ada/113893
            * exp_ch7.adb (Build_Anonymous_Master): Do not build the master
            for a local designated type.
            * exp_util.adb (Build_Allocate_Deallocate_Proc): Force Needs_Fin
            to false if no finalization master is attached to an access type
            and assert that it is anonymous in this case.
            * sem_res.adb (Resolve_Allocator): Mention that the object might
            not be finalized at all in the warning given when the type is an
            anonymous access-to-controlled type.

    gcc/testsuite/
            * gnat.dg/access10.adb: New test.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug ada/113893] finalization of object allocated by anonymous access type designating local type
  2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
                   ` (7 preceding siblings ...)
  2024-02-26 12:24 ` cvs-commit at gcc dot gnu.org
@ 2024-02-26 12:26 ` ebotcazou at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2024-02-26 12:26 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.5
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #8 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
This should run to completion now.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-02-26 12:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-12 20:35 [Bug ada/113893] New: Finalization exception issue with anonymous access object p.p11 at orange dot fr
2024-02-14 15:54 ` [Bug ada/113893] finalization issue with anonymous access object of local type ebotcazou at gcc dot gnu.org
2024-02-14 15:55 ` ebotcazou at gcc dot gnu.org
2024-02-14 16:13 ` ebotcazou at gcc dot gnu.org
2024-02-14 17:36 ` ebotcazou at gcc dot gnu.org
2024-02-26 12:20 ` [Bug ada/113893] finalization of object allocated by anonymous access type designating " cvs-commit at gcc dot gnu.org
2024-02-26 12:22 ` cvs-commit at gcc dot gnu.org
2024-02-26 12:23 ` cvs-commit at gcc dot gnu.org
2024-02-26 12:24 ` cvs-commit at gcc dot gnu.org
2024-02-26 12:26 ` ebotcazou at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).