aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2005-01-29 16:12:45 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2005-01-29 16:12:45 +0000
commit46df282378908dff9219749cd4cd576c155b2971 (patch)
tree146eb63899ed165bd17ec164fc3ef99342b7f13b /gcc/c-decl.c
parent24a09741e4e7ed510fc543cdf3136ebc6582db90 (diff)
downloadgcc-46df282378908dff9219749cd4cd576c155b2971.zip
gcc-46df282378908dff9219749cd4cd576c155b2971.tar.gz
gcc-46df282378908dff9219749cd4cd576c155b2971.tar.bz2
c-common.c (fix_string_type): Just use c_build_qualified_type to build string type.
* c-common.c (fix_string_type): Just use c_build_qualified_type to build string type. (c_build_qualified_type): Build qualified array types with TYPE_MAIN_VARIANT pointing to corresponding unqualified type. * c-decl.c (c_make_fname_decl): Build unqualified array type before qualified type. (grokdeclarator): Use TYPE_MAIN_VARIANT of typedef type if element type is qualified, not just if type itself is. Don't apply qualifiers to array type when declarator is processed. Apply qualifiers to field type whether or not it is an array type. Don't handle array types specially for applying qualifiers to variables. * c-typeck.c (composite_type): Build unqualified element type and array type when forming composite of array types. (common_pointer_type, comptypes, comp_target_types, type_lists_compatible_p, build_indirect_ref, build_array_ref, convert_for_assignment): Don't apply TYPE_MAIN_VARIANT to array types. (type_lists_compatible_p): Cache TREE_VALUE (args1) and TREE_VALUE (args2) in variables a1 and a2. testsuite: * gcc.dg/Wwrite-strings-1.c, gcc.dg/array-quals-2.c, gcc.dg/lvalue-3.c: New tests. * gcc.dg/concat.c: Update expected messages. From-SVN: r94411
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c43
1 files changed, 15 insertions, 28 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 6e8c742..efb17e8 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -2632,9 +2632,9 @@ c_make_fname_decl (tree id, int type_dep)
tree decl, type, init;
size_t length = strlen (name);
- type = build_array_type
- (build_qualified_type (char_type_node, TYPE_QUAL_CONST),
- build_index_type (size_int (length)));
+ type = build_array_type (char_type_node,
+ build_index_type (size_int (length)));
+ type = c_build_qualified_type (type, TYPE_QUAL_CONST);
decl = build_decl (VAR_DECL, id, type);
@@ -3861,7 +3861,7 @@ grokdeclarator (const struct c_declarator *declarator,
if (volatilep > 1)
pedwarn ("duplicate %<volatile%>");
}
- if (!flag_gen_aux_info && (TYPE_QUALS (type)))
+ if (!flag_gen_aux_info && (TYPE_QUALS (element_type)))
type = TYPE_MAIN_VARIANT (type);
type_quals = ((constp ? TYPE_QUAL_CONST : 0)
| (restrictp ? TYPE_QUAL_RESTRICT : 0)
@@ -3946,7 +3946,13 @@ grokdeclarator (const struct c_declarator *declarator,
/* Now figure out the structure of the declarator proper.
Descend through it, creating more complex types, until we reach
- the declared identifier (or NULL_TREE, in an absolute declarator). */
+ the declared identifier (or NULL_TREE, in an absolute declarator).
+ At each stage we maintain an unqualified version of the type
+ together with any qualifiers that should be applied to it with
+ c_build_qualified_type; this way, array types including
+ multidimensional array types are first built up in unqualified
+ form and then the qualified form is created with
+ TYPE_MAIN_VARIANT pointing to the unqualified form. */
while (declarator && declarator->kind != cdk_id)
{
@@ -4146,13 +4152,7 @@ grokdeclarator (const struct c_declarator *declarator,
if (pedantic && !COMPLETE_TYPE_P (type))
pedwarn ("array type has incomplete element type");
- /* Build the array type itself, then merge any constancy
- or volatility into the target type. We must do it in
- this order to ensure that the TYPE_MAIN_VARIANT field
- of the array type is set correctly. */
type = build_array_type (type, itype);
- if (type_quals)
- type = c_build_qualified_type (type, type_quals);
if (size_varies)
C_TYPE_VARIABLE_SIZE (type) = 1;
@@ -4278,7 +4278,8 @@ grokdeclarator (const struct c_declarator *declarator,
}
}
- /* Now TYPE has the actual type. */
+ /* Now TYPE has the actual type, apart from any qualifiers in
+ TYPE_QUALS. */
/* Check the type and width of a bit-field. */
if (bitfield)
@@ -4447,11 +4448,7 @@ grokdeclarator (const struct c_declarator *declarator,
error ("field %qs has incomplete type", name);
type = error_mark_node;
}
- /* Move type qualifiers down to element of an array. */
- if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
- type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
- type_quals),
- TYPE_DOMAIN (type));
+ type = c_build_qualified_type (type, type_quals);
decl = build_decl (FIELD_DECL, declarator->u.id, type);
DECL_NONADDRESSABLE_P (decl) = bitfield;
@@ -4556,17 +4553,7 @@ grokdeclarator (const struct c_declarator *declarator,
/* An uninitialized decl with `extern' is a reference. */
int extern_ref = !initialized && storage_class == csc_extern;
- /* Move type qualifiers down to element of an array. */
- if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
- {
- int saved_align = TYPE_ALIGN(type);
- type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
- type_quals),
- TYPE_DOMAIN (type));
- TYPE_ALIGN (type) = saved_align;
- }
- else if (type_quals)
- type = c_build_qualified_type (type, type_quals);
+ type = c_build_qualified_type (type, type_quals);
/* C99 6.2.2p7: It is invalid (compile-time undefined
behavior) to create an 'extern' declaration for a