Message ID | 52A5DB9D.50801@codesourcery.com |
---|---|
State | New |
Headers | show |
On Mon, 9 Dec 2013, Bernd Schmidt wrote: > Most of the compiler expects TYPE_ADDR_SPACE to be valid for things like > initializing a MEM. The C frontend does not set it for arrays, which > seems like an oversight caused by not setting other type qualifiers for > array types. I see nothing in TR 18037 to make address space qualifiers different from other qualifiers with regard to the rule that qualifiers apply to element types rather than array types.
On 12/09/2013 11:42 PM, Joseph S. Myers wrote: > On Mon, 9 Dec 2013, Bernd Schmidt wrote: > >> Most of the compiler expects TYPE_ADDR_SPACE to be valid for things like >> initializing a MEM. The C frontend does not set it for arrays, which >> seems like an oversight caused by not setting other type qualifiers for >> array types. > > I see nothing in TR 18037 to make address space qualifiers different from > other qualifiers with regard to the rule that qualifiers apply to element > types rather than array types. But is this relevant? We're dealing with the compiler's internal representation here, and everything assumes that TYPE_ADDRESS_SPACE is set properly for an object in a different address space. Bernd
On Mon, 9 Dec 2013, Bernd Schmidt wrote: > On 12/09/2013 11:42 PM, Joseph S. Myers wrote: > > On Mon, 9 Dec 2013, Bernd Schmidt wrote: > > > >> Most of the compiler expects TYPE_ADDR_SPACE to be valid for things like > >> initializing a MEM. The C frontend does not set it for arrays, which > >> seems like an oversight caused by not setting other type qualifiers for > >> array types. > > > > I see nothing in TR 18037 to make address space qualifiers different from > > other qualifiers with regard to the rule that qualifiers apply to element > > types rather than array types. > > But is this relevant? We're dealing with the compiler's internal > representation here, and everything assumes that TYPE_ADDRESS_SPACE is > set properly for an object in a different address space. It's a mistake for the internal representation to differ from what the qualifiers are in C standard terms, at least within the front end (it's possible qualifiers should be adjusted at some lowering stage).
Most of the compiler expects TYPE_ADDR_SPACE to be valid for things like initializing a MEM. The C frontend does not set it for arrays, which seems like an oversight caused by not setting other type qualifiers for array types. gcc/ * tree.h (set_type_quals): Declare. * tree.c (set_type_quals): No longer static. gcc/c/ * c-typeck.c (c_build_qualified_type): Ensure arrays get the correct TYPE_ADDR_SPACE. gcc/c-family/ * c-common.c (complete_array_type): Likewise. ------------------------------------------------------------------------ Index: gcc/c-family/c-common.c =================================================================== --- gcc/c-family/c-common.c (revision 422353) +++ gcc/c-family/c-common.c (revision 422354) @@ -9997,6 +9997,8 @@ complete_array_type (tree *ptype, tree i of using build_array_type to create a new type preserves all of the TYPE_LANG_FLAG_? bits that the front end may have set. */ main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); + set_type_quals (main_type, KEEP_QUAL_ADDR_SPACE (quals)); + TREE_TYPE (main_type) = unqual_elt; TYPE_DOMAIN (main_type) = build_range_type (TREE_TYPE (maxindex), Index: gcc/c/c-typeck.c =================================================================== --- gcc/c/c-typeck.c (revision 422353) +++ gcc/c/c-typeck.c (revision 422354) @@ -11748,6 +11748,7 @@ c_build_qualified_type (tree type, int t t = build_variant_type_copy (type); TREE_TYPE (t) = element_type; + set_type_quals (t, KEEP_QUAL_ADDR_SPACE (type_quals)); if (TYPE_STRUCTURAL_EQUALITY_P (element_type) || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain))) Index: gcc/tree.c =================================================================== --- gcc/tree.c (revision 422353) +++ gcc/tree.c (revision 422354) @@ -205,7 +205,6 @@ static GTY ((if_marked ("tree_priority_m param_is (struct tree_priority_map))) htab_t init_priority_for_decl; -static void set_type_quals (tree, int); static int type_hash_eq (const void *, const void *); static hashval_t type_hash_hash (const void *); static hashval_t int_cst_hash_hash (const void *); @@ -6076,7 +6075,7 @@ handle_dll_attribute (tree * pnode, tree /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask of the various TYPE_QUAL values. */ -static void +void set_type_quals (tree type, int type_quals) { TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0; Index: gcc/tree.h =================================================================== --- gcc/tree.h (revision 422353) +++ gcc/tree.h (revision 422354) @@ -3785,6 +3785,9 @@ extern tree build_qualified_type (tree, extern tree build_aligned_type (tree, unsigned int); +/* Set the type qualifiers on a type. */ +extern void set_type_quals (tree, int); + /* Like build_qualified_type, but only deals with the `const' and `volatile' qualifiers. This interface is retained for backwards compatibility with the various front-ends; new code should use