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
41/* Nonzero if we've already printed a "missing braces around initializer"
42 message within this initializer. */
43static int missing_braces_mentioned;
44
45static tree qualify_type PROTO((tree, tree));
46static int comp_target_types PROTO((tree, tree));
47static int function_types_compatible_p PROTO((tree, tree));
48static int type_lists_compatible_p PROTO((tree, tree));
49static int self_promoting_type_p PROTO((tree));
50static tree decl_constant_value PROTO((tree));
51static tree lookup_field PROTO((tree, tree, tree *));
52static tree convert_arguments PROTO((tree, tree, tree, tree));
53static tree pointer_int_sum PROTO((enum tree_code, tree, tree));
54static tree pointer_diff PROTO((tree, tree));
55static tree unary_complex_lvalue PROTO((enum tree_code, tree));
56static void pedantic_lvalue_warning PROTO((enum tree_code));
57static tree internal_build_compound_expr PROTO((tree, int));
58static tree convert_for_assignment PROTO((tree, tree, char *, tree,
59 tree, int));
60static void warn_for_assignment PROTO((char *, char *, tree, int));
61static tree valid_compound_expr_initializer PROTO((tree, tree));
62static void push_string PROTO((char *));
63static void push_member_name PROTO((tree));
64static void push_array_bounds PROTO((int));
65static int spelling_length PROTO((void));
66static char *print_spelling PROTO((char *));
67static char *get_spelling PROTO((char *));
68static void warning_init PROTO((char *, char *,
69 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 /* First, detect a valid value with a complete type. */
87 if (TYPE_SIZE (type) != 0
88 && type != void_type_node)
89 return value;
90
91 incomplete_type_error (value, type);
92 return error_mark_node;
93}
94
95/* Print an error message for invalid use of an incomplete type.
96 VALUE is the expression that was used (or 0 if that isn't known)
97 and TYPE is the type that was invalid. */
98
99void
100incomplete_type_error (value, type)
101 tree value;
102 tree type;
103{
104 char *errmsg;
105
106 /* Avoid duplicate error message. */
107 if (TREE_CODE (type) == ERROR_MARK)
108 return;
109
110 if (value != 0 && (TREE_CODE (value) == VAR_DECL
111 || TREE_CODE (value) == PARM_DECL))
112 error ("`%s' has an incomplete type",
113 IDENTIFIER_POINTER (DECL_NAME (value)));
114 else
115 {
116 retry:
117 /* We must print an error message. Be clever about what it says. */
118
119 switch (TREE_CODE (type))
120 {
121 case RECORD_TYPE:
122 errmsg = "invalid use of undefined type `struct %s'";
123 break;
124
125 case UNION_TYPE:
126 errmsg = "invalid use of undefined type `union %s'";
127 break;
128
129 case ENUMERAL_TYPE:
130 errmsg = "invalid use of undefined type `enum %s'";
131 break;
132
133 case VOID_TYPE:
134 error ("invalid use of void expression");
135 return;
136
137 case ARRAY_TYPE:
138 if (TYPE_DOMAIN (type))

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

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

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

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

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

442 return 1;
443
444 /* Different classes of types can't be compatible. */
445
446 if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
447
448 /* Qualifiers must match. */
449
450 if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
451 return 0;
452 if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (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_READONLY (type) || TYPE_VOLATILE (type)
1088 || constp || volatilep)
1089 restype = c_build_type_variant (restype,
1090 TYPE_READONLY (type) || constp,
1091 TYPE_VOLATILE (type) || volatilep);
1092
1093 if (TREE_CODE (exp) == INDIRECT_REF)
1094 return convert (TYPE_POINTER_TO (restype),
1095 TREE_OPERAND (exp, 0));
1096
1097 if (TREE_CODE (exp) == COMPOUND_EXPR)
1098 {
1099 tree op1 = default_conversion (TREE_OPERAND (exp, 1));

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

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

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

2788 enum tree_code code;
2789 tree xarg;
2790 int noconvert;
2791{
2792 /* No default_conversion here. It causes trouble for ADDR_EXPR. */
2793 register tree arg = xarg;
2794 register tree argtype = 0;
2795 register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
2796 char *errstring = NULL;
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 errstring = "wrong type argument to unary plus";
2813 else if (!noconvert)
2814 arg = default_conversion (arg);
2815 break;
2816
2817 case NEGATE_EXPR:
2818 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2819 || typecode == COMPLEX_TYPE))
2820 errstring = "wrong type argument to unary minus";
2821 else if (!noconvert)
2822 arg = default_conversion (arg);
2823 break;
2824
2825 case BIT_NOT_EXPR:
2826 if (typecode == COMPLEX_TYPE)
2827 {
2828 code = CONJ_EXPR;
2829 if (!noconvert)
2830 arg = default_conversion (arg);
2831 }
2832 else if (typecode != INTEGER_TYPE)
2833 errstring = "wrong type argument to bit-complement";
2834 else if (!noconvert)
2835 arg = default_conversion (arg);
2836 break;
2837
2838 case ABS_EXPR:
2839 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2840 || typecode == COMPLEX_TYPE))
2841 errstring = "wrong type argument to abs";
2842 else if (!noconvert)
2843 arg = default_conversion (arg);
2844 break;
2845
2846 case CONJ_EXPR:
2847 /* Conjugating a real value is a no-op, but allow it anyway. */
2848 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2849 || typecode == COMPLEX_TYPE))
2850 errstring = "wrong type argument to conjugation";
2851 else if (!noconvert)
2852 arg = default_conversion (arg);
2853 break;
2854
2855 case TRUTH_NOT_EXPR:
2856 if (typecode != INTEGER_TYPE
2857 && typecode != REAL_TYPE && typecode != POINTER_TYPE
2858 && typecode != COMPLEX_TYPE
2859 /* These will convert to a pointer. */
2860 && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
2861 {
2862 errstring = "wrong type argument to unary exclamation mark";
2863 break;
2864 }
2865 arg = truthvalue_conversion (arg);
2866 return invert_truthvalue (arg);
2867
2868 case NOP_EXPR:
2869 break;
2870
2871 case REALPART_EXPR:

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

2908 build_unary_op (code, real, 1), imag);
2909 }
2910
2911 /* Report invalid types. */
2912
2913 if (typecode != POINTER_TYPE
2914 && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
2915 {
2916 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
2917 errstring ="wrong type argument to increment";
2918 else
2919 errstring ="wrong type argument to decrement";
2920 break;
2921 }
2922
2923 {
2924 register tree inc;
2925 tree result_type = TREE_TYPE (arg);
2926
2927 arg = get_unwidened (arg, 0);
2928 argtype = TREE_TYPE (arg);
2929
2930 /* Compute the increment. */
2931
2932 if (typecode == POINTER_TYPE)
2933 {
2934 /* If pointer target is an undefined struct,
2935 we just cannot know how to do the arithmetic. */
2936 if (TYPE_SIZE (TREE_TYPE (result_type)) == 0)
2937 error ("%s of pointer to unknown structure",
2938 ((code == PREINCREMENT_EXPR
2939 || code == POSTINCREMENT_EXPR)
2940 ? "increment" : "decrement"));
2941 else if ((pedantic || warn_pointer_arith)
2942 && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
2943 || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
2944 pedwarn ("wrong type argument to %s",
2945 ((code == PREINCREMENT_EXPR
2946 || code == POSTINCREMENT_EXPR)
2947 ? "increment" : "decrement"));
2948 inc = c_size_in_bytes (TREE_TYPE (result_type));
2949 }
2950 else
2951 inc = integer_one_node;
2952
2953 inc = convert (argtype, inc);
2954
2955 /* Handle incrementing a cast-expression. */

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

2996 default:
2997 goto give_up;
2998 }
2999 give_up:
3000
3001 /* Complain about anything else that is not a true lvalue. */
3002 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
3003 || code == POSTINCREMENT_EXPR)
3004 ? "increment" : "decrement")))
3005 return error_mark_node;
3006
3007 /* Report a read-only lvalue. */
3008 if (TREE_READONLY (arg))
3009 readonly_warning (arg,
3010 ((code == PREINCREMENT_EXPR
3011 || code == POSTINCREMENT_EXPR)
3012 ? "increment" : "decrement"));

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

3070#endif
3071
3072 /* Allow the address of a constructor if all the elements
3073 are constant. */
3074 if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
3075 ;
3076 /* Anything not already handled and not a true memory reference
3077 is an error. */
3078 else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
3079 return error_mark_node;
3080
3081 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3082 argtype = TREE_TYPE (arg);
3083 /* If the lvalue is const or volatile,
3084 merge that into the type that the address will point to. */
3085 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
3086 || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
3087 {
3088 if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
3089 argtype = c_build_type_variant (argtype,
3090 TREE_READONLY (arg),
3091 TREE_THIS_VOLATILE (arg));
3092 }

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

3136 TREE_CONSTANT (addr) = 1;
3137 return addr;
3138 }
3139
3140 default:
3141 break;
3142 }
3143
3144 if (!errstring)
3145 {
3146 if (argtype == 0)
3147 argtype = TREE_TYPE (arg);
3148 return fold (build1 (code, argtype, arg));
3149 }
3150
3151 error (errstring);
3152 return error_mark_node;
3153}
3154
3155#if 0
3156/* If CONVERSIONS is a conversion expression or a nested sequence of such,
3157 convert ARG with the same conversions in the same order
3158 and return the result. */
3159
3160static tree

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

3218 return 0;
3219 }
3220}
3221
3222/* Return nonzero if REF is an lvalue valid for this language;
3223 otherwise, print an error message and return zero. */
3224
3225int
3226lvalue_or_else (ref, string)
3227 tree ref;
3228 char *string;
3229{
3230 int win = lvalue_p (ref);
3231 if (! win)
3232 error ("invalid lvalue in %s", string);
3233 return win;
3234}
3235
3236/* Apply unary lvalue-demanding operator CODE to the expression ARG
3237 for certain kinds of expressions which are not really lvalues
3238 but which we can accept as lvalues.
3239
3240 If ARG is not a kind of expression we can handle, return zero. */

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

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

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

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

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

3774 /* Go to the innermost object being pointed to. */
3775 tree in_type = type;
3776 tree in_otype = otype;
3777
3778 while (TREE_CODE (in_type) == POINTER_TYPE)
3779 in_type = TREE_TYPE (in_type);
3780 while (TREE_CODE (in_otype) == POINTER_TYPE)
3781 in_otype = TREE_TYPE (in_otype);
3782
3783 if (TYPE_VOLATILE (in_otype) && ! TYPE_VOLATILE (in_type))
3784 pedwarn ("cast discards `volatile' from pointer target type");
3785 if (TYPE_READONLY (in_otype) && ! TYPE_READONLY (in_type))
3786 pedwarn ("cast discards `const' from pointer target type");
3787 }
3788
3789 /* Warn about possible alignment problems. */
3790 if (STRICT_ALIGNMENT && warn_cast_align
3791 && TREE_CODE (type) == POINTER_TYPE
3792 && TREE_CODE (otype) == POINTER_TYPE
3793 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
3794 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE

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

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

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

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

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

4109 and vice versa; otherwise, targets must be the same.
4110 Meanwhile, the lhs target must have all the qualifiers of
4111 the rhs. */
4112 if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4113 || TYPE_MAIN_VARIANT (ttr) == void_type_node
4114 || comp_target_types (memb_type, rhstype))
4115 {
4116 /* If this type won't generate any warnings, use it. */
4117 if ((TREE_CODE (ttr) == FUNCTION_TYPE
4118 && TREE_CODE (ttl) == FUNCTION_TYPE)
4119 ? ((! TYPE_READONLY (ttl) | TYPE_READONLY (ttr))
4120 & (! TYPE_VOLATILE (ttl) | TYPE_VOLATILE (ttr)))
4121 : ((TYPE_READONLY (ttl) | ! TYPE_READONLY (ttr))
4122 & (TYPE_VOLATILE (ttl) | ! TYPE_VOLATILE (ttr))))
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_READONLY (ttl) && ! TYPE_READONLY (ttr))
4161 warn_for_assignment ("%s makes `const *' function pointer from non-const",
4162 get_spelling (errtype), funname,
4163 parmnum);
4164 if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
4165 warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile",
4166 get_spelling (errtype), funname,
4167 parmnum);
4168 }
4169 else
4170 {
4171 if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
4172 warn_for_assignment ("%s discards `const' from pointer target type",
4173 get_spelling (errtype), funname,
4174 parmnum);
4175 if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
4176 warn_for_assignment ("%s discards `volatile' from pointer target type",
4177 get_spelling (errtype), funname,
4178 parmnum);
4179 }
4180 }
4181
4182 if (pedantic && ! DECL_IN_SYSTEM_HEADER (fundecl))
4183 pedwarn ("ANSI C prohibits argument conversion to union type");
4184
4185 return build1 (NOP_EXPR, type, rhs);
4186 }
4187 }

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

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

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

4292 error ("incompatible type for argument %d of `%s'",
4293 parmnum, IDENTIFIER_POINTER (funname));
4294 }
4295 else
4296 error ("incompatible type for argument %d of indirect function call",
4297 parmnum);
4298 }
4299 else
4300 error ("incompatible types in %s", get_spelling (errtype));
4301
4302 return error_mark_node;
4303}
4304
4305/* Print a warning using MSG.
4306 It gets OPNAME as its one parameter.
4307 If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
4308 FUNCTION and ARGNUM are handled specially if we are building an
4309 Objective-C selector. */
4310
4311static void
4312warn_for_assignment (msg, opname, function, argnum)
4313 char *msg;
4314 char *opname;
4315 tree function;
4316 int argnum;
4317{
4318 static char argstring[] = "passing arg %d of `%s'";
4319 static char argnofun[] = "passing arg %d";
4320
4321 if (opname == 0)
4322 {
4323 tree selector = maybe_building_objc_message_expr ();
4324
4325 if (selector && argnum > 2)
4326 {
4327 function = selector;
4328 argnum -= 2;
4329 }
4330 if (function)
4331 {
4332 /* Function name is known; supply it. */
4333 opname = (char *) alloca (IDENTIFIER_LENGTH (function)
4334 + sizeof (argstring) + 25 /*%d*/ + 1);
4335 sprintf (opname, argstring, argnum, IDENTIFIER_POINTER (function));
4336 }
4337 else
4338 {
4339 /* Function name unknown (call through ptr); just give arg number. */
4340 opname = (char *) alloca (sizeof (argnofun) + 25 /*%d*/ + 1);
4341 sprintf (opname, argnofun, argnum);
4342 }
4343 }
4344 pedwarn (msg, opname);
4345}
4346
4347/* Return nonzero if VALUE is a valid constant-valued expression
4348 for use in initializing a static variable; one that can be an
4349 element of a "constant" initializer.
4350
4351 Return null_pointer_node if the value is absolute;
4352 if it is relocatable, return the variable that determines the relocation.

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

4418 /* Allow (int) &foo provided int is as wide as a pointer. */
4419 if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
4420 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE
4421 && (TYPE_PRECISION (TREE_TYPE (value))
4422 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4423 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4424 endtype);
4425
4426 /* Likewise conversions from int to pointers. */
4427 if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
4428 && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
4429 && (TYPE_PRECISION (TREE_TYPE (value))
4430 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4431 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4432 endtype);
4433
4434 /* Allow conversions to union types if the value inside is okay. */
4435 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4436 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4437 endtype);
4438 return 0;
4439
4440 case PLUS_EXPR:

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

4570 and popped. Each element on the stack is this structure. */
4571
4572struct spelling
4573{
4574 int kind;
4575 union
4576 {
4577 int i;
4578 char *s;
4579 } u;
4580};
4581
4582#define SPELLING_STRING 1
4583#define SPELLING_MEMBER 2
4584#define SPELLING_BOUNDS 3
4585
4586static struct spelling *spelling; /* Next stack element (unused). */

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

4626 spelling->MEMBER = (VALUE); \
4627 spelling++; \
4628}
4629
4630/* Push STRING on the stack. Printed literally. */
4631
4632static void
4633push_string (string)
4634 char *string;
4635{
4636 PUSH_SPELLING (SPELLING_STRING, string, u.s);
4637}
4638
4639/* Push a member name on the stack. Printed as '.' STRING. */
4640
4641static void
4642push_member_name (decl)
4643 tree decl;
4644
4645{
4646 char *string
4647 = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
4648 PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
4649}
4650
4651/* Push an array bounds on the stack. Printed as [BOUNDS]. */
4652
4653static void
4654push_array_bounds (bounds)

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

4678
4679/* Print the spelling to BUFFER and return it. */
4680
4681static char *
4682print_spelling (buffer)
4683 register char *buffer;
4684{
4685 register char *d = buffer;
4686 register char *s;
4687 register struct spelling *p;
4688
4689 for (p = spelling_base; p < spelling; p++)
4690 if (p->kind == SPELLING_BOUNDS)
4691 {
4692 sprintf (d, "[%d]", p->u.i);
4693 d += strlen (d);
4694 }
4695 else
4696 {
4697 if (p->kind == SPELLING_MEMBER)
4698 *d++ = '.';
4699 for (s = p->u.s; (*d = *s++); d++)
4700 ;
4701 }
4702 *d++ = '\0';
4703 return buffer;
4704}
4705
4706/* Provide a means to pass component names derived from the spelling stack. */
4707
4708char initialization_message;
4709
4710/* Interpret the spelling of the given ERRTYPE message. */
4711
4712static char *
4713get_spelling (errtype)
4714 char *errtype;
4715{
4716 static char *buffer;
4717 static int size = -1;
4718
4719 if (errtype == &initialization_message)
4720 {
4721 /* Avoid counting chars */
4722 static char message[] = "initialization of `%s'";
4723 register int needed = sizeof (message) + spelling_length () + 1;
4724 char *temp;
4725
4726 if (size < 0)
4727 buffer = (char *) xmalloc (size = needed);
4728 if (needed > size)
4729 buffer = (char *) xrealloc (buffer, size = needed);
4730
4731 temp = (char *) alloca (needed);
4732 sprintf (buffer, message, print_spelling (temp));
4733 return buffer;
4734 }
4735
4736 return errtype;
4737}
4738
4739/* Issue an error message for a bad initializer component.
4740 FORMAT describes the message. OFWHAT is the name for the component.
4741 LOCAL is a format string for formatting the insertion of the name
4742 into the message.
4743
4744 If OFWHAT is null, the component name is stored on the spelling stack.
4745 If the component name is a null string, then LOCAL is omitted entirely. */
4746
4747void
4748error_init (format, local, ofwhat)
4749 char *format, *local, *ofwhat;
4750{
4751 char *buffer;
4752
4753 if (ofwhat == 0)
4754 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4755 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4756
4757 if (*ofwhat)
4758 sprintf (buffer, local, ofwhat);
4759 else
4760 buffer[0] = 0;
4761
4762 error (format, buffer);
4763}
4764
4765/* Issue a pedantic warning for a bad initializer component.
4766 FORMAT describes the message. OFWHAT is the name for the component.
4767 LOCAL is a format string for formatting the insertion of the name
4768 into the message.
4769
4770 If OFWHAT is null, the component name is stored on the spelling stack.
4771 If the component name is a null string, then LOCAL is omitted entirely. */
4772
4773void
4774pedwarn_init (format, local, ofwhat)
4775 char *format, *local, *ofwhat;
4776{
4777 char *buffer;
4778
4779 if (ofwhat == 0)
4780 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4781 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4782
4783 if (*ofwhat)
4784 sprintf (buffer, local, ofwhat);
4785 else
4786 buffer[0] = 0;
4787
4788 pedwarn (format, buffer);
4789}
4790
4791/* Issue a warning for a bad initializer component.
4792 FORMAT describes the message. OFWHAT is the name for the component.
4793 LOCAL is a format string for formatting the insertion of the name
4794 into the message.
4795
4796 If OFWHAT is null, the component name is stored on the spelling stack.
4797 If the component name is a null string, then LOCAL is omitted entirely. */
4798
4799static void
4800warning_init (format, local, ofwhat)
4801 char *format, *local, *ofwhat;
4802{
4803 char *buffer;
4804
4805 if (ofwhat == 0)
4806 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4807 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4808
4809 if (*ofwhat)
4810 sprintf (buffer, local, ofwhat);
4811 else
4812 buffer[0] = 0;
4813
4814 warning (format, buffer);
4815}
4816
4817/* Digest the parser output INIT as an initializer for type TYPE.
4818 Return a C expression of type TYPE to represent the initial value.
4819
4820 The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
4821 if non-constant initializers or elements are seen. CONSTRUCTOR_CONSTANT
4822 applies only to elements of constructors. */

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

4854 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4855 TYPE_MAIN_VARIANT (type)))
4856 return inside_init;
4857
4858 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4859 != char_type_node)
4860 && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
4861 {
4862 error_init ("char-array%s initialized from wide string",
4863 " `%s'", NULL);
4864 return error_mark_node;
4865 }
4866 if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4867 == char_type_node)
4868 && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
4869 {
4870 error_init ("int-array%s initialized from non-wide string",
4871 " `%s'", NULL);
4872 return error_mark_node;
4873 }
4874
4875 TREE_TYPE (inside_init) = type;
4876 if (TYPE_DOMAIN (type) != 0
4877 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4878 {
4879 register int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
4880 size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4881 /* Subtract 1 (or sizeof (wchar_t))
4882 because it's ok to ignore the terminating null char
4883 that is counted in the length of the constant. */
4884 if (size < TREE_STRING_LENGTH (inside_init)
4885 - (TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node)
4886 ? TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT
4887 : 1))
4888 pedwarn_init (
4889 "initializer-string for array of chars%s is too long",
4890 " `%s'", NULL);
4891 }
4892 return inside_init;
4893 }
4894 }
4895
4896 /* Any type can be initialized
4897 from an expression of the same type, optionally with braces. */
4898

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

4909 {
4910 if (code == POINTER_TYPE
4911 && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4912 || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE))
4913 inside_init = default_conversion (inside_init);
4914 else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
4915 && TREE_CODE (inside_init) != CONSTRUCTOR)
4916 {
4917 error_init ("array%s initialized from non-constant array expression",
4918 " `%s'", NULL);
4919 return error_mark_node;
4920 }
4921
4922 if (optimize && TREE_CODE (inside_init) == VAR_DECL)
4923 inside_init = decl_constant_value (inside_init);
4924
4925 /* Compound expressions can only occur here if -pedantic or
4926 -pedantic-errors is specified. In the later case, we always want
4927 an error. In the former case, we simply want a warning. */
4928 if (require_constant && pedantic
4929 && TREE_CODE (inside_init) == COMPOUND_EXPR)
4930 {
4931 inside_init
4932 = valid_compound_expr_initializer (inside_init,
4933 TREE_TYPE (inside_init));
4934 if (inside_init == error_mark_node)
4935 error_init ("initializer element%s is not constant",
4936 " for `%s'", NULL);
4937 else
4938 pedwarn_init ("initializer element%s is not constant",
4939 " for `%s'", NULL);
4940 if (flag_pedantic_errors)
4941 inside_init = error_mark_node;
4942 }
4943 else if (require_constant && ! TREE_CONSTANT (inside_init))
4944 {
4945 error_init ("initializer element%s is not constant",
4946 " for `%s'", NULL);
4947 inside_init = error_mark_node;
4948 }
4949 else if (require_constant
4950 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4951 {
4952 error_init ("initializer element%s is not computable at load time",
4953 " for `%s'", NULL);
4954 inside_init = error_mark_node;
4955 }
4956
4957 return inside_init;
4958 }
4959
4960 /* Handle scalar types, including conversions. */
4961
4962 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
4963 || code == ENUMERAL_TYPE || code == COMPLEX_TYPE)
4964 {
4965 /* Note that convert_for_assignment calls default_conversion
4966 for arrays and functions. We must not call it in the
4967 case where inside_init is a null pointer constant. */
4968 inside_init
4969 = convert_for_assignment (type, init, "initialization",
4970 NULL_TREE, NULL_TREE, 0);
4971
4972 if (require_constant && ! TREE_CONSTANT (inside_init))
4973 {
4974 error_init ("initializer element%s is not constant",
4975 " for `%s'", NULL);
4976 inside_init = error_mark_node;
4977 }
4978 else if (require_constant
4979 && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4980 {
4981 error_init ("initializer element%s is not computable at load time",
4982 " for `%s'", NULL);
4983 inside_init = error_mark_node;
4984 }
4985
4986 return inside_init;
4987 }
4988
4989 /* Come here only for records and arrays. */
4990
4991 if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4992 {
4993 error_init ("variable-sized object%s may not be initialized",
4994 " `%s'", NULL);
4995 return error_mark_node;
4996 }
4997
4998 /* Traditionally, you can write struct foo x = 0;
4999 and it initializes the first element of x to 0. */
5000 if (flag_traditional)
5001 {
5002 tree top = 0, prev = 0, otype = type;

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

5012 TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp);
5013 prev = temp;
5014 if (TREE_CODE (type) == ARRAY_TYPE)
5015 type = TREE_TYPE (type);
5016 else if (TYPE_FIELDS (type))
5017 type = TREE_TYPE (TYPE_FIELDS (type));
5018 else
5019 {
5020 error_init ("invalid initializer%s", " for `%s'", NULL);
5021 return error_mark_node;
5022 }
5023 }
5024
5025 if (otype != type)
5026 {
5027 TREE_OPERAND (prev, 1)
5028 = build_tree_list (NULL_TREE,
5029 digest_init (type, init, require_constant,
5030 constructor_constant));
5031 return top;
5032 }
5033 else
5034 return error_mark_node;
5035 }
5036 error_init ("invalid initializer%s", " for `%s'", NULL);
5037 return error_mark_node;
5038}
5039
5040/* Handle initializers that use braces. */
5041
5042/* Type of object we are accumulating a constructor for.
5043 This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */
5044static tree constructor_type;

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

5191/* Prepare to parse and output the initializer for variable DECL. */
5192
5193void
5194start_init (decl, asmspec_tree, top_level)
5195 tree decl;
5196 tree asmspec_tree;
5197 int top_level;
5198{
5199 char *locus;
5200 struct initializer_stack *p
5201 = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
5202 char *asmspec = 0;
5203
5204 if (asmspec_tree)
5205 asmspec = TREE_STRING_POINTER (asmspec_tree);
5206
5207 p->decl = constructor_decl;

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

5505 constructor_depth++;
5506 if (! tree_int_cst_equal (constructor_index, constructor_unfilled_index)
5507 || constructor_range_end != 0)
5508 constructor_incremental = 0;
5509 }
5510
5511 if (constructor_type == 0)
5512 {
5513 error_init ("extra brace group at end of initializer%s",
5514 " for `%s'", NULL);
5515 constructor_fields = 0;
5516 constructor_unfilled_fields = 0;
5517 return;
5518 }
5519
5520 /* Turn off constructor_incremental if type is a struct with bitfields. */
5521 check_init_type_bitfields (constructor_type);
5522
5523 if (implicit && warn_missing_braces && !missing_braces_mentioned)
5524 {
5525 missing_braces_mentioned = 1;
5526 warning_init ("missing braces around initializer%s", " for `%s'", NULL);
5527 }
5528
5529 if (TREE_CODE (constructor_type) == RECORD_TYPE
5530 || TREE_CODE (constructor_type) == UNION_TYPE)
5531 {
5532 constructor_fields = TYPE_FIELDS (constructor_type);
5533 /* Skip any nameless bit fields at the beginning. */
5534 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)

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

5549 = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5550 }
5551 else
5552 constructor_index = copy_node (integer_zero_node);
5553 constructor_unfilled_index = copy_node (constructor_index);
5554 }
5555 else
5556 {
5557 warning_init ("braces around scalar initializer%s", " for `%s'", NULL);
5558 constructor_fields = constructor_type;
5559 constructor_unfilled_fields = constructor_type;
5560 }
5561}
5562
5563/* Don't read a struct incrementally if it has any bitfields,
5564 because the incremental reading code doesn't know how to
5565 handle bitfields yet. */
5566
5567static void
5568check_init_type_bitfields (type)
5569 tree type;
5570{
5571 if (TREE_CODE (type) == RECORD_TYPE)
5572 {
5573 tree tail;
5574 for (tail = TYPE_FIELDS (type); tail;
5575 tail = TREE_CHAIN (tail))
5576 {
5577 if (DECL_C_BIT_FIELD (tail)
5578 /* This catches cases like `int foo : 8;'. */
5579 || DECL_MODE (tail) != TYPE_MODE (TREE_TYPE (tail)))
5580 {
5581 constructor_incremental = 0;
5582 break;
5583 }
5584
5585 check_init_type_bitfields (TREE_TYPE (tail));
5586 }
5587 }
5588
5589 else if (TREE_CODE (type) == ARRAY_TYPE)
5590 check_init_type_bitfields (TREE_TYPE (type));
5591}
5592
5593/* At the end of an implicit or explicit brace level,
5594 finish up that level of constructor.
5595 If we were outputting the elements as they are read, return 0
5596 from inner levels (process_init_element ignores that),

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

5621
5622 /* Warn when some struct elements are implicitly initialized to zero. */
5623 if (extra_warnings
5624 && constructor_type
5625 && TREE_CODE (constructor_type) == RECORD_TYPE
5626 && constructor_unfilled_fields)
5627 {
5628 push_member_name (constructor_unfilled_fields);
5629 warning_init ("missing initializer%s", " for `%s'", NULL);
5630 RESTORE_SPELLING_DEPTH (constructor_depth);
5631 }
5632
5633 /* Now output all pending elements. */
5634 output_pending_init_elements (1);
5635
5636#if 0 /* c-parse.in warns about {}. */
5637 /* In ANSI, each brace level must have at least one element. */
5638 if (! implicit && pedantic
5639 && (TREE_CODE (constructor_type) == ARRAY_TYPE
5640 ? integer_zerop (constructor_unfilled_index)
5641 : constructor_unfilled_fields == TYPE_FIELDS (constructor_type)))
5642 pedwarn_init ("empty braces in initializer%s", " for `%s'", NULL);
5643#endif
5644
5645 /* Pad out the end of the structure. */
5646
5647 if (p->replacement_value)
5648 {
5649 /* If this closes a superfluous brace pair,
5650 just pass out the element between them. */

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

5698 && TREE_CODE (constructor_type) != UNION_TYPE
5699 && TREE_CODE (constructor_type) != ARRAY_TYPE
5700 && ! constructor_incremental)
5701 {
5702 /* A nonincremental scalar initializer--just return
5703 the element, after verifying there is just one. */
5704 if (constructor_elements == 0)
5705 {
5706 error_init ("empty scalar initializer%s",
5707 " for `%s'", NULL);
5708 constructor = error_mark_node;
5709 }
5710 else if (TREE_CHAIN (constructor_elements) != 0)
5711 {
5712 error_init ("extra elements in scalar initializer%s",
5713 " for `%s'", NULL);
5714 constructor = TREE_VALUE (constructor_elements);
5715 }
5716 else
5717 constructor = TREE_VALUE (constructor_elements);
5718 }
5719 else if (! constructor_incremental)
5720 {
5721 if (constructor_erroneous)

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

5839 while ((TREE_CODE (last) == NOP_EXPR
5840 || TREE_CODE (last) == CONVERT_EXPR
5841 || TREE_CODE (last) == NON_LVALUE_EXPR)
5842 && (TYPE_MODE (TREE_TYPE (last))
5843 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
5844 (last) = TREE_OPERAND (last, 0);
5845
5846 if (TREE_CODE (first) != INTEGER_CST)
5847 error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
5848 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5849 error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
5850 else if (! constructor_unfilled_index)
5851 error_init ("array index in non-array initializer%s", " for `%s'", NULL);
5852 else if (tree_int_cst_lt (first, constructor_unfilled_index))
5853 error_init ("duplicate array index in initializer%s", " for `%s'", NULL);
5854 else
5855 {
5856 TREE_INT_CST_LOW (constructor_index) = TREE_INT_CST_LOW (first);
5857 TREE_INT_CST_HIGH (constructor_index) = TREE_INT_CST_HIGH (first);
5858
5859 if (last != 0 && tree_int_cst_lt (last, first))
5860 error_init ("empty index range in initializer%s", " for `%s'", NULL);
5861 else
5862 {
5863 if (pedantic)
5864 pedwarn ("ANSI C forbids specifying element to initialize");
5865 constructor_range_end = last;
5866 }
5867 }
5868}

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

6183 || ((TREE_CODE (constructor_type) == RECORD_TYPE
6184 || TREE_CODE (constructor_type) == UNION_TYPE)
6185 && DECL_C_BIT_FIELD (field)
6186 && TREE_CODE (value) != INTEGER_CST))
6187 constructor_simple = 0;
6188
6189 if (require_constant_value && ! TREE_CONSTANT (value))
6190 {
6191 error_init ("initializer element%s is not constant",
6192 " for `%s'", NULL);
6193 value = error_mark_node;
6194 }
6195 else if (require_constant_elements
6196 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
6197 {
6198 error_init ("initializer element%s is not computable at load time",
6199 " for `%s'", NULL);
6200 value = error_mark_node;
6201 }
6202
6203 /* If this element duplicates one on constructor_pending_elts,
6204 print a message and ignore it. Don't do this when we're
6205 processing elements taken off constructor_pending_elts,
6206 because we'd always get spurious errors. */
6207 if (pending)
6208 {
6209 if (TREE_CODE (constructor_type) == RECORD_TYPE
6210 || TREE_CODE (constructor_type) == UNION_TYPE
6211 || TREE_CODE (constructor_type) == ARRAY_TYPE)
6212 {
6213 if (pending_init_member (field))
6214 {
6215 error_init ("duplicate initializer%s", " for `%s'", NULL);
6216 duplicate = 1;
6217 }
6218 }
6219 }
6220
6221 /* If this element doesn't come next in sequence,
6222 put it on constructor_pending_elts. */
6223 if (TREE_CODE (constructor_type) == ARRAY_TYPE

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

6560 && integer_zerop (constructor_unfilled_index))
6561 {
6562 constructor_stack->replacement_value = value;
6563 return;
6564 }
6565
6566 if (constructor_stack->replacement_value != 0)
6567 {
6568 error_init ("excess elements in struct initializer%s",
6569 " after `%s'", NULL_PTR);
6570 return;
6571 }
6572
6573 /* Ignore elements of a brace group if it is entirely superfluous
6574 and has already been diagnosed. */
6575 if (constructor_type == 0)
6576 return;
6577

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

6596 {
6597 if (TREE_CODE (constructor_type) == RECORD_TYPE)
6598 {
6599 tree fieldtype;
6600 enum tree_code fieldcode;
6601
6602 if (constructor_fields == 0)
6603 {
6604 pedwarn_init ("excess elements in struct initializer%s",
6605 " after `%s'", NULL_PTR);
6606 break;
6607 }
6608
6609 fieldtype = TREE_TYPE (constructor_fields);
6610 if (fieldtype != error_mark_node)
6611 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6612 fieldcode = TREE_CODE (fieldtype);
6613

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

6661 }
6662 if (TREE_CODE (constructor_type) == UNION_TYPE)
6663 {
6664 tree fieldtype;
6665 enum tree_code fieldcode;
6666
6667 if (constructor_fields == 0)
6668 {
6669 pedwarn_init ("excess elements in union initializer%s",
6670 " after `%s'", NULL_PTR);
6671 break;
6672 }
6673
6674 fieldtype = TREE_TYPE (constructor_fields);
6675 if (fieldtype != error_mark_node)
6676 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6677 fieldcode = TREE_CODE (fieldtype);
6678

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

6736 {
6737 push_init_level (1);
6738 continue;
6739 }
6740
6741 if (constructor_max_index != 0
6742 && tree_int_cst_lt (constructor_max_index, constructor_index))
6743 {
6744 pedwarn_init ("excess elements in array initializer%s",
6745 " after `%s'", NULL_PTR);
6746 break;
6747 }
6748
6749 /* In the case of [LO .. HI] = VALUE, only evaluate VALUE once. */
6750 if (constructor_range_end)
6751 {
6752 if (constructor_max_index != 0
6753 && tree_int_cst_lt (constructor_max_index,
6754 constructor_range_end))
6755 {
6756 pedwarn_init ("excess elements in array initializer%s",
6757 " after `%s'", NULL_PTR);
6758 TREE_INT_CST_HIGH (constructor_range_end)
6759 = TREE_INT_CST_HIGH (constructor_max_index);
6760 TREE_INT_CST_LOW (constructor_range_end)
6761 = TREE_INT_CST_LOW (constructor_max_index);
6762 }
6763
6764 value = save_expr (value);
6765 }

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

6800
6801 break;
6802 }
6803
6804 /* Handle the sole element allowed in a braced initializer
6805 for a scalar variable. */
6806 if (constructor_fields == 0)
6807 {
6808 pedwarn_init ("excess elements in scalar initializer%s",
6809 " after `%s'", NULL_PTR);
6810 break;
6811 }
6812
6813 if (value)
6814 output_init_element (value, constructor_type, NULL_TREE, 1);
6815 constructor_fields = 0;
6816 break;
6817 }

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

6918 {
6919 current_function_returns_null = 1;
6920 if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
6921 pedwarn ("`return' with a value, in function returning void");
6922 expand_return (retval);
6923 }
6924 else
6925 {
6926 tree t = convert_for_assignment (valtype, retval, "return",
6927 NULL_TREE, NULL_TREE, 0);
6928 tree res = DECL_RESULT (current_function_decl);
6929 tree inner;
6930
6931 if (t == error_mark_node)
6932 return;
6933
6934 inner = t = convert (TREE_TYPE (res), t);

--- 100 unchanged lines hidden ---