public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix spurious error on unchecked conversion to misaligned type
@ 2019-05-27 10:27 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2019-05-27 10:27 UTC (permalink / raw)
  To: gcc-patches

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

This is a regression present on the mainline, 9 and 8 branches.  The compiler 
issues a spurious error on the result of an unchecked conversion used as an 
actual In parameter in a subprogram call, if the destination type is a scalar 
type subject to a clause which gives an alignment lower than the natural one.

Tested on x86_64-suse-linux, applied on the mainline, 9 and 8 branches.


2019-05-27  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/trans.c (Call_to_gnu): Use the unpadded type when
	putting back an intermediate conversion the type of the actuals.


2019-05-27  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/unchecked_convert13.adb: New test.

-- 
Eric Botcazou

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

Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c	(revision 336034)
+++ gcc-interface/trans.c	(revision 336035)
@@ -5354,7 +5354,7 @@ Call_to_gnu (Node_Id gnat_node, tree *gn
 	 since the parent is a procedure call, so put it back here.  Note that
 	 we might have a dummy type here if the actual is the dereference of a
 	 pointer to it, but that's OK if the formal is passed by reference.  */
-      tree gnu_actual_type = gnat_to_gnu_type (Etype (gnat_actual));
+      tree gnu_actual_type = get_unpadded_type (Etype (gnat_actual));
       if (TYPE_IS_DUMMY_P (gnu_actual_type))
 	gcc_assert (is_true_formal_parm && DECL_BY_REF_P (gnu_formal));
       else if (suppress_type_conversion

[-- Attachment #3: unchecked_convert13.adb --]
[-- Type: text/x-adasrc, Size: 531 bytes --]

-- { dg-do compile }

with Ada.Unchecked_Conversion;

procedure Unchecked_Convert13 is

  type B16_T is mod 2 ** 16;
  for B16_T'Size use 16;
  for B16_T'Alignment use 1;

  type Rec_T is record
    A : Short_Integer;
  end record;
  for Rec_T use record
    A at 0 range 0 .. 15;
  end record;
  for Rec_T'Size use 16;

  Rec : constant Rec_T := (A => 0);

  function Rec_To_B16 is new Ada.Unchecked_Conversion (Rec_T, B16_T);

  procedure Nested (B16 : B16_T) is
  begin
    null;
  end;

begin
  Nested (Rec_To_B16 (Rec));
end;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-27 10:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-27 10:27 [Ada] Fix spurious error on unchecked conversion to misaligned type Eric Botcazou

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).