diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2018-05-31 10:45:57 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-05-31 10:45:57 +0000 |
commit | 42e4b796dccc43e0a30cd26186037f3fda7639fd (patch) | |
tree | 8b5c16ea50b86b6a95926011662787278726e603 | |
parent | 59f7c7167a75bdb3992f2c7fb3b358124aea8404 (diff) | |
download | gcc-42e4b796dccc43e0a30cd26186037f3fda7639fd.zip gcc-42e4b796dccc43e0a30cd26186037f3fda7639fd.tar.gz gcc-42e4b796dccc43e0a30cd26186037f3fda7639fd.tar.bz2 |
[Ada] Post warning on object size clause for subtype
This ensures that a warning for an object size clause present on a subtype
is posted on the clause and not on a size clause present on the type.
2018-05-31 Eric Botcazou <ebotcazou@adacore.com>
gcc/ada/
* einfo.ads (Object_Size_Clause): Declare.
* einfo.adb (Object_Size_Clause): New function.
* gcc-interface/utils.c (maybe_pad_type): Test Has_Size_Clause before
retrieving Size_Clause and post the warning on the object size clause
if Has_Object_Size_Clause is true.
gcc/testsuite/
* gnat.dg/size_clause1.adb: New testcase.
From-SVN: r260998
-rw-r--r-- | gcc/ada/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/ada/einfo.adb | 9 | ||||
-rw-r--r-- | gcc/ada/einfo.ads | 13 | ||||
-rw-r--r-- | gcc/ada/gcc-interface/utils.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/size_clause1.adb | 11 |
6 files changed, 50 insertions, 3 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index cec6c39..587516c 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2018-05-31 Eric Botcazou <ebotcazou@adacore.com> + + * einfo.ads (Object_Size_Clause): Declare. + * einfo.adb (Object_Size_Clause): New function. + * gcc-interface/utils.c (maybe_pad_type): Test Has_Size_Clause before + retrieving Size_Clause and post the warning on the object size clause + if Has_Object_Size_Clause is true. + 2018-05-31 Javier Miranda <miranda@adacore.com> * sem_util.ads, sem_util.adb (Find_Primitive_Eq): New subprogram. diff --git a/gcc/ada/einfo.adb b/gcc/ada/einfo.adb index 320b167..c41dc30 100644 --- a/gcc/ada/einfo.adb +++ b/gcc/ada/einfo.adb @@ -8755,6 +8755,15 @@ package body Einfo is return N; end Number_Formals; + ------------------------ + -- Object_Size_Clause -- + ------------------------ + + function Object_Size_Clause (Id : E) return N is + begin + return Get_Attribute_Definition_Clause (Id, Attribute_Object_Size); + end Object_Size_Clause; + -------------------- -- Parameter_Mode -- -------------------- diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index 9a7206f..2df6497 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -1828,7 +1828,7 @@ package Einfo is -- Has_Object_Size_Clause (Flag172) -- Defined in entities for types and subtypes. Set if an Object_Size --- clause has been processed for the type Used to prevent multiple +-- clause has been processed for the type. Used to prevent multiple -- Object_Size clauses for a given entity. -- Has_Out_Or_In_Out_Parameter (Flag110) @@ -3753,6 +3753,15 @@ package Einfo is -- Applies to subprograms and subprogram types. Yields the number of -- formals as a value of type Pos. +-- Object_Size_Clause (synthesized) +-- Applies to entities for types and subtypes. If an object size clause +-- is present in the rep item chain for an entity then the attribute +-- definition clause node is returned. Otherwise Object_Size_Clause +-- returns Empty if no item is present. Usually this is only meaningful +-- if the flag Has_Object_Size_Clause is set. This is because when the +-- representation item chain is copied for a derived type, it can inherit +-- an object size clause that is not applicable to the entity. + -- OK_To_Rename (Flag247) -- Defined only in entities for variables. If this flag is set, it -- means that if the entity is used as the initial value of an object @@ -5782,6 +5791,7 @@ package Einfo is -- Is_Access_Protected_Subprogram_Type (synth) -- Is_Atomic_Or_VFA (synth) -- Is_Controlled (synth) + -- Object_Size_Clause (synth) -- Partial_Invariant_Procedure (synth) -- Predicate_Function (synth) -- Predicate_Function_M (synth) @@ -7673,6 +7683,7 @@ package Einfo is function Number_Dimensions (Id : E) return Pos; function Number_Entries (Id : E) return Nat; function Number_Formals (Id : E) return Pos; + function Object_Size_Clause (Id : E) return N; function Parameter_Mode (Id : E) return Formal_Kind; function Partial_Refinement_Constituents (Id : E) return L; function Primitive_Operations (Id : E) return L; diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index cc25973..7de76637 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -1507,7 +1507,7 @@ built: || TREE_OVERFLOW (orig_size) || tree_int_cst_lt (size, orig_size)))) { - Node_Id gnat_error_node = Empty; + Node_Id gnat_error_node; /* For a packed array, post the message on the original array type. */ if (Is_Packed_Array_Impl_Type (gnat_entity)) @@ -1517,8 +1517,12 @@ built: || Ekind (gnat_entity) == E_Discriminant) && Present (Component_Clause (gnat_entity))) gnat_error_node = Last_Bit (Component_Clause (gnat_entity)); - else if (Present (Size_Clause (gnat_entity))) + else if (Has_Size_Clause (gnat_entity)) gnat_error_node = Expression (Size_Clause (gnat_entity)); + else if (Has_Object_Size_Clause (gnat_entity)) + gnat_error_node = Expression (Object_Size_Clause (gnat_entity)); + else + gnat_error_node = Empty; /* Generate message only for entities that come from source, since if we have an entity created by expansion, the message will be diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d5f177e..0c7a85d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-05-31 Eric Botcazou <ebotcazou@adacore.com> + + * gnat.dg/size_clause1.adb: New testcase. + 2018-05-31 Javier Miranda <miranda@adacore.com> * gnat.dg/tagged1.adb, gnat.dg/tagged1.ads: New testcase. diff --git a/gcc/testsuite/gnat.dg/size_clause1.adb b/gcc/testsuite/gnat.dg/size_clause1.adb new file mode 100644 index 0000000..fc090eb --- /dev/null +++ b/gcc/testsuite/gnat.dg/size_clause1.adb @@ -0,0 +1,11 @@ +procedure Size_Clause1 is + + type Modular is mod 2**64; + for Modular'Size use 64; + + subtype Enlarged_Modular is Modular; + for Enlarged_Modular'Object_Size use 128; -- { dg-warning "warning: 64 bits of \"Enlarged_Modular\" unused" } + +begin + null; +end Size_Clause1; |