Deleted Added
sdiff udiff text old ( 50397 ) new ( 52284 )
full compact
1/* Build expressions with type checking for C compiler.
2 Copyright (C) 1987, 88, 91-97, 1998 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)

--- 23 unchanged lines hidden (view full) ---

32#include "system.h"
33#include "tree.h"
34#include "c-tree.h"
35#include "flags.h"
36#include "output.h"
37#include "rtl.h"
38#include "expr.h"
39#include "toplev.h"
40#include "intl.h"
41
42/* Nonzero if we've already printed a "missing braces around initializer"
43 message within this initializer. */
44static int missing_braces_mentioned;
45
46static tree qualify_type PROTO((tree, tree));
47static int comp_target_types PROTO((tree, tree));
48static int function_types_compatible_p PROTO((tree, tree));
49static int type_lists_compatible_p PROTO((tree, tree));
50static int self_promoting_type_p PROTO((tree));
51static tree decl_constant_value PROTO((tree));
52static tree lookup_field PROTO((tree, tree, tree *));
53static tree convert_arguments PROTO((tree, tree, tree, tree));
54static tree pointer_int_sum PROTO((enum tree_code, tree, tree));
55static tree pointer_diff PROTO((tree, tree));
56static tree unary_complex_lvalue PROTO((enum tree_code, tree));
57static void pedantic_lvalue_warning PROTO((enum tree_code));
58static tree internal_build_compound_expr PROTO((tree, int));
59static tree convert_for_assignment PROTO((tree, tree, const char *, tree,
60 tree, int));
61static void warn_for_assignment PROTO((const char *, const char *,
62 tree, int));
63static tree valid_compound_expr_initializer PROTO((tree, tree));
64static void push_string PROTO((const char *));
65static void push_member_name PROTO((tree));
66static void push_array_bounds PROTO((int));
67static int spelling_length PROTO((void));
68static char *print_spelling PROTO((char *));
69static void warning_init PROTO((const char *));
70static tree digest_init PROTO((tree, tree, int, int));
71static void check_init_type_bitfields PROTO((tree));
72static void output_init_element PROTO((tree, tree, tree, int));
73static void output_pending_init_elements PROTO((int));
74static void add_pending_init PROTO((tree, tree));
75static int pending_init_member PROTO((tree));
76
77/* Do `exp = require_complete_type (exp);' to make sure exp
78 does not have an incomplete type. (That includes void types.) */
79
80tree
81require_complete_type (value)
82 tree value;
83{
84 tree type = TREE_TYPE (value);
85
86 if (TREE_CODE (value) == ERROR_MARK)
87 return error_mark_node;
88
89 /* First, detect a valid value with a complete type. */
90 if (TYPE_SIZE (type) != 0
91 && type != void_type_node)
92 return value;
93
94 incomplete_type_error (value, type);
95 return error_mark_node;
96}
97
98/* Print an error message for invalid use of an incomplete type.
99 VALUE is the expression that was used (or 0 if that isn't known)
100 and TYPE is the type that was invalid. */
101
102void
103incomplete_type_error (value, type)
104 tree value;
105 tree type;
106{
107 const char *type_code_string;
108
109 /* Avoid duplicate error message. */
110 if (TREE_CODE (type) == ERROR_MARK)
111 return;
112
113 if (value != 0 && (TREE_CODE (value) == VAR_DECL
114 || TREE_CODE (value) == PARM_DECL))
115 error ("`%s' has an incomplete type",
116 IDENTIFIER_POINTER (DECL_NAME (value)));
117 else
118 {
119 retry:
120 /* We must print an error message. Be clever about what it says. */
121
122 switch (TREE_CODE (type))
123 {
124 case RECORD_TYPE:
125 type_code_string = "struct";
126 break;
127
128 case UNION_TYPE:
129 type_code_string = "union";
130 break;
131
132 case ENUMERAL_TYPE:
133 type_code_string = "enum";
134 break;
135
136 case VOID_TYPE:
137 error ("invalid use of void expression");
138 return;
139
140 case ARRAY_TYPE:
141 if (TYPE_DOMAIN (type))

--- 4 unchanged lines hidden (view full) ---

146 error ("invalid use of array with unspecified bounds");
147 return;
148
149 default:
150 abort ();
151 }
152
153 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
154 error ("invalid use of undefined type `%s %s'",
155 type_code_string, IDENTIFIER_POINTER (TYPE_NAME (type)));
156 else
157 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
158 error ("invalid use of incomplete typedef `%s'",
159 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
160 }
161}
162
163/* Return a variant of TYPE which has all the type qualifiers of LIKE
164 as well as those of TYPE. */
165
166static tree
167qualify_type (type, like)
168 tree type, like;
169{
170 return c_build_qualified_type (type, TYPE_QUALS (like));
171}
172
173/* Return the common type of two types.
174 We assume that comptypes has already been done and returned 1;
175 if that isn't so, this may crash. In particular, we assume that qualifiers
176 match.
177
178 This is the type for the result of most arithmetic operations

--- 101 unchanged lines hidden (view full) ---

280
281 case POINTER_TYPE:
282 /* For two pointers, do this recursively on the target type,
283 and combine the qualifiers of the two types' targets. */
284 /* This code was turned off; I don't know why.
285 But ANSI C specifies doing this with the qualifiers.
286 So I turned it on again. */
287 {
288 tree pointed_to_1 = TREE_TYPE (t1);
289 tree pointed_to_2 = TREE_TYPE (t2);
290 tree target = common_type (TYPE_MAIN_VARIANT (pointed_to_1),
291 TYPE_MAIN_VARIANT (pointed_to_2));
292 t1 = build_pointer_type (c_build_qualified_type
293 (target,
294 TYPE_QUALS (pointed_to_1) |
295 TYPE_QUALS (pointed_to_2)));
296 return build_type_attribute_variant (t1, attributes);
297 }
298#if 0
299 t1 = build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
300 return build_type_attribute_variant (t1, attributes);
301#endif
302
303 case ARRAY_TYPE:

--- 140 unchanged lines hidden (view full) ---

444 return 1;
445
446 /* Different classes of types can't be compatible. */
447
448 if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
449
450 /* Qualifiers must match. */
451
452 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
453 return 0;
454
455 /* Allow for two different type nodes which have essentially the same
456 definition. Note that we already checked for equality of the type
457 qualifiers (just above). */
458
459 if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
460 return 1;
461

--- 617 unchanged lines hidden (view full) ---

1079
1080 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
1081 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
1082 {
1083 constp = TREE_READONLY (exp);
1084 volatilep = TREE_THIS_VOLATILE (exp);
1085 }
1086
1087 if (TYPE_QUALS (type) || constp || volatilep)
1088 restype
1089 = c_build_qualified_type (restype,
1090 TYPE_QUALS (type)
1091 | (constp * TYPE_QUAL_CONST)
1092 | (volatilep * TYPE_QUAL_VOLATILE));
1093
1094 if (TREE_CODE (exp) == INDIRECT_REF)
1095 return convert (TYPE_POINTER_TO (restype),
1096 TREE_OPERAND (exp, 0));
1097
1098 if (TREE_CODE (exp) == COMPOUND_EXPR)
1099 {
1100 tree op1 = default_conversion (TREE_OPERAND (exp, 1));

--- 219 unchanged lines hidden (view full) ---

1320
1321/* Given an expression PTR for a pointer, return an expression
1322 for the value pointed to.
1323 ERRORSTRING is the name of the operator to appear in error messages. */
1324
1325tree
1326build_indirect_ref (ptr, errorstring)
1327 tree ptr;
1328 const char *errorstring;
1329{
1330 register tree pointer = default_conversion (ptr);
1331 register tree type = TREE_TYPE (pointer);
1332
1333 if (TREE_CODE (type) == POINTER_TYPE)
1334 {
1335 if (TREE_CODE (pointer) == ADDR_EXPR
1336 && !flag_volatile

--- 1452 unchanged lines hidden (view full) ---

2789 enum tree_code code;
2790 tree xarg;
2791 int noconvert;
2792{
2793 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
2794 register tree arg = xarg;
2795 register tree argtype = 0;
2796 register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
2797 tree val;
2798
2799 if (typecode == ERROR_MARK)
2800 return error_mark_node;
2801 if (typecode == ENUMERAL_TYPE)
2802 typecode = INTEGER_TYPE;
2803
2804 switch (code)
2805 {
2806 case CONVERT_EXPR:
2807 /* This is used for unary plus, because a CONVERT_EXPR
2808 is enough to prevent anybody from looking inside for
2809 associativity, but won't generate any code. */
2810 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2811 || typecode == COMPLEX_TYPE))
2812 {
2813 error ("wrong type argument to unary plus");
2814 return error_mark_node;
2815 }
2816 else if (!noconvert)
2817 arg = default_conversion (arg);
2818 break;
2819
2820 case NEGATE_EXPR:
2821 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2822 || typecode == COMPLEX_TYPE))
2823 {
2824 error ("wrong type argument to unary minus");
2825 return error_mark_node;
2826 }
2827 else if (!noconvert)
2828 arg = default_conversion (arg);
2829 break;
2830
2831 case BIT_NOT_EXPR:
2832 if (typecode == COMPLEX_TYPE)
2833 {
2834 code = CONJ_EXPR;
2835 if (!noconvert)
2836 arg = default_conversion (arg);
2837 }
2838 else if (typecode != INTEGER_TYPE)
2839 {
2840 error ("wrong type argument to bit-complement");
2841 return error_mark_node;
2842 }
2843 else if (!noconvert)
2844 arg = default_conversion (arg);
2845 break;
2846
2847 case ABS_EXPR:
2848 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2849 || typecode == COMPLEX_TYPE))
2850 {
2851 error ("wrong type argument to abs");
2852 return error_mark_node;
2853 }
2854 else if (!noconvert)
2855 arg = default_conversion (arg);
2856 break;
2857
2858 case CONJ_EXPR:
2859 /* Conjugating a real value is a no-op, but allow it anyway. */
2860 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2861 || typecode == COMPLEX_TYPE))
2862 {
2863 error ("wrong type argument to conjugation");
2864 return error_mark_node;
2865 }
2866 else if (!noconvert)
2867 arg = default_conversion (arg);
2868 break;
2869
2870 case TRUTH_NOT_EXPR:
2871 if (typecode != INTEGER_TYPE
2872 && typecode != REAL_TYPE && typecode != POINTER_TYPE
2873 && typecode != COMPLEX_TYPE
2874 /* These will convert to a pointer. */
2875 && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
2876 {
2877 error ("wrong type argument to unary exclamation mark");
2878 return error_mark_node;
2879 }
2880 arg = truthvalue_conversion (arg);
2881 return invert_truthvalue (arg);
2882
2883 case NOP_EXPR:
2884 break;
2885
2886 case REALPART_EXPR:

--- 36 unchanged lines hidden (view full) ---

2923 build_unary_op (code, real, 1), imag);
2924 }
2925
2926 /* Report invalid types. */
2927
2928 if (typecode != POINTER_TYPE
2929 && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
2930 {
2931 error (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2932 ? "wrong type argument to increment"
2933 : "wrong type argument to decrement");
2934 return error_mark_node;
2935 }
2936
2937 {
2938 register tree inc;
2939 tree result_type = TREE_TYPE (arg);
2940
2941 arg = get_unwidened (arg, 0);
2942 argtype = TREE_TYPE (arg);
2943
2944 /* Compute the increment. */
2945
2946 if (typecode == POINTER_TYPE)
2947 {
2948 /* If pointer target is an undefined struct,
2949 we just cannot know how to do the arithmetic. */
2950 if (TYPE_SIZE (TREE_TYPE (result_type)) == 0)
2951 error (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2952 ? "increment of pointer to unknown structure"
2953 : "decrement of pointer to unknown structure");
2954 else if ((pedantic || warn_pointer_arith)
2955 && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
2956 || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
2957 pedwarn (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2958 ? "wrong type argument to increment"
2959 : "wrong type argument to decrement");
2960 inc = c_size_in_bytes (TREE_TYPE (result_type));
2961 }
2962 else
2963 inc = integer_one_node;
2964
2965 inc = convert (argtype, inc);
2966
2967 /* Handle incrementing a cast-expression. */

--- 40 unchanged lines hidden (view full) ---

3008 default:
3009 goto give_up;
3010 }
3011 give_up:
3012
3013 /* Complain about anything else that is not a true lvalue. */
3014 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
3015 || code == POSTINCREMENT_EXPR)
3016 ? "invalid lvalue in increment"
3017 : "invalid lvalue in decrement")))
3018 return error_mark_node;
3019
3020 /* Report a read-only lvalue. */
3021 if (TREE_READONLY (arg))
3022 readonly_warning (arg,
3023 ((code == PREINCREMENT_EXPR
3024 || code == POSTINCREMENT_EXPR)
3025 ? "increment" : "decrement"));

--- 57 unchanged lines hidden (view full) ---

3083#endif
3084
3085 /* Allow the address of a constructor if all the elements
3086 are constant. */
3087 if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
3088 ;
3089 /* Anything not already handled and not a true memory reference
3090 is an error. */
3091 else if (typecode != FUNCTION_TYPE
3092 && !lvalue_or_else (arg, "invalid lvalue in unary `&'"))
3093 return error_mark_node;
3094
3095 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3096 argtype = TREE_TYPE (arg);
3097 /* If the lvalue is const or volatile, merge that into the type
3098 to which the address will point. Note that you can't get a
3099 restricted pointer by taking the address of something, so we
3100 only have to deal with `const' and `volatile' here. */
3101 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
3102 || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
3103 {
3104 if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
3105 argtype = c_build_type_variant (argtype,
3106 TREE_READONLY (arg),
3107 TREE_THIS_VOLATILE (arg));
3108 }

--- 43 unchanged lines hidden (view full) ---

3152 TREE_CONSTANT (addr) = 1;
3153 return addr;
3154 }
3155
3156 default:
3157 break;
3158 }
3159
3160 if (argtype == 0)
3161 argtype = TREE_TYPE (arg);
3162 return fold (build1 (code, argtype, arg));
3163}
3164
3165#if 0
3166/* If CONVERSIONS is a conversion expression or a nested sequence of such,
3167 convert ARG with the same conversions in the same order
3168 and return the result. */
3169
3170static tree

--- 57 unchanged lines hidden (view full) ---

3228 return 0;
3229 }
3230}
3231
3232/* Return nonzero if REF is an lvalue valid for this language;
3233 otherwise, print an error message and return zero. */
3234
3235int
3236lvalue_or_else (ref, msgid)
3237 tree ref;
3238 const char *msgid;
3239{
3240 int win = lvalue_p (ref);
3241 if (! win)
3242 error (msgid);
3243 return win;
3244}
3245
3246/* Apply unary lvalue-demanding operator CODE to the expression ARG
3247 for certain kinds of expressions which are not really lvalues
3248 but which we can accept as lvalues.
3249
3250 If ARG is not a kind of expression we can handle, return zero. */

--- 36 unchanged lines hidden (view full) ---

3287/* If pedantic, warn about improper lvalue. CODE is either COND_EXPR
3288 COMPOUND_EXPR, or CONVERT_EXPR (for casts). */
3289
3290static void
3291pedantic_lvalue_warning (code)
3292 enum tree_code code;
3293{
3294 if (pedantic)
3295 pedwarn (code == COND_EXPR
3296 ? "ANSI C forbids use of conditional expressions as lvalues"
3297 : code == COMPOUND_EXPR
3298 ? "ANSI C forbids use of compound expressions as lvalues"
3299 : "ANSI C forbids use of cast expressions as lvalues");
3300}
3301
3302/* Warn about storing in something that is `const'. */
3303
3304void
3305readonly_warning (arg, msgid)
3306 tree arg;
3307 const char *msgid;
3308{
3309 /* Forbid assignments to iterators. */
3310 if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg))
3311 pedwarn ("%s of iterator `%s'", _(msgid),
3312 IDENTIFIER_POINTER (DECL_NAME (arg)));
3313
3314 if (TREE_CODE (arg) == COMPONENT_REF)
3315 {
3316 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3317 readonly_warning (TREE_OPERAND (arg, 0), msgid);
3318 else
3319 pedwarn ("%s of read-only member `%s'", _(msgid),
3320 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
3321 }
3322 else if (TREE_CODE (arg) == VAR_DECL)
3323 pedwarn ("%s of read-only variable `%s'", _(msgid),
3324 IDENTIFIER_POINTER (DECL_NAME (arg)));
3325 else
3326 pedwarn ("%s of read-only location", _(msgid));
3327}
3328
3329/* Mark EXP saying that we need to be able to take the
3330 address of it; it should not be allocated in a register.
3331 Value is 1 if successful. */
3332
3333int
3334mark_addressable (exp)

--- 387 unchanged lines hidden (view full) ---

3722
3723 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3724 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
3725 TYPE_MAIN_VARIANT (TREE_TYPE (value))))
3726 break;
3727
3728 if (field)
3729 {
3730 const char *name;
3731 tree t;
3732
3733 if (pedantic)
3734 pedwarn ("ANSI C forbids casts to union type");
3735 if (TYPE_NAME (type) != 0)
3736 {
3737 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3738 name = IDENTIFIER_POINTER (TYPE_NAME (type));

--- 36 unchanged lines hidden (view full) ---

3775 /* Go to the innermost object being pointed to. */
3776 tree in_type = type;
3777 tree in_otype = otype;
3778
3779 while (TREE_CODE (in_type) == POINTER_TYPE)
3780 in_type = TREE_TYPE (in_type);
3781 while (TREE_CODE (in_otype) == POINTER_TYPE)
3782 in_otype = TREE_TYPE (in_otype);
3783
3784 if (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type))
3785 /* There are qualifiers present in IN_OTYPE that are not
3786 present in IN_TYPE. */
3787 pedwarn ("cast discards qualifiers from pointer target type");
3788 }
3789
3790 /* Warn about possible alignment problems. */
3791 if (STRICT_ALIGNMENT && warn_cast_align
3792 && TREE_CODE (type) == POINTER_TYPE
3793 && TREE_CODE (otype) == POINTER_TYPE
3794 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
3795 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE

--- 164 unchanged lines hidden (view full) ---

3960
3961 default:
3962 break;
3963 }
3964
3965 /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
3966 Reject anything strange now. */
3967
3968 if (!lvalue_or_else (lhs, "invalid lvalue in assignment"))
3969 return error_mark_node;
3970
3971 /* Warn about storing in something that is `const'. */
3972
3973 if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
3974 || ((TREE_CODE (lhstype) == RECORD_TYPE
3975 || TREE_CODE (lhstype) == UNION_TYPE)
3976 && C_TYPE_FIELDS_READONLY (lhstype)))

--- 16 unchanged lines hidden (view full) ---

3993 if (lhstype != TREE_TYPE (lhs))
3994 {
3995 lhs = copy_node (lhs);
3996 TREE_TYPE (lhs) = lhstype;
3997 }
3998
3999 /* Convert new value to destination type. */
4000
4001 newrhs = convert_for_assignment (lhstype, newrhs, _("assignment"),
4002 NULL_TREE, NULL_TREE, 0);
4003 if (TREE_CODE (newrhs) == ERROR_MARK)
4004 return error_mark_node;
4005
4006 result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
4007 TREE_SIDE_EFFECTS (result) = 1;
4008
4009 /* If we got the LHS in a different type for storing in,
4010 convert the result back to the nominal type of LHS
4011 so that the value we return always has the same type
4012 as the LHS argument. */
4013
4014 if (olhstype == TREE_TYPE (result))
4015 return result;
4016 return convert_for_assignment (olhstype, result, _("assignment"),
4017 NULL_TREE, NULL_TREE, 0);
4018}
4019
4020/* Convert value RHS to type TYPE as preparation for an assignment
4021 to an lvalue of type TYPE.
4022 The real work of conversion is done by `convert'.
4023 The purpose of this function is to generate error messages
4024 for assignments that are not allowed in C.
4025 ERRTYPE is a string to use in error messages:
4026 "assignment", "return", etc. If it is null, this is parameter passing
4027 for a function call (and different error messages are output).
4028
4029 FUNNAME is the name of the function being called,
4030 as an IDENTIFIER_NODE, or null.
4031 PARMNUM is the number of the argument, for printing in error messages. */
4032
4033static tree
4034convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
4035 tree type, rhs;
4036 const char *errtype;
4037 tree fundecl, funname;
4038 int parmnum;
4039{
4040 register enum tree_code codel = TREE_CODE (type);
4041 register tree rhstype;
4042 register enum tree_code coder;
4043
4044 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */

--- 63 unchanged lines hidden (view full) ---

4108 and vice versa; otherwise, targets must be the same.
4109 Meanwhile, the lhs target must have all the qualifiers of
4110 the rhs. */
4111 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4112 || TYPE_MAIN_VARIANT (ttr) == void_type_node
4113 || comp_target_types (memb_type, rhstype))
4114 {
4115 /* If this type won't generate any warnings, use it. */
4116 if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
4117 || ((TREE_CODE (ttr) == FUNCTION_TYPE
4118 && TREE_CODE (ttl) == FUNCTION_TYPE)
4119 ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
4120 == TYPE_QUALS (ttr))
4121 : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
4122 == TYPE_QUALS (ttl))))
4123 break;
4124
4125 /* Keep looking for a better type, but remember this one. */
4126 if (! marginal_memb_type)
4127 marginal_memb_type = memb_type;
4128 }
4129 }
4130

--- 21 unchanged lines hidden (view full) ---

4152 if (TREE_CODE (ttr) == FUNCTION_TYPE
4153 && TREE_CODE (ttl) == FUNCTION_TYPE)
4154 {
4155 /* Because const and volatile on functions are
4156 restrictions that say the function will not do
4157 certain things, it is okay to use a const or volatile
4158 function where an ordinary one is wanted, but not
4159 vice-versa. */
4160 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4161 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4162 errtype, funname, parmnum);
4163 }
4164 else if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
4165 warn_for_assignment ("%s discards qualifiers from pointer target type",
4166 errtype, funname,
4167 parmnum);
4168 }
4169
4170 if (pedantic && ! DECL_IN_SYSTEM_HEADER (fundecl))
4171 pedwarn ("ANSI C prohibits argument conversion to union type");
4172
4173 return build1 (NOP_EXPR, type, rhs);
4174 }
4175 }

--- 18 unchanged lines hidden (view full) ---

4194 && TREE_CODE (ttr) == FUNCTION_TYPE)
4195 ||
4196 (TYPE_MAIN_VARIANT (ttr) == void_type_node
4197 /* Check TREE_CODE to catch cases like (void *) (char *) 0
4198 which are not ANSI null ptr constants. */
4199 && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR)
4200 && TREE_CODE (ttl) == FUNCTION_TYPE)))
4201 warn_for_assignment ("ANSI forbids %s between function pointer and `void *'",
4202 errtype, funname, parmnum);
4203 /* Const and volatile mean something different for function types,
4204 so the usual warnings are not appropriate. */
4205 else if (TREE_CODE (ttr) != FUNCTION_TYPE
4206 && TREE_CODE (ttl) != FUNCTION_TYPE)
4207 {
4208 if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
4209 warn_for_assignment ("%s discards qualifiers from pointer target type",
4210 errtype, funname, parmnum);
4211 /* If this is not a case of ignoring a mismatch in signedness,
4212 no warning. */
4213 else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4214 || TYPE_MAIN_VARIANT (ttr) == void_type_node
4215 || comp_target_types (type, rhstype))
4216 ;
4217 /* If there is a mismatch, do warn. */
4218 else if (pedantic)
4219 warn_for_assignment ("pointer targets in %s differ in signedness",
4220 errtype, funname, parmnum);
4221 }
4222 else if (TREE_CODE (ttl) == FUNCTION_TYPE
4223 && TREE_CODE (ttr) == FUNCTION_TYPE)
4224 {
4225 /* Because const and volatile on functions are restrictions
4226 that say the function will not do certain things,
4227 it is okay to use a const or volatile function
4228 where an ordinary one is wanted, but not vice-versa. */
4229 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4230 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4231 errtype, funname, parmnum);
4232 }
4233 }
4234 else
4235 warn_for_assignment ("%s from incompatible pointer type",
4236 errtype, funname, parmnum);
4237 return convert (type, rhs);
4238 }
4239 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
4240 {
4241 /* An explicit constant 0 can convert to a pointer,
4242 or one that results from arithmetic, even including
4243 a cast to integer type. */
4244 if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
4245 &&
4246 ! (TREE_CODE (rhs) == NOP_EXPR
4247 && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
4248 && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
4249 && integer_zerop (TREE_OPERAND (rhs, 0))))
4250 {
4251 warn_for_assignment ("%s makes pointer from integer without a cast",
4252 errtype, funname, parmnum);
4253 return convert (type, rhs);
4254 }
4255 return null_pointer_node;
4256 }
4257 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
4258 {
4259 warn_for_assignment ("%s makes integer from pointer without a cast",
4260 errtype, funname, parmnum);
4261 return convert (type, rhs);
4262 }
4263
4264 if (!errtype)
4265 {
4266 if (funname)
4267 {
4268 tree selector = maybe_building_objc_message_expr ();

--- 5 unchanged lines hidden (view full) ---

4274 error ("incompatible type for argument %d of `%s'",
4275 parmnum, IDENTIFIER_POINTER (funname));
4276 }
4277 else
4278 error ("incompatible type for argument %d of indirect function call",
4279 parmnum);
4280 }
4281 else
4282 error ("incompatible types in %s", errtype);
4283
4284 return error_mark_node;
4285}
4286
4287/* Print a warning using MSGID.
4288 It gets OPNAME as its one parameter.
4289 If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
4290 FUNCTION and ARGNUM are handled specially if we are building an
4291 Objective-C selector. */
4292
4293static void
4294warn_for_assignment (msgid, opname, function, argnum)
4295 const char *msgid;
4296 const char *opname;
4297 tree function;
4298 int argnum;
4299{
4300 if (opname == 0)
4301 {
4302 tree selector = maybe_building_objc_message_expr ();
4303 char * new_opname;
4304
4305 if (selector && argnum > 2)
4306 {
4307 function = selector;
4308 argnum -= 2;
4309 }
4310 if (function)
4311 {
4312 /* Function name is known; supply it. */
4313 const char *argstring = _("passing arg %d of `%s'");
4314 new_opname = (char *) alloca (IDENTIFIER_LENGTH (function)
4315 + strlen (argstring) + 1 + 25
4316 /*%d*/ + 1);
4317 sprintf (new_opname, argstring, argnum,
4318 IDENTIFIER_POINTER (function));
4319 }
4320 else
4321 {
4322 /* Function name unknown (call through ptr); just give arg number.*/
4323 const char *argnofun = _("passing arg %d of pointer to function");
4324 new_opname = (char *) alloca (strlen (argnofun) + 1 + 25 /*%d*/ + 1);
4325 sprintf (new_opname, argnofun, argnum);
4326 }
4327 opname = new_opname;
4328 }
4329 pedwarn (msgid, opname);
4330}
4331
4332/* Return nonzero if VALUE is a valid constant-valued expression
4333 for use in initializing a static variable; one that can be an
4334 element of a "constant" initializer.
4335
4336 Return null_pointer_node if the value is absolute;
4337 if it is relocatable, return the variable that determines the relocation.

--- 65 unchanged lines hidden (view full) ---

4403 /* Allow (int) &foo provided int is as wide as a pointer. */
4404 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4405 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE
4406 && (TYPE_PRECISION (TREE_TYPE (value))
4407 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4408 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4409 endtype);
4410
4411 /* Likewise conversions from int to pointers, but also allow
4412 conversions from 0. */
4413 if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
4414 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
4415 {
4416 if (integer_zerop (TREE_OPERAND (value, 0)))
4417 return null_pointer_node;
4418 else if (TYPE_PRECISION (TREE_TYPE (value))
4419 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4420 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4421 endtype);
4422 }
4423
4424 /* Allow conversions to union types if the value inside is okay. */
4425 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4426 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4427 endtype);
4428 return 0;
4429
4430 case PLUS_EXPR:

--- 129 unchanged lines hidden (view full) ---

4560 and popped. Each element on the stack is this structure. */
4561
4562struct spelling
4563{
4564 int kind;
4565 union
4566 {
4567 int i;
4568 const char *s;
4569 } u;
4570};
4571
4572#define SPELLING_STRING 1
4573#define SPELLING_MEMBER 2
4574#define SPELLING_BOUNDS 3
4575
4576static struct spelling *spelling; /* Next stack element (unused). */

--- 39 unchanged lines hidden (view full) ---

4616 spelling->MEMBER = (VALUE); \
4617 spelling++; \
4618}
4619
4620/* Push STRING on the stack. Printed literally. */
4621
4622static void
4623push_string (string)
4624 const char *string;
4625{
4626 PUSH_SPELLING (SPELLING_STRING, string, u.s);
4627}
4628
4629/* Push a member name on the stack. Printed as '.' STRING. */
4630
4631static void
4632push_member_name (decl)
4633 tree decl;
4634
4635{
4636 const char *string
4637 = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
4638 PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
4639}
4640
4641/* Push an array bounds on the stack. Printed as [BOUNDS]. */
4642
4643static void
4644push_array_bounds (bounds)

--- 23 unchanged lines hidden (view full) ---

4668
4669/* Print the spelling to BUFFER and return it. */
4670
4671static char *
4672print_spelling (buffer)
4673 register char *buffer;
4674{
4675 register char *d = buffer;
4676 register struct spelling *p;
4677
4678 for (p = spelling_base; p < spelling; p++)
4679 if (p->kind == SPELLING_BOUNDS)
4680 {
4681 sprintf (d, "[%d]", p->u.i);
4682 d += strlen (d);
4683 }
4684 else
4685 {
4686 register const char *s;
4687 if (p->kind == SPELLING_MEMBER)
4688 *d++ = '.';
4689 for (s = p->u.s; (*d = *s++); d++)
4690 ;
4691 }
4692 *d++ = '\0';
4693 return buffer;
4694}
4695
4696/* Issue an error message for a bad initializer component.
4697 MSGID identifies the message.
4698 The component name is taken from the spelling stack. */
4699
4700void
4701error_init (msgid)
4702 const char *msgid;
4703{
4704 char *ofwhat;
4705
4706 error (msgid);
4707 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4708 if (*ofwhat)
4709 error ("(near initialization for `%s')", ofwhat);
4710}
4711
4712/* Issue a pedantic warning for a bad initializer component.
4713 MSGID identifies the message.
4714 The component name is taken from the spelling stack. */
4715
4716void
4717pedwarn_init (msgid)
4718 const char *msgid;
4719{
4720 char *ofwhat;
4721
4722 pedwarn (msgid);
4723 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4724 if (*ofwhat)
4725 pedwarn ("(near initialization for `%s')", ofwhat);
4726}
4727
4728/* Issue a warning for a bad initializer component.
4729 MSGID identifies the message.
4730 The component name is taken from the spelling stack. */
4731
4732static void
4733warning_init (msgid)
4734 const char *msgid;
4735{
4736 char *ofwhat;
4737
4738 warning (msgid);
4739 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4740 if (*ofwhat)
4741 warning ("(near initialization for `%s')", ofwhat);
4742}
4743
4744/* Digest the parser output INIT as an initializer for type TYPE.
4745 Return a C expression of type TYPE to represent the initial value.
4746
4747 The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
4748 if non-constant initializers or elements are seen. CONSTRUCTOR_CONSTANT
4749 applies only to elements of constructors. */

--- 31 unchanged lines hidden (view full) ---

4781 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4782 TYPE_MAIN_VARIANT (type)))
4783 return inside_init;
4784
4785 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4786 != char_type_node)
4787 && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
4788 {
4789 error_init ("char-array initialized from wide string");
4790 return error_mark_node;
4791 }
4792 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4793 == char_type_node)
4794 && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
4795 {
4796 error_init ("int-array initialized from non-wide string");
4797 return error_mark_node;
4798 }
4799
4800 TREE_TYPE (inside_init) = type;
4801 if (TYPE_DOMAIN (type) != 0
4802 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4803 {
4804 register int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
4805 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4806 /* Subtract 1 (or sizeof (wchar_t))
4807 because it's ok to ignore the terminating null char
4808 that is counted in the length of the constant. */
4809 if (size < TREE_STRING_LENGTH (inside_init)
4810 - (TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node)
4811 ? TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT
4812 : 1))
4813 pedwarn_init ("initializer-string for array of chars is too long");
4814 }
4815 return inside_init;
4816 }
4817 }
4818
4819 /* Any type can be initialized
4820 from an expression of the same type, optionally with braces. */
4821

--- 10 unchanged lines hidden (view full) ---

4832 {
4833 if (code == POINTER_TYPE
4834 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4835 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE))
4836 inside_init = default_conversion (inside_init);
4837 else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
4838 && TREE_CODE (inside_init) != CONSTRUCTOR)
4839 {
4840 error_init ("array initialized from non-constant array expression");
4841 return error_mark_node;
4842 }
4843
4844 if (optimize && TREE_CODE (inside_init) == VAR_DECL)
4845 inside_init = decl_constant_value (inside_init);
4846
4847 /* Compound expressions can only occur here if -pedantic or
4848 -pedantic-errors is specified. In the later case, we always want
4849 an error. In the former case, we simply want a warning. */
4850 if (require_constant && pedantic
4851 && TREE_CODE (inside_init) == COMPOUND_EXPR)
4852 {
4853 inside_init
4854 = valid_compound_expr_initializer (inside_init,
4855 TREE_TYPE (inside_init));
4856 if (inside_init == error_mark_node)
4857 error_init ("initializer element is not constant");
4858 else
4859 pedwarn_init ("initializer element is not constant");
4860 if (flag_pedantic_errors)
4861 inside_init = error_mark_node;
4862 }
4863 else if (require_constant && ! TREE_CONSTANT (inside_init))
4864 {
4865 error_init ("initializer element is not constant");
4866 inside_init = error_mark_node;
4867 }
4868 else if (require_constant
4869 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4870 {
4871 error_init ("initializer element is not computable at load time");
4872 inside_init = error_mark_node;
4873 }
4874
4875 return inside_init;
4876 }
4877
4878 /* Handle scalar types, including conversions. */
4879
4880 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
4881 || code == ENUMERAL_TYPE || code == COMPLEX_TYPE)
4882 {
4883 /* Note that convert_for_assignment calls default_conversion
4884 for arrays and functions. We must not call it in the
4885 case where inside_init is a null pointer constant. */
4886 inside_init
4887 = convert_for_assignment (type, init, _("initialization"),
4888 NULL_TREE, NULL_TREE, 0);
4889
4890 if (require_constant && ! TREE_CONSTANT (inside_init))
4891 {
4892 error_init ("initializer element is not constant");
4893 inside_init = error_mark_node;
4894 }
4895 else if (require_constant
4896 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4897 {
4898 error_init ("initializer element is not computable at load time");
4899 inside_init = error_mark_node;
4900 }
4901
4902 return inside_init;
4903 }
4904
4905 /* Come here only for records and arrays. */
4906
4907 if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4908 {
4909 error_init ("variable-sized object may not be initialized");
4910 return error_mark_node;
4911 }
4912
4913 /* Traditionally, you can write struct foo x = 0;
4914 and it initializes the first element of x to 0. */
4915 if (flag_traditional)
4916 {
4917 tree top = 0, prev = 0, otype = type;

--- 9 unchanged lines hidden (view full) ---

4927 TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp);
4928 prev = temp;
4929 if (TREE_CODE (type) == ARRAY_TYPE)
4930 type = TREE_TYPE (type);
4931 else if (TYPE_FIELDS (type))
4932 type = TREE_TYPE (TYPE_FIELDS (type));
4933 else
4934 {
4935 error_init ("invalid initializer");
4936 return error_mark_node;
4937 }
4938 }
4939
4940 if (otype != type)
4941 {
4942 TREE_OPERAND (prev, 1)
4943 = build_tree_list (NULL_TREE,
4944 digest_init (type, init, require_constant,
4945 constructor_constant));
4946 return top;
4947 }
4948 else
4949 return error_mark_node;
4950 }
4951 error_init ("invalid initializer");
4952 return error_mark_node;
4953}
4954
4955/* Handle initializers that use braces. */
4956
4957/* Type of object we are accumulating a constructor for.
4958 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
4959static tree constructor_type;

--- 146 unchanged lines hidden (view full) ---

5106/* Prepare to parse and output the initializer for variable DECL. */
5107
5108void
5109start_init (decl, asmspec_tree, top_level)
5110 tree decl;
5111 tree asmspec_tree;
5112 int top_level;
5113{
5114 const char *locus;
5115 struct initializer_stack *p
5116 = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
5117 char *asmspec = 0;
5118
5119 if (asmspec_tree)
5120 asmspec = TREE_STRING_POINTER (asmspec_tree);
5121
5122 p->decl = constructor_decl;

--- 297 unchanged lines hidden (view full) ---

5420 constructor_depth++;
5421 if (! tree_int_cst_equal (constructor_index, constructor_unfilled_index)
5422 || constructor_range_end != 0)
5423 constructor_incremental = 0;
5424 }
5425
5426 if (constructor_type == 0)
5427 {
5428 error_init ("extra brace group at end of initializer");
5429 constructor_fields = 0;
5430 constructor_unfilled_fields = 0;
5431 return;
5432 }
5433
5434 /* Turn off constructor_incremental if type is a struct with bitfields. */
5435 check_init_type_bitfields (constructor_type);
5436
5437 if (implicit && warn_missing_braces && !missing_braces_mentioned)
5438 {
5439 missing_braces_mentioned = 1;
5440 warning_init ("missing braces around initializer");
5441 }
5442
5443 if (TREE_CODE (constructor_type) == RECORD_TYPE
5444 || TREE_CODE (constructor_type) == UNION_TYPE)
5445 {
5446 constructor_fields = TYPE_FIELDS (constructor_type);
5447 /* Skip any nameless bit fields at the beginning. */
5448 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)

--- 14 unchanged lines hidden (view full) ---

5463 = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5464 }
5465 else
5466 constructor_index = copy_node (integer_zero_node);
5467 constructor_unfilled_index = copy_node (constructor_index);
5468 }
5469 else
5470 {
5471 warning_init ("braces around scalar initializer");
5472 constructor_fields = constructor_type;
5473 constructor_unfilled_fields = constructor_type;
5474 }
5475}
5476
5477/* Don't read a struct incrementally if it has any bitfields,
5478 because the incremental reading code doesn't know how to
5479 handle bitfields yet. */
5480
5481static void
5482check_init_type_bitfields (type)
5483 tree type;
5484{
5485 if (TREE_CODE (type) == RECORD_TYPE)
5486 {
5487 tree tail;
5488 for (tail = TYPE_FIELDS (type); tail;
5489 tail = TREE_CHAIN (tail))
5490 {
5491 if (DECL_C_BIT_FIELD (tail))
5492 {
5493 constructor_incremental = 0;
5494 break;
5495 }
5496
5497 check_init_type_bitfields (TREE_TYPE (tail));
5498 }
5499 }
5500
5501 else if (TREE_CODE (type) == UNION_TYPE)
5502 {
5503 tree tail = TYPE_FIELDS (type);
5504 if (tail && DECL_C_BIT_FIELD (tail))
5505 /* We also use the nonincremental algorithm for initiliazation
5506 of unions whose first member is a bitfield, becuase the
5507 incremental algorithm has no code for dealing with
5508 bitfields. */
5509 constructor_incremental = 0;
5510 }
5511
5512 else if (TREE_CODE (type) == ARRAY_TYPE)
5513 check_init_type_bitfields (TREE_TYPE (type));
5514}
5515
5516/* At the end of an implicit or explicit brace level,
5517 finish up that level of constructor.
5518 If we were outputting the elements as they are read, return 0
5519 from inner levels (process_init_element ignores that),

--- 24 unchanged lines hidden (view full) ---

5544
5545 /* Warn when some struct elements are implicitly initialized to zero. */
5546 if (extra_warnings
5547 && constructor_type
5548 && TREE_CODE (constructor_type) == RECORD_TYPE
5549 && constructor_unfilled_fields)
5550 {
5551 push_member_name (constructor_unfilled_fields);
5552 warning_init ("missing initializer");
5553 RESTORE_SPELLING_DEPTH (constructor_depth);
5554 }
5555
5556 /* Now output all pending elements. */
5557 output_pending_init_elements (1);
5558
5559#if 0 /* c-parse.in warns about {}. */
5560 /* In ANSI, each brace level must have at least one element. */
5561 if (! implicit && pedantic
5562 && (TREE_CODE (constructor_type) == ARRAY_TYPE
5563 ? integer_zerop (constructor_unfilled_index)
5564 : constructor_unfilled_fields == TYPE_FIELDS (constructor_type)))
5565 pedwarn_init ("empty braces in initializer");
5566#endif
5567
5568 /* Pad out the end of the structure. */
5569
5570 if (p->replacement_value)
5571 {
5572 /* If this closes a superfluous brace pair,
5573 just pass out the element between them. */

--- 47 unchanged lines hidden (view full) ---

5621 && TREE_CODE (constructor_type) != UNION_TYPE
5622 && TREE_CODE (constructor_type) != ARRAY_TYPE
5623 && ! constructor_incremental)
5624 {
5625 /* A nonincremental scalar initializer--just return
5626 the element, after verifying there is just one. */
5627 if (constructor_elements == 0)
5628 {
5629 error_init ("empty scalar initializer");
5630 constructor = error_mark_node;
5631 }
5632 else if (TREE_CHAIN (constructor_elements) != 0)
5633 {
5634 error_init ("extra elements in scalar initializer");
5635 constructor = TREE_VALUE (constructor_elements);
5636 }
5637 else
5638 constructor = TREE_VALUE (constructor_elements);
5639 }
5640 else if (! constructor_incremental)
5641 {
5642 if (constructor_erroneous)

--- 117 unchanged lines hidden (view full) ---

5760 while ((TREE_CODE (last) == NOP_EXPR
5761 || TREE_CODE (last) == CONVERT_EXPR
5762 || TREE_CODE (last) == NON_LVALUE_EXPR)
5763 && (TYPE_MODE (TREE_TYPE (last))
5764 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
5765 (last) = TREE_OPERAND (last, 0);
5766
5767 if (TREE_CODE (first) != INTEGER_CST)
5768 error_init ("nonconstant array index in initializer");
5769 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5770 error_init ("nonconstant array index in initializer");
5771 else if (! constructor_unfilled_index)
5772 error_init ("array index in non-array initializer");
5773 else if (tree_int_cst_lt (first, constructor_unfilled_index))
5774 error_init ("duplicate array index in initializer");
5775 else
5776 {
5777 TREE_INT_CST_LOW (constructor_index) = TREE_INT_CST_LOW (first);
5778 TREE_INT_CST_HIGH (constructor_index) = TREE_INT_CST_HIGH (first);
5779
5780 if (last != 0 && tree_int_cst_lt (last, first))
5781 error_init ("empty index range in initializer");
5782 else
5783 {
5784 if (pedantic)
5785 pedwarn ("ANSI C forbids specifying element to initialize");
5786 constructor_range_end = last;
5787 }
5788 }
5789}

--- 314 unchanged lines hidden (view full) ---

6104 || ((TREE_CODE (constructor_type) == RECORD_TYPE
6105 || TREE_CODE (constructor_type) == UNION_TYPE)
6106 && DECL_C_BIT_FIELD (field)
6107 && TREE_CODE (value) != INTEGER_CST))
6108 constructor_simple = 0;
6109
6110 if (require_constant_value && ! TREE_CONSTANT (value))
6111 {
6112 error_init ("initializer element is not constant");
6113 value = error_mark_node;
6114 }
6115 else if (require_constant_elements
6116 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
6117 {
6118 error_init ("initializer element is not computable at load time");
6119 value = error_mark_node;
6120 }
6121
6122 /* If this element duplicates one on constructor_pending_elts,
6123 print a message and ignore it. Don't do this when we're
6124 processing elements taken off constructor_pending_elts,
6125 because we'd always get spurious errors. */
6126 if (pending)
6127 {
6128 if (TREE_CODE (constructor_type) == RECORD_TYPE
6129 || TREE_CODE (constructor_type) == UNION_TYPE
6130 || TREE_CODE (constructor_type) == ARRAY_TYPE)
6131 {
6132 if (pending_init_member (field))
6133 {
6134 error_init ("duplicate initializer");
6135 duplicate = 1;
6136 }
6137 }
6138 }
6139
6140 /* If this element doesn't come next in sequence,
6141 put it on constructor_pending_elts. */
6142 if (TREE_CODE (constructor_type) == ARRAY_TYPE

--- 336 unchanged lines hidden (view full) ---

6479 && integer_zerop (constructor_unfilled_index))
6480 {
6481 constructor_stack->replacement_value = value;
6482 return;
6483 }
6484
6485 if (constructor_stack->replacement_value != 0)
6486 {
6487 error_init ("excess elements in struct initializer");
6488 return;
6489 }
6490
6491 /* Ignore elements of a brace group if it is entirely superfluous
6492 and has already been diagnosed. */
6493 if (constructor_type == 0)
6494 return;
6495

--- 18 unchanged lines hidden (view full) ---

6514 {
6515 if (TREE_CODE (constructor_type) == RECORD_TYPE)
6516 {
6517 tree fieldtype;
6518 enum tree_code fieldcode;
6519
6520 if (constructor_fields == 0)
6521 {
6522 pedwarn_init ("excess elements in struct initializer");
6523 break;
6524 }
6525
6526 fieldtype = TREE_TYPE (constructor_fields);
6527 if (fieldtype != error_mark_node)
6528 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6529 fieldcode = TREE_CODE (fieldtype);
6530

--- 47 unchanged lines hidden (view full) ---

6578 }
6579 if (TREE_CODE (constructor_type) == UNION_TYPE)
6580 {
6581 tree fieldtype;
6582 enum tree_code fieldcode;
6583
6584 if (constructor_fields == 0)
6585 {
6586 pedwarn_init ("excess elements in union initializer");
6587 break;
6588 }
6589
6590 fieldtype = TREE_TYPE (constructor_fields);
6591 if (fieldtype != error_mark_node)
6592 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6593 fieldcode = TREE_CODE (fieldtype);
6594

--- 57 unchanged lines hidden (view full) ---

6652 {
6653 push_init_level (1);
6654 continue;
6655 }
6656
6657 if (constructor_max_index != 0
6658 && tree_int_cst_lt (constructor_max_index, constructor_index))
6659 {
6660 pedwarn_init ("excess elements in array initializer");
6661 break;
6662 }
6663
6664 /* In the case of [LO .. HI] = VALUE, only evaluate VALUE once. */
6665 if (constructor_range_end)
6666 {
6667 if (constructor_max_index != 0
6668 && tree_int_cst_lt (constructor_max_index,
6669 constructor_range_end))
6670 {
6671 pedwarn_init ("excess elements in array initializer");
6672 TREE_INT_CST_HIGH (constructor_range_end)
6673 = TREE_INT_CST_HIGH (constructor_max_index);
6674 TREE_INT_CST_LOW (constructor_range_end)
6675 = TREE_INT_CST_LOW (constructor_max_index);
6676 }
6677
6678 value = save_expr (value);
6679 }

--- 34 unchanged lines hidden (view full) ---

6714
6715 break;
6716 }
6717
6718 /* Handle the sole element allowed in a braced initializer
6719 for a scalar variable. */
6720 if (constructor_fields == 0)
6721 {
6722 pedwarn_init ("excess elements in scalar initializer");
6723 break;
6724 }
6725
6726 if (value)
6727 output_init_element (value, constructor_type, NULL_TREE, 1);
6728 constructor_fields = 0;
6729 break;
6730 }

--- 100 unchanged lines hidden (view full) ---

6831 {
6832 current_function_returns_null = 1;
6833 if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
6834 pedwarn ("`return' with a value, in function returning void");
6835 expand_return (retval);
6836 }
6837 else
6838 {
6839 tree t = convert_for_assignment (valtype, retval, _("return"),
6840 NULL_TREE, NULL_TREE, 0);
6841 tree res = DECL_RESULT (current_function_decl);
6842 tree inner;
6843
6844 if (t == error_mark_node)
6845 return;
6846
6847 inner = t = convert (TREE_TYPE (res), t);

--- 100 unchanged lines hidden ---