From d110c3ed97ac3a7083fa32f7f1f53984ebdf1d92 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Wed, 15 Oct 2014 10:24:36 +0000 Subject: [PATCH] * stor-layout.c (self_referential_size): Do not promote arguments. From-SVN: r216249 --- gcc/ChangeLog | 4 +++ gcc/stor-layout.c | 7 +--- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gnat.dg/opt41.adb | 15 ++++++++ gcc/testsuite/gnat.dg/opt41_pkg.adb | 53 +++++++++++++++++++++++++++++ gcc/testsuite/gnat.dg/opt41_pkg.ads | 28 +++++++++++++++ 6 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/opt41.adb create mode 100644 gcc/testsuite/gnat.dg/opt41_pkg.adb create mode 100644 gcc/testsuite/gnat.dg/opt41_pkg.ads diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9c3dcf4a6d1..5bc3571e39f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2014-10-15 Eric Botcazou + + * stor-layout.c (self_referential_size): Do not promote arguments. + 2014-10-15 Marek Polacek * doc/invoke.texi: Update to reflect that GNU11 is the default diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index c7b524c574c..a95722ac10e 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -211,12 +211,7 @@ self_referential_size (tree size) param_type = TREE_TYPE (ref); param_decl = build_decl (input_location, PARM_DECL, param_name, param_type); - if (targetm.calls.promote_prototypes (NULL_TREE) - && INTEGRAL_TYPE_P (param_type) - && TYPE_PRECISION (param_type) < TYPE_PRECISION (integer_type_node)) - DECL_ARG_TYPE (param_decl) = integer_type_node; - else - DECL_ARG_TYPE (param_decl) = param_type; + DECL_ARG_TYPE (param_decl) = param_type; DECL_ARTIFICIAL (param_decl) = 1; TREE_READONLY (param_decl) = 1; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 65cb5fdc77b..fb25dae6f94 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-10-15 Eric Botcazou + + * gnat.dg/opt41.adb: New test. + * gnat.dg/opt41_pkg.ad[sb]: New helper. + 2014-10-15 Richard Biener * g++.dg/torture/pr63419.C: Add -Wno-psabi. diff --git a/gcc/testsuite/gnat.dg/opt41.adb b/gcc/testsuite/gnat.dg/opt41.adb new file mode 100644 index 00000000000..21660431c50 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt41.adb @@ -0,0 +1,15 @@ +-- { dg-do run } +-- { dg-options "-Os" } + +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with Opt41_Pkg; use Opt41_Pkg; + +procedure Opt41 is + R : Rec := (Five, To_Unbounded_String ("CONFIG")); + SP : String_Access := new String'(To_String (Rec_Write (R))); + RP : Rec_Ptr := new Rec'(Rec_Read (SP)); +begin + if RP.D /= R.D then + raise Program_Error; + end if; +end; diff --git a/gcc/testsuite/gnat.dg/opt41_pkg.adb b/gcc/testsuite/gnat.dg/opt41_pkg.adb new file mode 100644 index 00000000000..c43c1bfdf04 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt41_pkg.adb @@ -0,0 +1,53 @@ +with Ada.Streams; use Ada.Streams; + +package body Opt41_Pkg is + + type Wstream is new Root_Stream_Type with record + S : Unbounded_String; + end record; + + procedure Read (Stream : in out Wstream; + Item : out Stream_Element_Array; + Last : out Stream_Element_Offset) is null; + + procedure Write (Stream : in out Wstream; Item : Stream_Element_Array) is + begin + for J in Item'Range loop + Append (Stream.S, Character'Val (Item (J))); + end loop; + end Write; + + function Rec_Write (R : Rec) return Unbounded_String is + S : aliased Wstream; + begin + Rec'Output (S'Access, R); + return S.S; + end Rec_Write; + + type Rstream is new Root_Stream_Type with record + S : String_Access; + Idx : Integer := 1; + end record; + + procedure Write (Stream : in out Rstream; Item : Stream_Element_Array) is null; + + procedure Read (Stream : in out Rstream; + Item : out Stream_Element_Array; + Last : out Stream_Element_Offset) is + begin + Last := Stream_Element_Offset'Min + (Item'Last, Item'First + Stream_Element_Offset (Stream.S'Last - Stream.Idx)); + for I in Item'First .. Last loop + Item (I) := Stream_Element (Character'Pos (Stream.S (Stream.Idx))); + Stream.Idx := Stream.Idx + 1; + end loop; + end Read; + + function Rec_Read (Str : String_Access) return Rec is + S : aliased Rstream; + begin + S.S := Str; + return Rec'Input (S'Access); + end Rec_Read; + +end Opt41_Pkg; diff --git a/gcc/testsuite/gnat.dg/opt41_pkg.ads b/gcc/testsuite/gnat.dg/opt41_pkg.ads new file mode 100644 index 00000000000..e73bc931927 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt41_pkg.ads @@ -0,0 +1,28 @@ +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; + +package Opt41_Pkg is + + type Enum is (One, Two, Three, Four, Five, Six); + + type Rec (D : Enum) is record + case D is + when One => + I : Integer; + when Two | Five | Six => + S : Unbounded_String; + case D is + when Two => B : Boolean; + when others => null; + end case; + when others => + null; + end case; + end record; + + type Rec_Ptr is access all Rec; + + function Rec_Write (R : Rec) return Unbounded_String; + + function Rec_Read (Str : String_Access) return Rec; + +end Opt41_Pkg; -- 2.30.2