diff options
author | Arnaud Charlet <charlet@gcc.gnu.org> | 2014-08-01 15:46:29 +0200 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2014-08-01 15:46:29 +0200 |
commit | 1eb5852081801218c02c934db5aa9852fc284645 (patch) | |
tree | 17c3243a6166917936352164905bb90a504297ef /gcc/ada/gcc-interface/utils.c | |
parent | ecda544d41f26433d80a0632c09dec07fd2a8dfd (diff) | |
download | gcc-1eb5852081801218c02c934db5aa9852fc284645.zip gcc-1eb5852081801218c02c934db5aa9852fc284645.tar.gz gcc-1eb5852081801218c02c934db5aa9852fc284645.tar.bz2 |
ada-tree.h (DECL_BY_DESCRIPTOR_P): Delete.
2014-08-01 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/ada-tree.h (DECL_BY_DESCRIPTOR_P): Delete.
(DECL_FUNCTION_STUB): Likewise.
(SET_DECL_FUNCTION_STUB): Likewise.
(DECL_PARM_ALT_TYPE): Likewise.
(SET_DECL_PARM_ALT_TYPE): Likewise.
(TYPE_VAX_FLOATING_POINT_P): Delete.
(TYPE_DIGITS_VALUE): Likewise.
(SET_TYPE_DIGITS_VALUE): Likewise.
* gcc-interface/gigi.h (standard_datatypes): Remove ADT_malloc32_decl.
(malloc32_decl): Delete.
(build_vms_descriptor): Likewise.
(build_vms_descriptor32): Likewise.
(fill_vms_descriptor): Likewise.
(convert_vms_descriptor): Likewise.
(TARGET_ABI_OPEN_VMS): Likewise.
(TARGET_MALLOC64): Likewise.
* gcc-interface/decl.c (add_parallel_type_for_packed_array): New.
(gnat_to_gnu_entity): Call it to add the original type as a parallel
type to the implementation type of a packed array type.
<E_Procedure>: Remove now obsolete kludge.
<E_Exception>: Delete obsolete comment.
<object>: Small tweak.
<E_Subprogram_Type>: Remove support for stub subprograms, as well as
for the descriptor passing mechanism.
(gnat_to_gnu_param): Likewise.
* gcc-interface/misc.c (gnat_init_gcc_fp): Remove special case.
(gnat_print_type): Adjust.
* gcc-interface/trans.c (gigi): Remove obsolete initializations.
(vms_builtin_establish_handler_decl): Delete.
(gnat_vms_condition_handler_decl): Likewise.
(establish_gnat_vms_condition_handler): Likewise.
(build_function_stub): Likewise.
(Subprogram_Body_to_gnu): Do not call above functions.
(Call_to_gnu): Remove support for the descriptor passing mechanism.
* gcc-interface/utils.c (make_descriptor_field): Delete.
(build_vms_descriptor32): Likewise.
(build_vms_descriptor): Likewise.
(fill_vms_descriptor): Likewise.
(convert_vms_descriptor64): Likewise.
(convert_vms_descriptor32): Likewise.
(convert_vms_descriptor): Likewise.
* gcc-interface/utils.c (unchecked_convert): Likewise.
* gcc-interface/utils2.c (maybe_wrap_malloc): Remove obsolete stuff.
2014-08-01 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/trans.c (gigi): Use gnat_to_gnu_type for the exception
type and get_unpadded_type for the longest FP type.
(Attribute_to_gnu) <Machine>: Compare the precision of the types.
(convert_with_check): Adjust formatting and remove FIXME.
2014-08-01 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Signed_Integer_Subtype>:
Do not convert the RM bounds to the base type.
(E_Floating_Point_Subtype): Likewise.
(E_Array_Subtype): Convert the bounds to the base type.
* gcc-interface/trans.c (get_type_length): New function.
(Attribute_to_gnu) <Range_Length>: Call it.
<Length>: Likewise.
(Loop_Statement_to_gnu): Convert the bounds to the base type.
(gnat_to_gnu) <N_In>: Likewise.
* gcc-interface/utils.c (make_type_from_size): Do not convert the RM
bounds to the base type.
(create_range_type): Likewise.
(convert): Convert the bounds to the base type for biased types.
* gcc-interface/utils2.c (compare_arrays): Convert the bounds to the
base type.
2014-08-01 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/trans.c (gnat_to_gnu) <N_Selected_Component>: Remove
incorrect implicit type derivation.
* gcc-interface/utils.c (max_size) <tcc_reference>: Convert the bounds
to the base type.
From-SVN: r213462
Diffstat (limited to 'gcc/ada/gcc-interface/utils.c')
-rw-r--r-- | gcc/ada/gcc-interface/utils.c | 1002 |
1 files changed, 22 insertions, 980 deletions
diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index b26d217..f450f24 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -954,12 +954,8 @@ make_type_from_size (tree type, tree size_tree, bool for_biased) else new_type = make_signed_type (size); TREE_TYPE (new_type) = TREE_TYPE (type) ? TREE_TYPE (type) : type; - SET_TYPE_RM_MIN_VALUE (new_type, - convert (TREE_TYPE (new_type), - TYPE_MIN_VALUE (type))); - SET_TYPE_RM_MAX_VALUE (new_type, - convert (TREE_TYPE (new_type), - TYPE_MAX_VALUE (type))); + SET_TYPE_RM_MIN_VALUE (new_type, TYPE_MIN_VALUE (type)); + SET_TYPE_RM_MAX_VALUE (new_type, TYPE_MAX_VALUE (type)); /* Copy the name to show that it's essentially the same type and not a subrange type. */ TYPE_NAME (new_type) = TYPE_NAME (type); @@ -2051,8 +2047,8 @@ create_range_type (tree type, tree min, tree max) TYPE_MAX_VALUE (type)); /* Then set the actual range. */ - SET_TYPE_RM_MIN_VALUE (range_type, convert (type, min)); - SET_TYPE_RM_MAX_VALUE (range_type, convert (type, max)); + SET_TYPE_RM_MIN_VALUE (range_type, min); + SET_TYPE_RM_MAX_VALUE (range_type, max); return range_type; } @@ -2734,10 +2730,11 @@ create_subprog_decl (tree subprog_name, tree asm_name, tree subprog_type, case is_required: if (Back_End_Inlining) - decl_attributes (&subprog_decl, - tree_cons (get_identifier ("always_inline"), - NULL_TREE, NULL_TREE), - ATTR_FLAG_TYPE_IN_PLACE); + decl_attributes (&subprog_decl, + tree_cons (get_identifier ("always_inline"), + NULL_TREE, NULL_TREE), + ATTR_FLAG_TYPE_IN_PLACE); + /* ... fall through ... */ case is_enabled: @@ -3108,12 +3105,14 @@ max_size (tree exp, bool max_p) case tcc_reference: /* If this contains a PLACEHOLDER_EXPR, it is the thing we want to modify. Otherwise, we treat it like a variable. */ - if (!CONTAINS_PLACEHOLDER_P (exp)) - return exp; + if (CONTAINS_PLACEHOLDER_P (exp)) + { + tree val_type = TREE_TYPE (TREE_OPERAND (exp, 1)); + tree val = (max_p ? TYPE_MAX_VALUE (type) : TYPE_MIN_VALUE (type)); + return max_size (convert (get_base_type (val_type), val), true); + } - type = TREE_TYPE (TREE_OPERAND (exp, 1)); - return - max_size (max_p ? TYPE_MAX_VALUE (type) : TYPE_MIN_VALUE (type), true); + return exp; case tcc_comparison: return max_p ? size_one_node : size_zero_node; @@ -3343,962 +3342,6 @@ build_vector_type_for_array (tree array_type, tree attribute) return vector_type; } -/* Helper routine to make a descriptor field. FIELD_LIST is the list of decls - being built; the new decl is chained on to the front of the list. */ - -static tree -make_descriptor_field (const char *name, tree type, tree rec_type, - tree initial, tree field_list) -{ - tree field - = create_field_decl (get_identifier (name), type, rec_type, NULL_TREE, - NULL_TREE, 0, 0); - - DECL_INITIAL (field) = initial; - DECL_CHAIN (field) = field_list; - return field; -} - -/* Build a 32-bit VMS descriptor from a Mechanism_Type, which must specify a - descriptor type, and the GCC type of an object. Each FIELD_DECL in the - type contains in its DECL_INITIAL the expression to use when a constructor - is made for the type. GNAT_ENTITY is an entity used to print out an error - message if the mechanism cannot be applied to an object of that type and - also for the name. */ - -tree -build_vms_descriptor32 (tree type, Mechanism_Type mech, Entity_Id gnat_entity) -{ - tree record_type = make_node (RECORD_TYPE); - tree pointer32_type, pointer64_type; - tree field_list = NULL_TREE; - int klass, ndim, i, dtype = 0; - tree inner_type, tem; - tree *idx_arr; - - /* If TYPE is an unconstrained array, use the underlying array type. */ - if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE) - type = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))); - - /* If this is an array, compute the number of dimensions in the array, - get the index types, and point to the inner type. */ - if (TREE_CODE (type) != ARRAY_TYPE) - ndim = 0; - else - for (ndim = 1, inner_type = type; - TREE_CODE (TREE_TYPE (inner_type)) == ARRAY_TYPE - && TYPE_MULTI_ARRAY_P (TREE_TYPE (inner_type)); - ndim++, inner_type = TREE_TYPE (inner_type)) - ; - - idx_arr = XALLOCAVEC (tree, ndim); - - if (mech != By_Descriptor_NCA && mech != By_Short_Descriptor_NCA - && TREE_CODE (type) == ARRAY_TYPE && TYPE_CONVENTION_FORTRAN_P (type)) - for (i = ndim - 1, inner_type = type; - i >= 0; - i--, inner_type = TREE_TYPE (inner_type)) - idx_arr[i] = TYPE_DOMAIN (inner_type); - else - for (i = 0, inner_type = type; - i < ndim; - i++, inner_type = TREE_TYPE (inner_type)) - idx_arr[i] = TYPE_DOMAIN (inner_type); - - /* Now get the DTYPE value. */ - switch (TREE_CODE (type)) - { - case INTEGER_TYPE: - case ENUMERAL_TYPE: - case BOOLEAN_TYPE: - if (TYPE_VAX_FLOATING_POINT_P (type)) - switch (tree_to_uhwi (TYPE_DIGITS_VALUE (type))) - { - case 6: - dtype = 10; - break; - case 9: - dtype = 11; - break; - case 15: - dtype = 27; - break; - } - else - switch (GET_MODE_BITSIZE (TYPE_MODE (type))) - { - case 8: - dtype = TYPE_UNSIGNED (type) ? 2 : 6; - break; - case 16: - dtype = TYPE_UNSIGNED (type) ? 3 : 7; - break; - case 32: - dtype = TYPE_UNSIGNED (type) ? 4 : 8; - break; - case 64: - dtype = TYPE_UNSIGNED (type) ? 5 : 9; - break; - case 128: - dtype = TYPE_UNSIGNED (type) ? 25 : 26; - break; - } - break; - - case REAL_TYPE: - dtype = GET_MODE_BITSIZE (TYPE_MODE (type)) == 32 ? 52 : 53; - break; - - case COMPLEX_TYPE: - if (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE - && TYPE_VAX_FLOATING_POINT_P (type)) - switch (tree_to_uhwi (TYPE_DIGITS_VALUE (type))) - { - case 6: - dtype = 12; - break; - case 9: - dtype = 13; - break; - case 15: - dtype = 29; - } - else - dtype = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))) == 32 ? 54: 55; - break; - - case ARRAY_TYPE: - dtype = 14; - break; - - default: - break; - } - - /* Get the CLASS value. */ - switch (mech) - { - case By_Descriptor_A: - case By_Short_Descriptor_A: - klass = 4; - break; - case By_Descriptor_NCA: - case By_Short_Descriptor_NCA: - klass = 10; - break; - case By_Descriptor_SB: - case By_Short_Descriptor_SB: - klass = 15; - break; - case By_Descriptor: - case By_Short_Descriptor: - case By_Descriptor_S: - case By_Short_Descriptor_S: - default: - klass = 1; - break; - } - - /* Make the type for a descriptor for VMS. The first four fields are the - same for all types. */ - field_list - = make_descriptor_field ("LENGTH", gnat_type_for_size (16, 1), record_type, - size_in_bytes ((mech == By_Descriptor_A - || mech == By_Short_Descriptor_A) - ? inner_type : type), - field_list); - field_list - = make_descriptor_field ("DTYPE", gnat_type_for_size (8, 1), record_type, - size_int (dtype), field_list); - field_list - = make_descriptor_field ("CLASS", gnat_type_for_size (8, 1), record_type, - size_int (klass), field_list); - - pointer32_type = build_pointer_type_for_mode (type, SImode, false); - pointer64_type = build_pointer_type_for_mode (type, DImode, false); - - /* Ensure that only 32-bit pointers are passed in 32-bit descriptors. Note - that we cannot build a template call to the CE routine as it would get a - wrong source location; instead we use a second placeholder for it. */ - tem = build_unary_op (ADDR_EXPR, pointer64_type, - build0 (PLACEHOLDER_EXPR, type)); - tem = build3 (COND_EXPR, pointer32_type, - Pmode != SImode - ? build_binary_op (GE_EXPR, boolean_type_node, tem, - build_int_cstu (pointer64_type, 0x80000000)) - : boolean_false_node, - build0 (PLACEHOLDER_EXPR, void_type_node), - convert (pointer32_type, tem)); - - field_list - = make_descriptor_field ("POINTER", pointer32_type, record_type, tem, - field_list); - - switch (mech) - { - case By_Descriptor: - case By_Short_Descriptor: - case By_Descriptor_S: - case By_Short_Descriptor_S: - break; - - case By_Descriptor_SB: - case By_Short_Descriptor_SB: - field_list - = make_descriptor_field ("SB_L1", gnat_type_for_size (32, 1), - record_type, - (TREE_CODE (type) == ARRAY_TYPE - ? TYPE_MIN_VALUE (TYPE_DOMAIN (type)) - : size_zero_node), - field_list); - field_list - = make_descriptor_field ("SB_U1", gnat_type_for_size (32, 1), - record_type, - (TREE_CODE (type) == ARRAY_TYPE - ? TYPE_MAX_VALUE (TYPE_DOMAIN (type)) - : size_zero_node), - field_list); - break; - - case By_Descriptor_A: - case By_Short_Descriptor_A: - case By_Descriptor_NCA: - case By_Short_Descriptor_NCA: - field_list - = make_descriptor_field ("SCALE", gnat_type_for_size (8, 1), - record_type, size_zero_node, field_list); - - field_list - = make_descriptor_field ("DIGITS", gnat_type_for_size (8, 1), - record_type, size_zero_node, field_list); - - field_list - = make_descriptor_field ("AFLAGS", gnat_type_for_size (8, 1), - record_type, - size_int ((mech == By_Descriptor_NCA - || mech == By_Short_Descriptor_NCA) - ? 0 - /* Set FL_COLUMN, FL_COEFF, and - FL_BOUNDS. */ - : (TREE_CODE (type) == ARRAY_TYPE - && TYPE_CONVENTION_FORTRAN_P - (type) - ? 224 : 192)), - field_list); - - field_list - = make_descriptor_field ("DIMCT", gnat_type_for_size (8, 1), - record_type, size_int (ndim), field_list); - - field_list - = make_descriptor_field ("ARSIZE", gnat_type_for_size (32, 1), - record_type, size_in_bytes (type), - field_list); - - /* Now build a pointer to the 0,0,0... element. */ - tem = build0 (PLACEHOLDER_EXPR, type); - for (i = 0, inner_type = type; i < ndim; - i++, inner_type = TREE_TYPE (inner_type)) - tem = build4 (ARRAY_REF, TREE_TYPE (inner_type), tem, - convert (TYPE_DOMAIN (inner_type), size_zero_node), - NULL_TREE, NULL_TREE); - - field_list - = make_descriptor_field ("A0", pointer32_type, record_type, - build1 (ADDR_EXPR, pointer32_type, tem), - field_list); - - /* Next come the addressing coefficients. */ - tem = size_one_node; - for (i = 0; i < ndim; i++) - { - char fname[3]; - tree idx_length - = size_binop (MULT_EXPR, tem, - size_binop (PLUS_EXPR, - size_binop (MINUS_EXPR, - TYPE_MAX_VALUE (idx_arr[i]), - TYPE_MIN_VALUE (idx_arr[i])), - size_int (1))); - - fname[0] = ((mech == By_Descriptor_NCA || - mech == By_Short_Descriptor_NCA) ? 'S' : 'M'); - fname[1] = '0' + i, fname[2] = 0; - field_list - = make_descriptor_field (fname, gnat_type_for_size (32, 1), - record_type, idx_length, field_list); - - if (mech == By_Descriptor_NCA || mech == By_Short_Descriptor_NCA) - tem = idx_length; - } - - /* Finally here are the bounds. */ - for (i = 0; i < ndim; i++) - { - char fname[3]; - - fname[0] = 'L', fname[1] = '0' + i, fname[2] = 0; - field_list - = make_descriptor_field (fname, gnat_type_for_size (32, 1), - record_type, TYPE_MIN_VALUE (idx_arr[i]), - field_list); - - fname[0] = 'U'; - field_list - = make_descriptor_field (fname, gnat_type_for_size (32, 1), - record_type, TYPE_MAX_VALUE (idx_arr[i]), - field_list); - } - break; - - default: - post_error ("unsupported descriptor type for &", gnat_entity); - } - - TYPE_NAME (record_type) = create_concat_name (gnat_entity, "DESC"); - finish_record_type (record_type, nreverse (field_list), 0, false); - return record_type; -} - -/* Build a 64-bit VMS descriptor from a Mechanism_Type, which must specify a - descriptor type, and the GCC type of an object. Each FIELD_DECL in the - type contains in its DECL_INITIAL the expression to use when a constructor - is made for the type. GNAT_ENTITY is an entity used to print out an error - message if the mechanism cannot be applied to an object of that type and - also for the name. */ - -tree -build_vms_descriptor (tree type, Mechanism_Type mech, Entity_Id gnat_entity) -{ - tree record_type = make_node (RECORD_TYPE); - tree pointer64_type; - tree field_list = NULL_TREE; - int klass, ndim, i, dtype = 0; - tree inner_type, tem; - tree *idx_arr; - - /* If TYPE is an unconstrained array, use the underlying array type. */ - if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE) - type = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))); - - /* If this is an array, compute the number of dimensions in the array, - get the index types, and point to the inner type. */ - if (TREE_CODE (type) != ARRAY_TYPE) - ndim = 0; - else - for (ndim = 1, inner_type = type; - TREE_CODE (TREE_TYPE (inner_type)) == ARRAY_TYPE - && TYPE_MULTI_ARRAY_P (TREE_TYPE (inner_type)); - ndim++, inner_type = TREE_TYPE (inner_type)) - ; - - idx_arr = XALLOCAVEC (tree, ndim); - - if (mech != By_Descriptor_NCA - && TREE_CODE (type) == ARRAY_TYPE && TYPE_CONVENTION_FORTRAN_P (type)) - for (i = ndim - 1, inner_type = type; - i >= 0; - i--, inner_type = TREE_TYPE (inner_type)) - idx_arr[i] = TYPE_DOMAIN (inner_type); - else - for (i = 0, inner_type = type; - i < ndim; - i++, inner_type = TREE_TYPE (inner_type)) - idx_arr[i] = TYPE_DOMAIN (inner_type); - - /* Now get the DTYPE value. */ - switch (TREE_CODE (type)) - { - case INTEGER_TYPE: - case ENUMERAL_TYPE: - case BOOLEAN_TYPE: - if (TYPE_VAX_FLOATING_POINT_P (type)) - switch (tree_to_uhwi (TYPE_DIGITS_VALUE (type))) - { - case 6: - dtype = 10; - break; - case 9: - dtype = 11; - break; - case 15: - dtype = 27; - break; - } - else - switch (GET_MODE_BITSIZE (TYPE_MODE (type))) - { - case 8: - dtype = TYPE_UNSIGNED (type) ? 2 : 6; - break; - case 16: - dtype = TYPE_UNSIGNED (type) ? 3 : 7; - break; - case 32: - dtype = TYPE_UNSIGNED (type) ? 4 : 8; - break; - case 64: - dtype = TYPE_UNSIGNED (type) ? 5 : 9; - break; - case 128: - dtype = TYPE_UNSIGNED (type) ? 25 : 26; - break; - } - break; - - case REAL_TYPE: - dtype = GET_MODE_BITSIZE (TYPE_MODE (type)) == 32 ? 52 : 53; - break; - - case COMPLEX_TYPE: - if (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE - && TYPE_VAX_FLOATING_POINT_P (type)) - switch (tree_to_uhwi (TYPE_DIGITS_VALUE (type))) - { - case 6: - dtype = 12; - break; - case 9: - dtype = 13; - break; - case 15: - dtype = 29; - } - else - dtype = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))) == 32 ? 54: 55; - break; - - case ARRAY_TYPE: - dtype = 14; - break; - - default: - break; - } - - /* Get the CLASS value. */ - switch (mech) - { - case By_Descriptor_A: - klass = 4; - break; - case By_Descriptor_NCA: - klass = 10; - break; - case By_Descriptor_SB: - klass = 15; - break; - case By_Descriptor: - case By_Descriptor_S: - default: - klass = 1; - break; - } - - /* Make the type for a 64-bit descriptor for VMS. The first six fields - are the same for all types. */ - field_list - = make_descriptor_field ("MBO", gnat_type_for_size (16, 1), - record_type, size_int (1), field_list); - field_list - = make_descriptor_field ("DTYPE", gnat_type_for_size (8, 1), - record_type, size_int (dtype), field_list); - field_list - = make_descriptor_field ("CLASS", gnat_type_for_size (8, 1), - record_type, size_int (klass), field_list); - field_list - = make_descriptor_field ("MBMO", gnat_type_for_size (32, 1), - record_type, size_int (-1), field_list); - field_list - = make_descriptor_field ("LENGTH", gnat_type_for_size (64, 1), - record_type, - size_in_bytes (mech == By_Descriptor_A - ? inner_type : type), - field_list); - - pointer64_type = build_pointer_type_for_mode (type, DImode, false); - - field_list - = make_descriptor_field ("POINTER", pointer64_type, record_type, - build_unary_op (ADDR_EXPR, pointer64_type, - build0 (PLACEHOLDER_EXPR, type)), - field_list); - - switch (mech) - { - case By_Descriptor: - case By_Descriptor_S: - break; - - case By_Descriptor_SB: - field_list - = make_descriptor_field ("SB_L1", gnat_type_for_size (64, 1), - record_type, - (TREE_CODE (type) == ARRAY_TYPE - ? TYPE_MIN_VALUE (TYPE_DOMAIN (type)) - : size_zero_node), - field_list); - field_list - = make_descriptor_field ("SB_U1", gnat_type_for_size (64, 1), - record_type, - (TREE_CODE (type) == ARRAY_TYPE - ? TYPE_MAX_VALUE (TYPE_DOMAIN (type)) - : size_zero_node), - field_list); - break; - - case By_Descriptor_A: - case By_Descriptor_NCA: - field_list - = make_descriptor_field ("SCALE", gnat_type_for_size (8, 1), - record_type, size_zero_node, field_list); - - field_list - = make_descriptor_field ("DIGITS", gnat_type_for_size (8, 1), - record_type, size_zero_node, field_list); - - dtype = (mech == By_Descriptor_NCA - ? 0 - /* Set FL_COLUMN, FL_COEFF, and - FL_BOUNDS. */ - : (TREE_CODE (type) == ARRAY_TYPE - && TYPE_CONVENTION_FORTRAN_P (type) - ? 224 : 192)); - field_list - = make_descriptor_field ("AFLAGS", gnat_type_for_size (8, 1), - record_type, size_int (dtype), - field_list); - - field_list - = make_descriptor_field ("DIMCT", gnat_type_for_size (8, 1), - record_type, size_int (ndim), field_list); - - field_list - = make_descriptor_field ("MBZ", gnat_type_for_size (32, 1), - record_type, size_int (0), field_list); - field_list - = make_descriptor_field ("ARSIZE", gnat_type_for_size (64, 1), - record_type, size_in_bytes (type), - field_list); - - /* Now build a pointer to the 0,0,0... element. */ - tem = build0 (PLACEHOLDER_EXPR, type); - for (i = 0, inner_type = type; i < ndim; - i++, inner_type = TREE_TYPE (inner_type)) - tem = build4 (ARRAY_REF, TREE_TYPE (inner_type), tem, - convert (TYPE_DOMAIN (inner_type), size_zero_node), - NULL_TREE, NULL_TREE); - - field_list - = make_descriptor_field ("A0", pointer64_type, record_type, - build1 (ADDR_EXPR, pointer64_type, tem), - field_list); - - /* Next come the addressing coefficients. */ - tem = size_one_node; - for (i = 0; i < ndim; i++) - { - char fname[3]; - tree idx_length - = size_binop (MULT_EXPR, tem, - size_binop (PLUS_EXPR, - size_binop (MINUS_EXPR, - TYPE_MAX_VALUE (idx_arr[i]), - TYPE_MIN_VALUE (idx_arr[i])), - size_int (1))); - - fname[0] = (mech == By_Descriptor_NCA ? 'S' : 'M'); - fname[1] = '0' + i, fname[2] = 0; - field_list - = make_descriptor_field (fname, gnat_type_for_size (64, 1), - record_type, idx_length, field_list); - - if (mech == By_Descriptor_NCA) - tem = idx_length; - } - - /* Finally here are the bounds. */ - for (i = 0; i < ndim; i++) - { - char fname[3]; - - fname[0] = 'L', fname[1] = '0' + i, fname[2] = 0; - field_list - = make_descriptor_field (fname, gnat_type_for_size (64, 1), - record_type, - TYPE_MIN_VALUE (idx_arr[i]), field_list); - - fname[0] = 'U'; - field_list - = make_descriptor_field (fname, gnat_type_for_size (64, 1), - record_type, - TYPE_MAX_VALUE (idx_arr[i]), field_list); - } - break; - - default: - post_error ("unsupported descriptor type for &", gnat_entity); - } - - TYPE_NAME (record_type) = create_concat_name (gnat_entity, "DESC64"); - finish_record_type (record_type, nreverse (field_list), 0, false); - return record_type; -} - -/* Fill in a VMS descriptor of GNU_TYPE for GNU_EXPR and return the result. - GNAT_ACTUAL is the actual parameter for which the descriptor is built. */ - -tree -fill_vms_descriptor (tree gnu_type, tree gnu_expr, Node_Id gnat_actual) -{ - vec<constructor_elt, va_gc> *v = NULL; - tree field; - - gnu_expr = maybe_unconstrained_array (gnu_expr); - gnu_expr = gnat_protect_expr (gnu_expr); - gnat_mark_addressable (gnu_expr); - - /* We may need to substitute both GNU_EXPR and a CALL_EXPR to the raise CE - routine in case we have a 32-bit descriptor. */ - gnu_expr = build2 (COMPOUND_EXPR, void_type_node, - build_call_raise (CE_Range_Check_Failed, gnat_actual, - N_Raise_Constraint_Error), - gnu_expr); - - for (field = TYPE_FIELDS (gnu_type); field; field = DECL_CHAIN (field)) - { - tree value - = convert (TREE_TYPE (field), - SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_INITIAL (field), - gnu_expr)); - CONSTRUCTOR_APPEND_ELT (v, field, value); - } - - return gnat_build_constructor (gnu_type, v); -} - -/* Convert GNU_EXPR, a pointer to a 64bit VMS descriptor, to GNU_TYPE, a - regular pointer or fat pointer type. GNAT_SUBPROG is the subprogram to - which the VMS descriptor is passed. */ - -static tree -convert_vms_descriptor64 (tree gnu_type, tree gnu_expr, Entity_Id gnat_subprog) -{ - tree desc_type = TREE_TYPE (TREE_TYPE (gnu_expr)); - tree desc = build1 (INDIRECT_REF, desc_type, gnu_expr); - /* The CLASS field is the 3rd field in the descriptor. */ - tree klass = DECL_CHAIN (DECL_CHAIN (TYPE_FIELDS (desc_type))); - /* The POINTER field is the 6th field in the descriptor. */ - tree pointer = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (klass))); - - /* Retrieve the value of the POINTER field. */ - tree gnu_expr64 - = build3 (COMPONENT_REF, TREE_TYPE (pointer), desc, pointer, NULL_TREE); - - if (POINTER_TYPE_P (gnu_type)) - return convert (gnu_type, gnu_expr64); - - else if (TYPE_IS_FAT_POINTER_P (gnu_type)) - { - tree p_array_type = TREE_TYPE (TYPE_FIELDS (gnu_type)); - tree p_bounds_type = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_type))); - tree template_type = TREE_TYPE (p_bounds_type); - tree min_field = TYPE_FIELDS (template_type); - tree max_field = DECL_CHAIN (TYPE_FIELDS (template_type)); - tree template_tree, template_addr, aflags, dimct, t, u; - /* See the head comment of build_vms_descriptor. */ - int iklass = TREE_INT_CST_LOW (DECL_INITIAL (klass)); - tree lfield, ufield; - vec<constructor_elt, va_gc> *v; - - /* Convert POINTER to the pointer-to-array type. */ - gnu_expr64 = convert (p_array_type, gnu_expr64); - - switch (iklass) - { - case 1: /* Class S */ - case 15: /* Class SB */ - /* Build {1, LENGTH} template; LENGTH64 is the 5th field. */ - vec_alloc (v, 2); - t = DECL_CHAIN (DECL_CHAIN (klass)); - t = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - CONSTRUCTOR_APPEND_ELT (v, min_field, - convert (TREE_TYPE (min_field), - integer_one_node)); - CONSTRUCTOR_APPEND_ELT (v, max_field, - convert (TREE_TYPE (max_field), t)); - template_tree = gnat_build_constructor (template_type, v); - template_addr = build_unary_op (ADDR_EXPR, NULL_TREE, template_tree); - - /* For class S, we are done. */ - if (iklass == 1) - break; - - /* Test that we really have a SB descriptor, like DEC Ada. */ - t = build3 (COMPONENT_REF, TREE_TYPE (klass), desc, klass, NULL); - u = convert (TREE_TYPE (klass), DECL_INITIAL (klass)); - u = build_binary_op (EQ_EXPR, boolean_type_node, t, u); - /* If so, there is already a template in the descriptor and - it is located right after the POINTER field. The fields are - 64bits so they must be repacked. */ - t = DECL_CHAIN (pointer); - lfield = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - lfield = convert (TREE_TYPE (TYPE_FIELDS (template_type)), lfield); - - t = DECL_CHAIN (t); - ufield = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - ufield = convert - (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (template_type))), ufield); - - /* Build the template in the form of a constructor. */ - vec_alloc (v, 2); - CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (template_type), lfield); - CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (template_type)), - ufield); - template_tree = gnat_build_constructor (template_type, v); - - /* Otherwise use the {1, LENGTH} template we build above. */ - template_addr = build3 (COND_EXPR, p_bounds_type, u, - build_unary_op (ADDR_EXPR, p_bounds_type, - template_tree), - template_addr); - break; - - case 4: /* Class A */ - /* The AFLAGS field is the 3rd field after the pointer in the - descriptor. */ - t = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (pointer))); - aflags = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - /* The DIMCT field is the next field in the descriptor after - aflags. */ - t = DECL_CHAIN (t); - dimct = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - /* Raise CONSTRAINT_ERROR if either more than 1 dimension - or FL_COEFF or FL_BOUNDS not set. */ - u = build_int_cst (TREE_TYPE (aflags), 192); - u = build_binary_op (TRUTH_OR_EXPR, boolean_type_node, - build_binary_op (NE_EXPR, boolean_type_node, - dimct, - convert (TREE_TYPE (dimct), - size_one_node)), - build_binary_op (NE_EXPR, boolean_type_node, - build2 (BIT_AND_EXPR, - TREE_TYPE (aflags), - aflags, u), - u)); - /* There is already a template in the descriptor and it is located - in block 3. The fields are 64bits so they must be repacked. */ - t = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (DECL_CHAIN - (t))))); - lfield = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - lfield = convert (TREE_TYPE (TYPE_FIELDS (template_type)), lfield); - - t = DECL_CHAIN (t); - ufield = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - ufield = convert - (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (template_type))), ufield); - - /* Build the template in the form of a constructor. */ - vec_alloc (v, 2); - CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (template_type), lfield); - CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (template_type)), - ufield); - template_tree = gnat_build_constructor (template_type, v); - template_tree = build3 (COND_EXPR, template_type, u, - build_call_raise (CE_Length_Check_Failed, Empty, - N_Raise_Constraint_Error), - template_tree); - template_addr - = build_unary_op (ADDR_EXPR, p_bounds_type, template_tree); - break; - - case 10: /* Class NCA */ - default: - post_error ("unsupported descriptor type for &", gnat_subprog); - template_addr = integer_zero_node; - break; - } - - /* Build the fat pointer in the form of a constructor. */ - vec_alloc (v, 2); - CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (gnu_type), gnu_expr64); - CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (gnu_type)), - template_addr); - return gnat_build_constructor (gnu_type, v); - } - - else - gcc_unreachable (); -} - -/* Convert GNU_EXPR, a pointer to a 32bit VMS descriptor, to GNU_TYPE, a - regular pointer or fat pointer type. GNAT_SUBPROG is the subprogram to - which the VMS descriptor is passed. */ - -static tree -convert_vms_descriptor32 (tree gnu_type, tree gnu_expr, Entity_Id gnat_subprog) -{ - tree desc_type = TREE_TYPE (TREE_TYPE (gnu_expr)); - tree desc = build1 (INDIRECT_REF, desc_type, gnu_expr); - /* The CLASS field is the 3rd field in the descriptor. */ - tree klass = DECL_CHAIN (DECL_CHAIN (TYPE_FIELDS (desc_type))); - /* The POINTER field is the 4th field in the descriptor. */ - tree pointer = DECL_CHAIN (klass); - - /* Retrieve the value of the POINTER field. */ - tree gnu_expr32 - = build3 (COMPONENT_REF, TREE_TYPE (pointer), desc, pointer, NULL_TREE); - - if (POINTER_TYPE_P (gnu_type)) - return convert (gnu_type, gnu_expr32); - - else if (TYPE_IS_FAT_POINTER_P (gnu_type)) - { - tree p_array_type = TREE_TYPE (TYPE_FIELDS (gnu_type)); - tree p_bounds_type = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_type))); - tree template_type = TREE_TYPE (p_bounds_type); - tree min_field = TYPE_FIELDS (template_type); - tree max_field = DECL_CHAIN (TYPE_FIELDS (template_type)); - tree template_tree, template_addr, aflags, dimct, t, u; - /* See the head comment of build_vms_descriptor. */ - int iklass = TREE_INT_CST_LOW (DECL_INITIAL (klass)); - vec<constructor_elt, va_gc> *v; - - /* Convert POINTER to the pointer-to-array type. */ - gnu_expr32 = convert (p_array_type, gnu_expr32); - - switch (iklass) - { - case 1: /* Class S */ - case 15: /* Class SB */ - /* Build {1, LENGTH} template; LENGTH is the 1st field. */ - vec_alloc (v, 2); - t = TYPE_FIELDS (desc_type); - t = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - CONSTRUCTOR_APPEND_ELT (v, min_field, - convert (TREE_TYPE (min_field), - integer_one_node)); - CONSTRUCTOR_APPEND_ELT (v, max_field, - convert (TREE_TYPE (max_field), t)); - template_tree = gnat_build_constructor (template_type, v); - template_addr = build_unary_op (ADDR_EXPR, NULL_TREE, template_tree); - - /* For class S, we are done. */ - if (iklass == 1) - break; - - /* Test that we really have a SB descriptor, like DEC Ada. */ - t = build3 (COMPONENT_REF, TREE_TYPE (klass), desc, klass, NULL); - u = convert (TREE_TYPE (klass), DECL_INITIAL (klass)); - u = build_binary_op (EQ_EXPR, boolean_type_node, t, u); - /* If so, there is already a template in the descriptor and - it is located right after the POINTER field. */ - t = DECL_CHAIN (pointer); - template_tree - = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - /* Otherwise use the {1, LENGTH} template we build above. */ - template_addr = build3 (COND_EXPR, p_bounds_type, u, - build_unary_op (ADDR_EXPR, p_bounds_type, - template_tree), - template_addr); - break; - - case 4: /* Class A */ - /* The AFLAGS field is the 7th field in the descriptor. */ - t = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (pointer))); - aflags = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - /* The DIMCT field is the 8th field in the descriptor. */ - t = DECL_CHAIN (t); - dimct = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - /* Raise CONSTRAINT_ERROR if either more than 1 dimension - or FL_COEFF or FL_BOUNDS not set. */ - u = build_int_cst (TREE_TYPE (aflags), 192); - u = build_binary_op (TRUTH_OR_EXPR, boolean_type_node, - build_binary_op (NE_EXPR, boolean_type_node, - dimct, - convert (TREE_TYPE (dimct), - size_one_node)), - build_binary_op (NE_EXPR, boolean_type_node, - build2 (BIT_AND_EXPR, - TREE_TYPE (aflags), - aflags, u), - u)); - /* There is already a template in the descriptor and it is - located at the start of block 3 (12th field). */ - t = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (t)))); - template_tree - = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); - template_tree = build3 (COND_EXPR, TREE_TYPE (t), u, - build_call_raise (CE_Length_Check_Failed, Empty, - N_Raise_Constraint_Error), - template_tree); - template_addr - = build_unary_op (ADDR_EXPR, p_bounds_type, template_tree); - break; - - case 10: /* Class NCA */ - default: - post_error ("unsupported descriptor type for &", gnat_subprog); - template_addr = integer_zero_node; - break; - } - - /* Build the fat pointer in the form of a constructor. */ - vec_alloc (v, 2); - CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (gnu_type), gnu_expr32); - CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (gnu_type)), - template_addr); - - return gnat_build_constructor (gnu_type, v); - } - - else - gcc_unreachable (); -} - -/* Convert GNU_EXPR, a pointer to a VMS descriptor, to GNU_TYPE, a regular - pointer or fat pointer type. GNU_EXPR_ALT_TYPE is the alternate (32-bit) - pointer type of GNU_EXPR. GNAT_SUBPROG is the subprogram to which the - descriptor is passed. */ - -tree -convert_vms_descriptor (tree gnu_type, tree gnu_expr, tree gnu_expr_alt_type, - Entity_Id gnat_subprog) -{ - tree desc_type = TREE_TYPE (TREE_TYPE (gnu_expr)); - tree desc = build1 (INDIRECT_REF, desc_type, gnu_expr); - tree mbo = TYPE_FIELDS (desc_type); - const char *mbostr = IDENTIFIER_POINTER (DECL_NAME (mbo)); - tree mbmo = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (mbo))); - tree is64bit, gnu_expr32, gnu_expr64; - - /* If the field name is not MBO, it must be 32-bit and no alternate. - Otherwise primary must be 64-bit and alternate 32-bit. */ - if (strcmp (mbostr, "MBO") != 0) - { - tree ret = convert_vms_descriptor32 (gnu_type, gnu_expr, gnat_subprog); - return ret; - } - - /* Build the test for 64-bit descriptor. */ - mbo = build3 (COMPONENT_REF, TREE_TYPE (mbo), desc, mbo, NULL_TREE); - mbmo = build3 (COMPONENT_REF, TREE_TYPE (mbmo), desc, mbmo, NULL_TREE); - is64bit - = build_binary_op (TRUTH_ANDIF_EXPR, boolean_type_node, - build_binary_op (EQ_EXPR, boolean_type_node, - convert (integer_type_node, mbo), - integer_one_node), - build_binary_op (EQ_EXPR, boolean_type_node, - convert (integer_type_node, mbmo), - integer_minus_one_node)); - - /* Build the 2 possible end results. */ - gnu_expr64 = convert_vms_descriptor64 (gnu_type, gnu_expr, gnat_subprog); - gnu_expr = fold_convert (gnu_expr_alt_type, gnu_expr); - gnu_expr32 = convert_vms_descriptor32 (gnu_type, gnu_expr, gnat_subprog); - return build3 (COND_EXPR, gnu_type, is64bit, gnu_expr64, gnu_expr32); -} - /* Build a type to be used to represent an aliased object whose nominal type is an unconstrained array. This consists of a RECORD_TYPE containing a field of TEMPLATE_TYPE and a field of OBJECT_TYPE, which is an ARRAY_TYPE. @@ -4704,9 +3747,9 @@ convert (tree type, tree expr) /* If the input is a biased type, adjust first. */ if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype)) return convert (type, fold_build2 (PLUS_EXPR, TREE_TYPE (etype), + fold_convert (TREE_TYPE (etype), expr), fold_convert (TREE_TYPE (etype), - expr), - TYPE_MIN_VALUE (etype))); + TYPE_MIN_VALUE (etype)))); /* If the input is a justified modular type, we need to extract the actual object before converting it to any other type with the exceptions of an @@ -5012,7 +4055,8 @@ convert (tree type, tree expr) return fold_convert (type, fold_build2 (MINUS_EXPR, TREE_TYPE (type), convert (TREE_TYPE (type), expr), - TYPE_MIN_VALUE (type))); + convert (TREE_TYPE (type), + TYPE_MIN_VALUE (type)))); /* ... fall through ... */ @@ -5426,12 +4470,10 @@ unchecked_convert (tree type, tree expr, bool notrunc_p) /* If both types types are integral just do a normal conversion. Likewise for a conversion to an unconstrained array. */ - if ((((INTEGRAL_TYPE_P (type) - && !(code == INTEGER_TYPE && TYPE_VAX_FLOATING_POINT_P (type))) + if (((INTEGRAL_TYPE_P (type) || (POINTER_TYPE_P (type) && !TYPE_IS_THIN_POINTER_P (type)) || (code == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (type))) - && ((INTEGRAL_TYPE_P (etype) - && !(ecode == INTEGER_TYPE && TYPE_VAX_FLOATING_POINT_P (etype))) + && (INTEGRAL_TYPE_P (etype) || (POINTER_TYPE_P (etype) && !TYPE_IS_THIN_POINTER_P (etype)) || (ecode == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (etype)))) || code == UNCONSTRAINED_ARRAY_TYPE) |