From 236b0552f8fada3afce1bee489b7cf7b631e854e Mon Sep 17 00:00:00 2001 From: ebotcazou Date: Sat, 21 Oct 2017 09:53:50 +0000 Subject: * gcc-interface/utils.c (pad_type_hash): Use hashval_t for hash value. (convert): Do not use an unchecked conversion for converting from a type to another type padding it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253971 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ada/ChangeLog | 6 +++ gcc/ada/gcc-interface/utils.c | 16 ++++--- gcc/testsuite/ChangeLog | 9 ++++ gcc/testsuite/gnat.dg/specs/discr2.ads | 50 ++++++++++++++++++++++ gcc/testsuite/gnat.dg/specs/discr3.ads | 22 ++++++++++ gcc/testsuite/gnat.dg/specs/discr4.ads | 23 ++++++++++ gcc/testsuite/gnat.dg/specs/discr4_pkg.ads | 27 ++++++++++++ gcc/testsuite/gnat.dg/specs/discr_private.ads | 50 ---------------------- .../gnat.dg/specs/discr_record_constant.ads | 22 ---------- 9 files changed, 147 insertions(+), 78 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/specs/discr2.ads create mode 100644 gcc/testsuite/gnat.dg/specs/discr3.ads create mode 100644 gcc/testsuite/gnat.dg/specs/discr4.ads create mode 100644 gcc/testsuite/gnat.dg/specs/discr4_pkg.ads delete mode 100644 gcc/testsuite/gnat.dg/specs/discr_private.ads delete mode 100644 gcc/testsuite/gnat.dg/specs/discr_record_constant.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index dac7791a8e6..308ec70a775 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2017-10-21 Eric Botcazou + + * gcc-interface/utils.c (pad_type_hash): Use hashval_t for hash value. + (convert): Do not use an unchecked conversion for converting from a + type to another type padding it. + 2017-10-20 Doug Rupp * libgnarl/s-osinte__linux.ads (Relative_Timed_Wait): Add variable diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 99453821e41..bfd3388c56a 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -101,7 +101,7 @@ static tree handle_vector_type_attribute (tree *, tree, tree, int, bool *); /* Fake handler for attributes we don't properly support, typically because they'd require dragging a lot of the common-c front-end circuitry. */ -static tree fake_attribute_handler (tree *, tree, tree, int, bool *); +static tree fake_attribute_handler (tree *, tree, tree, int, bool *); /* Table of machine-independent internal attributes for Ada. We support this minimal set of attributes to accommodate the needs of builtins. */ @@ -222,8 +222,9 @@ static GTY((deletable)) tree free_block_chain; /* A hash table of padded types. It is modelled on the generic type hash table in tree.c, which must thus be used as a reference. */ -struct GTY((for_user)) pad_type_hash { - unsigned long hash; +struct GTY((for_user)) pad_type_hash +{ + hashval_t hash; tree type; }; @@ -4249,10 +4250,13 @@ convert (tree type, tree expr) return convert (type, TREE_OPERAND (expr, 0)); /* If the inner type is of self-referential size and the expression type - is a record, do this as an unchecked conversion. But first pad the - expression if possible to have the same size on both sides. */ + is a record, do this as an unchecked conversion unless both types are + essentially the same. But first pad the expression if possible to + have the same size on both sides. */ if (ecode == RECORD_TYPE - && CONTAINS_PLACEHOLDER_P (DECL_SIZE (TYPE_FIELDS (type)))) + && CONTAINS_PLACEHOLDER_P (DECL_SIZE (TYPE_FIELDS (type))) + && TYPE_MAIN_VARIANT (etype) + != TYPE_MAIN_VARIANT (TREE_TYPE (TYPE_FIELDS (type)))) { if (TREE_CODE (TYPE_SIZE (etype)) == INTEGER_CST) expr = convert (maybe_pad_type (etype, TYPE_SIZE (type), 0, Empty, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 12f9f6d98c4..1380165912e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2017-10-21 Eric Botcazou + + * gnat.dg/specs/discr_private.ads: Rename into ... + * gnat.dg/specs/discr2.ads: ...this. + * gnat.dg/specs/discr_record_constant.ads: Rename into... + * gnat.dg/specs/discr3.ads: ...this. + * gnat.dg/specs/discr4.ads: New test. + * gnat.dg/specs/discr4_pkg.ads: New helper. + 2017-10-21 Paul Thomas PR fortran/82586 diff --git a/gcc/testsuite/gnat.dg/specs/discr2.ads b/gcc/testsuite/gnat.dg/specs/discr2.ads new file mode 100644 index 00000000000..f7ece058812 --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/discr2.ads @@ -0,0 +1,50 @@ +-- { dg-do compile } +-- { dg-options "-gnatws" } + +package Discr2 is + + package Dec is + type T_DECIMAL (Prec : Integer := 1) is private; + private + type T_DECIMAL (Prec : Integer := 1) is record + case Prec is + when 1 .. 2 => Value : Integer; + when others => null; + end case; + end record; + end; + + type Value_T is record + Bits : Dec.T_DECIMAL(1); + end record; + for Value_T'size use 88; + + type Value_Entry_T is record + Index : Integer; + Value : Value_T; + end record; + + type Value_Mode is (QI, HI, SI, DI, XI); + for Value_Mode'size use 8; + + type Valid_Modes_T is array (Value_Mode) of Boolean; + + type Register_T is record + Ventry : Value_Entry_T; + Vmodes : Valid_Modes_T; + end record; + + type Regid_T is (Latch, Acc); + for Regid_T use (Latch => 0, Acc => 2); + for Regid_T'Size use 8; + + type Regarray_T is array (Regid_T) of Register_T; + + type Machine_T (Up : Boolean := True) is record + case Up is + when True => Regs : Regarray_T; + when False => null; + end case; + end record; + +end Discr2; diff --git a/gcc/testsuite/gnat.dg/specs/discr3.ads b/gcc/testsuite/gnat.dg/specs/discr3.ads new file mode 100644 index 00000000000..bcb996b7386 --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/discr3.ads @@ -0,0 +1,22 @@ +-- { dg-do compile } + +pragma Restrictions (No_Implicit_Heap_Allocations); + +package Discr3 is + + type T (Big : Boolean := False) is record + case Big is + when True => + Content : Integer; + when False => + null; + end case; + end record; + + D : constant T := (True, 0); + + Var : T := D; -- OK, maximum size + Con : constant T := D; -- Violation of restriction + Ter : constant T := Con; -- Violation of restriction + +end Discr3; diff --git a/gcc/testsuite/gnat.dg/specs/discr4.ads b/gcc/testsuite/gnat.dg/specs/discr4.ads new file mode 100644 index 00000000000..ef9f046abcd --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/discr4.ads @@ -0,0 +1,23 @@ +-- { dg-do compile } +-- { dg-options "-O" } + +with Disc4_Pkg; use Disc4_Pkg; + +package Disc4 is + + type Data is record + Val : Rec; + Set : Boolean; + end record; + + type Pair is record + Lower, Upper : Data; + end record; + + function Build (L, U : Rec) return Pair is ((L, True), (U, False)); + + C1 : constant Pair := Build (Rec_One, Rec_Three); + + C2 : constant Pair := Build (Get (0), Rec_Three); + +end Disc4; diff --git a/gcc/testsuite/gnat.dg/specs/discr4_pkg.ads b/gcc/testsuite/gnat.dg/specs/discr4_pkg.ads new file mode 100644 index 00000000000..4b6c573729d --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/discr4_pkg.ads @@ -0,0 +1,27 @@ +package Disc4_Pkg is + + type Enum is (One, Two, Three); + + type Rec is private; + + Rec_One : constant Rec; + Rec_Three : constant Rec; + + function Get (Value : Integer) return Rec; + +private + + type Rec (D : Enum := Two) is record + case D is + when One => null; + when Two => Value : Integer; + when Three => null; + end case; + end record; + + Rec_One : constant Rec := (D => One); + Rec_Three : constant Rec := (D => Three); + + function Get (Value : Integer) return Rec is (Two, Value); + +end Disc4_Pkg; diff --git a/gcc/testsuite/gnat.dg/specs/discr_private.ads b/gcc/testsuite/gnat.dg/specs/discr_private.ads deleted file mode 100644 index 0ddfbd137ff..00000000000 --- a/gcc/testsuite/gnat.dg/specs/discr_private.ads +++ /dev/null @@ -1,50 +0,0 @@ --- { dg-do compile } --- { dg-options "-gnatws" } - -package Discr_Private is - - package Dec is - type T_DECIMAL (Prec : Integer := 1) is private; - private - type T_DECIMAL (Prec : Integer := 1) is record - case Prec is - when 1 .. 2 => Value : Integer; - when others => null; - end case; - end record; - end; - - type Value_T is record - Bits : Dec.T_DECIMAL(1); - end record; - for Value_T'size use 88; - - type Value_Entry_T is record - Index : Integer; - Value : Value_T; - end record; - - type Value_Mode is (QI, HI, SI, DI, XI); - for Value_Mode'size use 8; - - type Valid_Modes_T is array (Value_Mode) of Boolean; - - type Register_T is record - Ventry : Value_Entry_T; - Vmodes : Valid_Modes_T; - end record; - - type Regid_T is (Latch, Acc); - for Regid_T use (Latch => 0, Acc => 2); - for Regid_T'Size use 8; - - type Regarray_T is array (Regid_T) of Register_T; - - type Machine_T (Up : Boolean := True) is record - case Up is - when True => Regs : Regarray_T; - when False => null; - end case; - end record; - -end Discr_Private; diff --git a/gcc/testsuite/gnat.dg/specs/discr_record_constant.ads b/gcc/testsuite/gnat.dg/specs/discr_record_constant.ads deleted file mode 100644 index f43b1386909..00000000000 --- a/gcc/testsuite/gnat.dg/specs/discr_record_constant.ads +++ /dev/null @@ -1,22 +0,0 @@ --- { dg-do compile } - -pragma Restrictions (No_Implicit_Heap_Allocations); - -package Discr_Record_Constant is - - type T (Big : Boolean := False) is record - case Big is - when True => - Content : Integer; - when False => - null; - end case; - end record; - - D : constant T := (True, 0); - - Var : T := D; -- OK, maximum size - Con : constant T := D; -- Violation of restriction - Ter : constant T := Con; -- Violation of restriction - -end Discr_Record_Constant; -- cgit v1.2.1