From: Eric Botcazou Date: Mon, 12 Aug 2019 09:01:38 +0000 (+0000) Subject: [Ada] Small comment tweaks for 3 predicates on bit-aligned references X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fba9fcae321660fdc760fd293d92970e52489706;p=gcc.git [Ada] Small comment tweaks for 3 predicates on bit-aligned references They fix a few glitches left and right. No functional changes. 2019-08-12 Eric Botcazou gcc/ada/ * exp_util.ads (Component_May_Be_Bit_Aligned): Small comment tweaks. (Possible_Bit_Aligned_Component): Likewise. (Type_May_Have_Bit_Aligned_Components): Likewise. * exp_util.adb (Component_May_Be_Bit_Aligned): Likewise. (Possible_Bit_Aligned_Component): Likewise. (Type_May_Have_Bit_Aligned_Components): Likewise. From-SVN: r274304 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index fa543dfb803..64f4c6bb9ac 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,13 @@ +2019-08-12 Eric Botcazou + + * exp_util.ads (Component_May_Be_Bit_Aligned): Small comment + tweaks. + (Possible_Bit_Aligned_Component): Likewise. + (Type_May_Have_Bit_Aligned_Components): Likewise. + * exp_util.adb (Component_May_Be_Bit_Aligned): Likewise. + (Possible_Bit_Aligned_Component): Likewise. + (Type_May_Have_Bit_Aligned_Components): Likewise. + 2019-08-12 Eric Botcazou * exp_ch4.adb (Expand_N_Op_Eq): Expand the array equality if diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 2a3132b0605..41708c3097f 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -4444,8 +4444,8 @@ package body Exp_Util is begin -- If no component clause, then everything is fine, since the back end - -- never bit-misaligns by default, even if there is a pragma Packed for - -- the record. + -- never misaligns from byte boundaries by default, even if there is a + -- pragma Pack for the record. if No (Comp) or else No (Component_Clause (Comp)) then return False; @@ -10707,9 +10707,9 @@ package body Exp_Util is Ptyp : constant Entity_Id := Etype (P); begin - -- If we know the component size and it is less than 64, then - -- we are definitely OK. The back end always does assignment of - -- misaligned small objects correctly. + -- If we know the component size and it is not larger than 64, + -- then we are definitely OK. The back end does the assignment + -- of misaligned small objects correctly. if Known_Static_Component_Size (Ptyp) and then Component_Size (Ptyp) <= 64 @@ -10732,13 +10732,15 @@ package body Exp_Util is Comp : constant Entity_Id := Entity (Selector_Name (N)); begin - -- If there is no component clause, then we are in the clear - -- since the back end will never misalign a large component - -- unless it is forced to do so. In the clear means we need - -- only the recursive test on the prefix. + -- This is the crucial test: if the component itself causes + -- trouble, then we can stop and return True. if Component_May_Be_Bit_Aligned (Comp) then return True; + + -- Otherwise, we need to test the prefix, to see if we are + -- selecting from a possibly unaligned component. + else return Possible_Bit_Aligned_Component (P); end if; @@ -10751,7 +10753,7 @@ package body Exp_Util is return Possible_Bit_Aligned_Component (Prefix (N)); -- For an unchecked conversion, check whether the expression may - -- be bit-aligned. + -- be bit aligned. when N_Unchecked_Type_Conversion => return Possible_Bit_Aligned_Component (Expression (N)); @@ -13505,9 +13507,17 @@ package body Exp_Util is begin E := First_Component_Or_Discriminant (Typ); while Present (E) loop - if Component_May_Be_Bit_Aligned (E) - or else Type_May_Have_Bit_Aligned_Components (Etype (E)) - then + -- This is the crucial test: if the component itself causes + -- trouble, then we can stop and return True. + + if Component_May_Be_Bit_Aligned (E) then + return True; + end if; + + -- Otherwise, we need to test its type, to see if it may + -- itself contain a troublesome component. + + if Type_May_Have_Bit_Aligned_Components (Etype (E)) then return True; end if; diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads index c0848c7c65d..30a3c71bd90 100644 --- a/gcc/ada/exp_util.ads +++ b/gcc/ada/exp_util.ads @@ -401,32 +401,27 @@ package Exp_Util is -- case overflow. function Component_May_Be_Bit_Aligned (Comp : Entity_Id) return Boolean; - -- This function is in charge of detecting record components that may - -- cause trouble in the back end if an attempt is made to assign the - -- component. The back end can handle such assignments with no problem if - -- the components involved are small (64-bits or less) records or scalar - -- items (including bit-packed arrays represented with modular types) or - -- are both aligned on a byte boundary (starting on a byte boundary, and - -- occupying an integral number of bytes). + -- This function is in charge of detecting record components that may cause + -- trouble for the back end if an attempt is made to access the component + -- as a whole. The back end can handle such accesses with no problem if the + -- components involved are small (64 bits or less) records or scalar items + -- (including bit-packed arrays represented with a modular type), or else + -- if they are aligned on byte boundaries (i.e. starting on a byte boundary + -- and occupying an integral number of bytes). -- -- However, problems arise for records larger than 64 bits, or for arrays -- (other than bit-packed arrays represented with a modular type) if the - -- component starts on a non-byte boundary, or does not occupy an integral - -- number of bytes (i.e. there are some bits possibly shared with fields - -- at the start or beginning of the component). The back end cannot handle - -- loading and storing such components in a single operation. + -- component either does not start on a byte boundary or does not occupy an + -- integral number of bytes (i.e. there are some bits possibly shared with + -- other components at the start or the end of the component). The back end + -- cannot handle loading from or storing to such components as a whole. -- - -- This function is used to detect the troublesome situation. it is - -- conservative in the sense that it produces True unless it knows for - -- sure that the component is safe (as outlined in the first paragraph - -- above). The code generation for record and array assignment checks for - -- trouble using this function, and if so the assignment is generated + -- This function is used to detect the troublesome situation. It is meant + -- to be conservative in the sense that it produces True unless it knows + -- for sure that the component is safe (as outlined in the first paragraph + -- above). The processing for record and array assignment indirectly checks + -- for trouble using this function and, if so, the assignment is expanded -- component-wise, which the back end is required to handle correctly. - -- - -- Note that in GNAT 3, the back end will reject such components anyway, - -- so the hard work in checking for this case is wasted in GNAT 3, but - -- it is harmless, so it is easier to do it in all cases, rather than - -- conditionalize it in GNAT 5 or beyond. function Containing_Package_With_Ext_Axioms (E : Entity_Id) return Entity_Id; @@ -962,12 +957,12 @@ package Exp_Util is -- returned only if the replacement is safe. function Possible_Bit_Aligned_Component (N : Node_Id) return Boolean; - -- This function is used during processing the assignment of a record or - -- indexed component. The argument N is either the left hand or right hand - -- side of an assignment, and this function determines if there is a record - -- component reference where the record may be bit aligned in a manner that - -- causes trouble for the back end (see Component_May_Be_Bit_Aligned for - -- further details). + -- This function is used during processing the assignment of a record or an + -- array, or the construction of an aggregate. The argument N is either the + -- left or the right hand side of an assignment and the function determines + -- whether there is a record component reference where the component may be + -- bit aligned in a manner that causes trouble for the back end (see also + -- Component_May_Be_Bit_Aligned for further details). function Power_Of_Two (N : Node_Id) return Nat; -- Determines if N is a known at compile time value which is of the form @@ -1170,8 +1165,9 @@ package Exp_Util is function Type_May_Have_Bit_Aligned_Components (Typ : Entity_Id) return Boolean; -- Determines if Typ is a composite type that has within it (looking down - -- recursively at any subcomponents), a record type which has component - -- that may be bit aligned (see Possible_Bit_Aligned_Component). The result + -- recursively at subcomponents) a record which contains a component that + -- may be bit aligned in a manner that causes trouble for the back end + -- (see also Component_May_Be_Bit_Aligned for further details). The result -- is conservative, in that a result of False is decisive. A result of True -- means that such a component may or may not be present.