public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Couple of adjustments to special return mechanism
Date: Fri, 19 Jun 2015 20:16:00 -0000	[thread overview]
Message-ID: <3310687.np76IbU8Td@polaris> (raw)

[-- Attachment #1: Type: text/plain, Size: 700 bytes --]

Functions that return a discriminated record types with default discriminant 
are handled specially, in the sense that the caller and the callee don't see 
the same size for the return value (the former seeing the larger one).  The 
attached patch makes a couple of adjustments to this support.

Tested on x86_64-suse-linux, applied on the mainline.


2015-06-19  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Function>: Make sure
	the size of a padding type built around the return type is positive.
	* gcc-interface/trans.c (gnat_to_gnu) <N_Simple_Return_Statement>:
	Use INIT_EXPR instead of MODIFY_EXPR to assign to the return object.


-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 1806 bytes --]

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 224602)
+++ gcc-interface/decl.c	(working copy)
@@ -4242,12 +4242,23 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	    if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_return_type)))
 	      {
 		tree orig_type = gnu_return_type;
+		tree max_return_size
+		  = max_size (TYPE_SIZE (gnu_return_type), true);
+
+		/* If the size overflows to 0, set it to an arbitrary positive
+		   value so that assignments in the type are preserved.  Their
+		   actual size is independent of this positive value.  */
+		if (TREE_CODE (max_return_size) == INTEGER_CST
+		    && TREE_OVERFLOW (max_return_size)
+		    && integer_zerop (max_return_size))
+		  {
+		    max_return_size = copy_node (bitsize_unit_node);
+		    TREE_OVERFLOW (max_return_size) = 1;
+		  }
 
 		gnu_return_type
-		  = maybe_pad_type (gnu_return_type,
-				    max_size (TYPE_SIZE (gnu_return_type),
-					      true),
-				    0, gnat_entity, false, false, definition,
+		  = maybe_pad_type (gnu_return_type, max_return_size, 0,
+				    gnat_entity, false, false, definition,
 				    true);
 
 		/* Declare it now since it will never be declared otherwise.
Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c	(revision 224602)
+++ gcc-interface/trans.c	(working copy)
@@ -6861,7 +6861,7 @@ gnat_to_gnu (Node_Id gnat_node)
 		tree gnu_ret_deref
 		  = build_unary_op (INDIRECT_REF, TREE_TYPE (gnu_ret_val),
 				    gnu_ret_obj);
-		gnu_result = build2 (MODIFY_EXPR, void_type_node,
+		gnu_result = build2 (INIT_EXPR, void_type_node,
 				     gnu_ret_deref, gnu_ret_val);
 		add_stmt_with_node (gnu_result, gnat_node);
 		gnu_ret_val = NULL_TREE;

                 reply	other threads:[~2015-06-19 20:11 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=3310687.np76IbU8Td@polaris \
    --to=ebotcazou@adacore.com \
    --cc=gcc-patches@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).