public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marc Poulhi?s <dkm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r15-185] ada: Fix wrong Finalization_Size for No_Heap_Finalization objects
Date: Mon,  6 May 2024 09:16:42 +0000 (GMT)	[thread overview]
Message-ID: <20240506091642.9F65E3858C78@sourceware.org> (raw)

https://gcc.gnu.org/g:3862106d3506293ad5af2fc04d2d21ef3a5e0edf

commit r15-185-g3862106d3506293ad5af2fc04d2d21ef3a5e0edf
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Sat Dec 16 11:34:48 2023 +0100

    ada: Fix wrong Finalization_Size for No_Heap_Finalization objects
    
    When an access type is subject to the No_Heap_Finalization pragma, no header
    is added in front of objects allocated through it, and the value returned by
    Finalization_Size is defined to be the size of this header.
    
    gcc/ada/
    
            * exp_attr.adb (Expand_N_Attribute_Reference) <Finalization_Size>:
            Return 0 if the prefix is a dereference of an access value subject
            to the No_Heap_Finalization pragma.

Diff:
---
 gcc/ada/exp_attr.adb | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 614f1fbe14d..a8e06f0005e 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -3563,6 +3563,14 @@ package body Exp_Attr is
       --  Start of processing for Finalization_Size
 
       begin
+         --  If the prefix is the dereference of an access value subject to
+         --  pragma No_Heap_Finalization, then no header has been added.
+
+         if Nkind (Pref) = N_Explicit_Dereference
+           and then No_Heap_Finalization (Etype (Prefix (Pref)))
+         then
+            Rewrite (N, Make_Integer_Literal (Loc, 0));
+
          --  An object of a class-wide type first requires a runtime check to
          --  determine whether it is actually controlled or not. Depending on
          --  the outcome of this check, the Finalization_Size of the object
@@ -3578,7 +3586,7 @@ package body Exp_Attr is
          --
          --  and the attribute reference is replaced with a reference to Size.
 
-         if Is_Class_Wide_Type (Ptyp) then
+         elsif Is_Class_Wide_Type (Ptyp) then
             Size := Make_Temporary (Loc, 'S');
 
             Insert_Actions (N, New_List (

                 reply	other threads:[~2024-05-06  9:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240506091642.9F65E3858C78@sourceware.org \
    --to=dkm@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).