[Ada] Add No_Truncation flag on view conversion for GNAT-LLVM

Message ID 20200605122338.GA56590@adacore.com
State New
Headers show
Series
  • [Ada] Add No_Truncation flag on view conversion for GNAT-LLVM
Related show

Commit Message

Pierre-Marie de Rodat June 5, 2020, 12:23 p.m.
This puts the No_Truncation flag on the unchecked conversion built for
converting between the prefix of 'Valid_Scalars and the view of its type
as returned by Validated_View for scalar types.  This is needed in order
to prevent GNAT-LLVM from masking out the bits outside the RM size of
the prefix, which is required here.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-05  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* exp_attr.adb (Expand_N_Attribute_Reference) <Valid_Scalars>:
	Set the No_Truncation flag on the unchecked conversion built for
	scalar types.

Patch

--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -7185,6 +7185,12 @@  package body Exp_Attr is
                   Unchecked_Convert_To (Val_Typ, New_Copy_Tree (Pref)),
                 Attribute_Name => Name_Valid);
 
+            --  Required by LLVM although the sizes are the same???
+
+            if Nkind (Prefix (Expr)) = N_Unchecked_Type_Conversion then
+               Set_No_Truncation (Prefix (Expr));
+            end if;
+
          --  Validate the scalar components of an array by iterating over all
          --  dimensions of the array while checking individual components.