Deleted Added
full compact
c-typeck.c (50397) c-typeck.c (52284)
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"
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"
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));
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));
58static tree convert_for_assignment PROTO((tree, tree, char *, tree,
59static tree convert_for_assignment PROTO((tree, tree, const char *, tree,
59 tree, int));
60 tree, int));
60static void warn_for_assignment PROTO((char *, char *, tree, int));
61static void warn_for_assignment PROTO((const char *, const char *,
62 tree, int));
61static tree valid_compound_expr_initializer PROTO((tree, tree));
63static tree valid_compound_expr_initializer PROTO((tree, tree));
62static void push_string PROTO((char *));
64static void push_string PROTO((const 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 *));
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 *));
67static char *get_spelling PROTO((char *));
68static void warning_init PROTO((char *, char *,
69 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
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
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{
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{
104 char *errmsg;
107 const char *type_code_string;
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:
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:
122 errmsg = "invalid use of undefined type `struct %s'";
125 type_code_string = "struct";
123 break;
124
125 case UNION_TYPE:
126 break;
127
128 case UNION_TYPE:
126 errmsg = "invalid use of undefined type `union %s'";
129 type_code_string = "union";
127 break;
128
129 case ENUMERAL_TYPE:
130 break;
131
132 case ENUMERAL_TYPE:
130 errmsg = "invalid use of undefined type `enum %s'";
133 type_code_string = "enum";
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)
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)
151 error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
154 error ("invalid use of undefined type `%s %s'",
155 type_code_string, 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{
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{
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);
170 return c_build_qualified_type (type, TYPE_QUALS (like));
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 {
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 {
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));
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)));
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
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
450 if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
452 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
451 return 0;
453 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
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);
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));
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;
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;
1327 char *errorstring;
1328 const 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));
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));
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))
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";
2812 {
2813 error ("wrong type argument to unary plus");
2814 return error_mark_node;
2815 }
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))
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))
2820 errstring = "wrong type argument to unary minus";
2823 {
2824 error ("wrong type argument to unary minus");
2825 return error_mark_node;
2826 }
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)
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)
2833 errstring = "wrong type argument to bit-complement";
2839 {
2840 error ("wrong type argument to bit-complement");
2841 return error_mark_node;
2842 }
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))
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))
2841 errstring = "wrong type argument to abs";
2850 {
2851 error ("wrong type argument to abs");
2852 return error_mark_node;
2853 }
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))
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))
2850 errstring = "wrong type argument to conjugation";
2862 {
2863 error ("wrong type argument to conjugation");
2864 return error_mark_node;
2865 }
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 {
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 {
2862 errstring = "wrong type argument to unary exclamation mark";
2863 break;
2877 error ("wrong type argument to unary exclamation mark");
2878 return error_mark_node;
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 {
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 {
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;
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;
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)
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)
2937 error ("%s of pointer to unknown structure",
2938 ((code == PREINCREMENT_EXPR
2939 || code == POSTINCREMENT_EXPR)
2940 ? "increment" : "decrement"));
2951 error (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2952 ? "increment of pointer to unknown structure"
2953 : "decrement of pointer to unknown structure");
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))
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))
2944 pedwarn ("wrong type argument to %s",
2945 ((code == PREINCREMENT_EXPR
2946 || code == POSTINCREMENT_EXPR)
2947 ? "increment" : "decrement"));
2957 pedwarn (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2958 ? "wrong type argument to increment"
2959 : "wrong type argument to 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)
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)
3004 ? "increment" : "decrement")))
3016 ? "invalid lvalue in increment"
3017 : "invalid lvalue in 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. */
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. */
3078 else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
3091 else if (typecode != FUNCTION_TYPE
3092 && !lvalue_or_else (arg, "invalid lvalue in unary `&'"))
3079 return error_mark_node;
3080
3081 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3082 argtype = TREE_TYPE (arg);
3093 return error_mark_node;
3094
3095 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3096 argtype = TREE_TYPE (arg);
3083 /* If the lvalue is const or volatile,
3084 merge that into the type that the address will point to. */
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. */
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
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
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;
3160 if (argtype == 0)
3161 argtype = TREE_TYPE (arg);
3162 return fold (build1 (code, argtype, arg));
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
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
3226lvalue_or_else (ref, string)
3236lvalue_or_else (ref, msgid)
3227 tree ref;
3237 tree ref;
3228 char *string;
3238 const char *msgid;
3229{
3230 int win = lvalue_p (ref);
3231 if (! win)
3239{
3240 int win = lvalue_p (ref);
3241 if (! win)
3232 error ("invalid lvalue in %s", string);
3242 error (msgid);
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)
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)
3285 pedwarn ("ANSI C forbids use of %s expressions as lvalues",
3286 code == COND_EXPR ? "conditional"
3287 : code == COMPOUND_EXPR ? "compound" : "cast");
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");
3288}
3289
3290/* Warn about storing in something that is `const'. */
3291
3292void
3300}
3301
3302/* Warn about storing in something that is `const'. */
3303
3304void
3293readonly_warning (arg, string)
3305readonly_warning (arg, msgid)
3294 tree arg;
3306 tree arg;
3295 char *string;
3307 const char *msgid;
3296{
3308{
3297 char buf[80];
3298 strcpy (buf, string);
3299
3300 /* Forbid assignments to iterators. */
3301 if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg))
3309 /* Forbid assignments to iterators. */
3310 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 }
3311 pedwarn ("%s of iterator `%s'", _(msgid),
3312 IDENTIFIER_POINTER (DECL_NAME (arg)));
3306
3307 if (TREE_CODE (arg) == COMPONENT_REF)
3308 {
3309 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3313
3314 if (TREE_CODE (arg) == COMPONENT_REF)
3315 {
3316 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3310 readonly_warning (TREE_OPERAND (arg, 0), string);
3317 readonly_warning (TREE_OPERAND (arg, 0), msgid);
3311 else
3318 else
3312 {
3313 strcat (buf, " of read-only member `%s'");
3314 pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
3315 }
3319 pedwarn ("%s of read-only member `%s'", _(msgid),
3320 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
3316 }
3317 else if (TREE_CODE (arg) == VAR_DECL)
3321 }
3322 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 }
3323 pedwarn ("%s of read-only variable `%s'", _(msgid),
3324 IDENTIFIER_POINTER (DECL_NAME (arg)));
3322 else
3325 else
3323 {
3324 pedwarn ("%s of read-only location", buf);
3325 }
3326 pedwarn ("%s of read-only location", _(msgid));
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 {
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 {
3729 char *name;
3730 const 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);
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);
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");
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");
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
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
3967 if (!lvalue_or_else (lhs, "assignment"))
3968 if (!lvalue_or_else (lhs, "invalid lvalue in 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
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
4000 newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
4001 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;
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;
4015 return convert_for_assignment (olhstype, result, "assignment",
4016 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
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
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.
4027 for a function call (and different error messages are output).
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;
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;
4037 char *errtype;
4036 const 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. */
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. */
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))))
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. */
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);
4160 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4161 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4162 errtype, funname, parmnum);
4168 }
4163 }
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 }
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);
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 *'",
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 *'",
4214 get_spelling (errtype), funname, parmnum);
4202 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 {
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 {
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);
4208 if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
4209 warn_for_assignment ("%s discards qualifiers from pointer target type",
4210 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",
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",
4235 get_spelling (errtype), funname, parmnum);
4220 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. */
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. */
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);
4229 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4230 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4231 errtype, funname, parmnum);
4250 }
4251 }
4252 else
4253 warn_for_assignment ("%s from incompatible pointer type",
4232 }
4233 }
4234 else
4235 warn_for_assignment ("%s from incompatible pointer type",
4254 get_spelling (errtype), funname, parmnum);
4236 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",
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",
4270 get_spelling (errtype), funname, parmnum);
4252 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",
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",
4278 get_spelling (errtype), funname, parmnum);
4260 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
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
4300 error ("incompatible types in %s", get_spelling (errtype));
4282 error ("incompatible types in %s", errtype);
4301
4302 return error_mark_node;
4303}
4304
4283
4284 return error_mark_node;
4285}
4286
4305/* Print a warning using MSG.
4287/* Print a warning using MSGID.
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
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
4312warn_for_assignment (msg, opname, function, argnum)
4313 char *msg;
4314 char *opname;
4294warn_for_assignment (msgid, opname, function, argnum)
4295 const char *msgid;
4296 const char *opname;
4315 tree function;
4316 int argnum;
4317{
4297 tree function;
4298 int argnum;
4299{
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 ();
4300 if (opname == 0)
4301 {
4302 tree selector = maybe_building_objc_message_expr ();
4303 char * new_opname;
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. */
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. */
4333 opname = (char *) alloca (IDENTIFIER_LENGTH (function)
4334 + sizeof (argstring) + 25 /*%d*/ + 1);
4335 sprintf (opname, argstring, argnum, IDENTIFIER_POINTER (function));
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));
4336 }
4337 else
4338 {
4319 }
4320 else
4321 {
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);
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);
4342 }
4326 }
4327 opname = new_opname;
4343 }
4328 }
4344 pedwarn (msg, opname);
4329 pedwarn (msgid, 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
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
4426 /* Likewise conversions from int to pointers. */
4411 /* Likewise conversions from int to pointers, but also allow
4412 conversions from 0. */
4427 if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
4413 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);
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 }
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;
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;
4578 char *s;
4568 const 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)
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)
4634 char *string;
4624 const 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{
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{
4646 char *string
4636 const 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;
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;
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 {
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;
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
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
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.
4696/* 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.
4697 MSGID identifies the message.
4698 The component name is taken from the spelling stack. */
4743
4699
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
4700void
4748error_init (format, local, ofwhat)
4749 char *format, *local, *ofwhat;
4701error_init (msgid)
4702 const char *msgid;
4750{
4703{
4751 char *buffer;
4704 char *ofwhat;
4752
4705
4753 if (ofwhat == 0)
4754 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4755 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4756
4706 error (msgid);
4707 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4757 if (*ofwhat)
4708 if (*ofwhat)
4758 sprintf (buffer, local, ofwhat);
4759 else
4760 buffer[0] = 0;
4761
4762 error (format, buffer);
4709 error ("(near initialization for `%s')", ofwhat);
4763}
4764
4765/* Issue a pedantic warning for a bad initializer component.
4710}
4711
4712/* 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.
4713 MSGID identifies the message.
4714 The component name is taken from the spelling stack. */
4769
4715
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
4716void
4774pedwarn_init (format, local, ofwhat)
4775 char *format, *local, *ofwhat;
4717pedwarn_init (msgid)
4718 const char *msgid;
4776{
4719{
4777 char *buffer;
4720 char *ofwhat;
4778
4721
4779 if (ofwhat == 0)
4780 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4781 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4782
4722 pedwarn (msgid);
4723 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4783 if (*ofwhat)
4724 if (*ofwhat)
4784 sprintf (buffer, local, ofwhat);
4785 else
4786 buffer[0] = 0;
4787
4788 pedwarn (format, buffer);
4725 pedwarn ("(near initialization for `%s')", ofwhat);
4789}
4790
4791/* Issue a warning for a bad initializer component.
4726}
4727
4728/* 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.
4729 MSGID identifies the message.
4730 The component name is taken from the spelling stack. */
4795
4731
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
4732static void
4800warning_init (format, local, ofwhat)
4801 char *format, *local, *ofwhat;
4733warning_init (msgid)
4734 const char *msgid;
4802{
4735{
4803 char *buffer;
4736 char *ofwhat;
4804
4737
4805 if (ofwhat == 0)
4806 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4807 buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
4808
4738 warning (msgid);
4739 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4809 if (*ofwhat)
4740 if (*ofwhat)
4810 sprintf (buffer, local, ofwhat);
4811 else
4812 buffer[0] = 0;
4813
4814 warning (format, buffer);
4741 warning ("(near initialization for `%s')", ofwhat);
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 {
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 {
4862 error_init ("char-array%s initialized from wide string",
4863 " `%s'", NULL);
4789 error_init ("char-array initialized from wide string");
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 {
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 {
4870 error_init ("int-array%s initialized from non-wide string",
4871 " `%s'", NULL);
4796 error_init ("int-array initialized from non-wide string");
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))
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))
4888 pedwarn_init (
4889 "initializer-string for array of chars%s is too long",
4890 " `%s'", NULL);
4813 pedwarn_init ("initializer-string for array of chars is too long");
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 {
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 {
4917 error_init ("array%s initialized from non-constant array expression",
4918 " `%s'", NULL);
4840 error_init ("array initialized from non-constant array expression");
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)
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)
4935 error_init ("initializer element%s is not constant",
4936 " for `%s'", NULL);
4857 error_init ("initializer element is not constant");
4937 else
4858 else
4938 pedwarn_init ("initializer element%s is not constant",
4939 " for `%s'", NULL);
4859 pedwarn_init ("initializer element is not constant");
4940 if (flag_pedantic_errors)
4941 inside_init = error_mark_node;
4942 }
4943 else if (require_constant && ! TREE_CONSTANT (inside_init))
4944 {
4860 if (flag_pedantic_errors)
4861 inside_init = error_mark_node;
4862 }
4863 else if (require_constant && ! TREE_CONSTANT (inside_init))
4864 {
4945 error_init ("initializer element%s is not constant",
4946 " for `%s'", NULL);
4865 error_init ("initializer element is not constant");
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 {
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 {
4952 error_init ("initializer element%s is not computable at load time",
4953 " for `%s'", NULL);
4871 error_init ("initializer element is not computable at load time");
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
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
4969 = convert_for_assignment (type, init, "initialization",
4887 = convert_for_assignment (type, init, _("initialization"),
4970 NULL_TREE, NULL_TREE, 0);
4971
4972 if (require_constant && ! TREE_CONSTANT (inside_init))
4973 {
4888 NULL_TREE, NULL_TREE, 0);
4889
4890 if (require_constant && ! TREE_CONSTANT (inside_init))
4891 {
4974 error_init ("initializer element%s is not constant",
4975 " for `%s'", NULL);
4892 error_init ("initializer element is not constant");
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 {
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 {
4981 error_init ("initializer element%s is not computable at load time",
4982 " for `%s'", NULL);
4898 error_init ("initializer element is not computable at load time");
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 {
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 {
4993 error_init ("variable-sized object%s may not be initialized",
4994 " `%s'", NULL);
4909 error_init ("variable-sized object may not be initialized");
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 {
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 {
5020 error_init ("invalid initializer%s", " for `%s'", NULL);
4935 error_init ("invalid initializer");
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 }
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 }
5036 error_init ("invalid initializer%s", " for `%s'", NULL);
4951 error_init ("invalid initializer");
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{
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{
5199 char *locus;
5114 const 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 {
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 {
5513 error_init ("extra brace group at end of initializer%s",
5514 " for `%s'", NULL);
5428 error_init ("extra brace group at end of initializer");
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;
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;
5526 warning_init ("missing braces around initializer%s", " for `%s'", NULL);
5440 warning_init ("missing braces around initializer");
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 {
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 {
5557 warning_init ("braces around scalar initializer%s", " for `%s'", NULL);
5471 warning_init ("braces around scalar initializer");
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 {
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 {
5577 if (DECL_C_BIT_FIELD (tail)
5578 /* This catches cases like `int foo : 8;'. */
5579 || DECL_MODE (tail) != TYPE_MODE (TREE_TYPE (tail)))
5491 if (DECL_C_BIT_FIELD (tail))
5580 {
5581 constructor_incremental = 0;
5582 break;
5583 }
5584
5585 check_init_type_bitfields (TREE_TYPE (tail));
5586 }
5587 }
5588
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
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);
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);
5629 warning_init ("missing initializer%s", " for `%s'", NULL);
5552 warning_init ("missing initializer");
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)))
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)))
5642 pedwarn_init ("empty braces in initializer%s", " for `%s'", NULL);
5565 pedwarn_init ("empty braces in initializer");
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 {
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 {
5706 error_init ("empty scalar initializer%s",
5707 " for `%s'", NULL);
5629 error_init ("empty scalar initializer");
5708 constructor = error_mark_node;
5709 }
5710 else if (TREE_CHAIN (constructor_elements) != 0)
5711 {
5630 constructor = error_mark_node;
5631 }
5632 else if (TREE_CHAIN (constructor_elements) != 0)
5633 {
5712 error_init ("extra elements in scalar initializer%s",
5713 " for `%s'", NULL);
5634 error_init ("extra elements in scalar initializer");
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)
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)
5847 error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
5768 error_init ("nonconstant array index in initializer");
5848 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5769 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5849 error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
5770 error_init ("nonconstant array index in initializer");
5850 else if (! constructor_unfilled_index)
5771 else if (! constructor_unfilled_index)
5851 error_init ("array index in non-array initializer%s", " for `%s'", NULL);
5772 error_init ("array index in non-array initializer");
5852 else if (tree_int_cst_lt (first, constructor_unfilled_index))
5773 else if (tree_int_cst_lt (first, constructor_unfilled_index))
5853 error_init ("duplicate array index in initializer%s", " for `%s'", NULL);
5774 error_init ("duplicate array index in initializer");
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))
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))
5860 error_init ("empty index range in initializer%s", " for `%s'", NULL);
5781 error_init ("empty index range in initializer");
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 {
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 {
6191 error_init ("initializer element%s is not constant",
6192 " for `%s'", NULL);
6112 error_init ("initializer element is not constant");
6193 value = error_mark_node;
6194 }
6195 else if (require_constant_elements
6196 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
6197 {
6113 value = error_mark_node;
6114 }
6115 else if (require_constant_elements
6116 && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
6117 {
6198 error_init ("initializer element%s is not computable at load time",
6199 " for `%s'", NULL);
6118 error_init ("initializer element is not computable at load time");
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 {
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 {
6215 error_init ("duplicate initializer%s", " for `%s'", NULL);
6134 error_init ("duplicate initializer");
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 {
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 {
6568 error_init ("excess elements in struct initializer%s",
6569 " after `%s'", NULL_PTR);
6487 error_init ("excess elements in struct initializer");
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 {
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 {
6604 pedwarn_init ("excess elements in struct initializer%s",
6605 " after `%s'", NULL_PTR);
6522 pedwarn_init ("excess elements in struct initializer");
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 {
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 {
6669 pedwarn_init ("excess elements in union initializer%s",
6670 " after `%s'", NULL_PTR);
6586 pedwarn_init ("excess elements in union initializer");
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 {
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 {
6744 pedwarn_init ("excess elements in array initializer%s",
6745 " after `%s'", NULL_PTR);
6660 pedwarn_init ("excess elements in array initializer");
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 {
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 {
6756 pedwarn_init ("excess elements in array initializer%s",
6757 " after `%s'", NULL_PTR);
6671 pedwarn_init ("excess elements in array initializer");
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 {
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 {
6808 pedwarn_init ("excess elements in scalar initializer%s",
6809 " after `%s'", NULL_PTR);
6722 pedwarn_init ("excess elements in scalar initializer");
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 {
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 {
6926 tree t = convert_for_assignment (valtype, retval, "return",
6839 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 ---
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 ---