comparison gcc/c-typeck.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents 3bfb6c00c1e0
children 326d9e06c2e3 b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
31 #include "tm.h" 31 #include "tm.h"
32 #include "rtl.h" 32 #include "rtl.h"
33 #include "tree.h" 33 #include "tree.h"
34 #include "langhooks.h" 34 #include "langhooks.h"
35 #include "c-tree.h" 35 #include "c-tree.h"
36 #include "c-lang.h"
36 #include "tm_p.h" 37 #include "tm_p.h"
37 #include "flags.h" 38 #include "flags.h"
38 #include "output.h" 39 #include "output.h"
39 #include "expr.h" 40 #include "expr.h"
40 #include "toplev.h" 41 #include "toplev.h"
52 ic_assign, 53 ic_assign,
53 ic_init, 54 ic_init,
54 ic_return 55 ic_return
55 }; 56 };
56 57
58 /* Whether we are building a boolean conversion inside
59 convert_for_assignment, or some other late binary operation. If
60 build_binary_op is called (from code shared with C++) in this case,
61 then the operands have already been folded and the result will not
62 be folded again, so C_MAYBE_CONST_EXPR should not be generated. */
63 bool in_late_binary_op;
64
57 /* The level of nesting inside "__alignof__". */ 65 /* The level of nesting inside "__alignof__". */
58 int in_alignof; 66 int in_alignof;
59 67
60 /* The level of nesting inside "sizeof". */ 68 /* The level of nesting inside "sizeof". */
61 int in_sizeof; 69 int in_sizeof;
62 70
63 /* The level of nesting inside "typeof". */ 71 /* The level of nesting inside "typeof". */
64 int in_typeof; 72 int in_typeof;
65
66 struct c_label_context_se *label_context_stack_se;
67 struct c_label_context_vm *label_context_stack_vm;
68 73
69 /* Nonzero if we've already printed a "missing braces around initializer" 74 /* Nonzero if we've already printed a "missing braces around initializer"
70 message within this initializer. */ 75 message within this initializer. */
71 static int missing_braces_mentioned; 76 static int missing_braces_mentioned;
72 77
73 static int require_constant_value; 78 static int require_constant_value;
74 static int require_constant_elements; 79 static int require_constant_elements;
75 80
76 static bool null_pointer_constant_p (const_tree); 81 static bool null_pointer_constant_p (const_tree);
77 static tree qualify_type (tree, tree); 82 static tree qualify_type (tree, tree);
78 static int tagged_types_tu_compatible_p (const_tree, const_tree); 83 static int tagged_types_tu_compatible_p (const_tree, const_tree, bool *);
79 static int comp_target_types (tree, tree); 84 static int comp_target_types (location_t, tree, tree);
80 static int function_types_compatible_p (const_tree, const_tree); 85 static int function_types_compatible_p (const_tree, const_tree, bool *);
81 static int type_lists_compatible_p (const_tree, const_tree); 86 static int type_lists_compatible_p (const_tree, const_tree, bool *);
82 static tree decl_constant_value_for_broken_optimization (tree);
83 static tree lookup_field (tree, tree); 87 static tree lookup_field (tree, tree);
84 static int convert_arguments (int, tree *, tree, tree, tree, tree); 88 static int convert_arguments (tree, VEC(tree,gc) *, VEC(tree,gc) *, tree,
85 static tree pointer_diff (tree, tree); 89 tree);
86 static tree convert_for_assignment (tree, tree, enum impl_conv, tree, tree, 90 static tree pointer_diff (location_t, tree, tree);
87 int); 91 static tree convert_for_assignment (location_t, tree, tree, tree,
92 enum impl_conv, bool, tree, tree, int);
88 static tree valid_compound_expr_initializer (tree, tree); 93 static tree valid_compound_expr_initializer (tree, tree);
89 static void push_string (const char *); 94 static void push_string (const char *);
90 static void push_member_name (tree); 95 static void push_member_name (tree);
91 static int spelling_length (void); 96 static int spelling_length (void);
92 static char *print_spelling (char *); 97 static char *print_spelling (char *);
93 static void warning_init (int, const char *); 98 static void warning_init (int, const char *);
94 static tree digest_init (tree, tree, bool, int); 99 static tree digest_init (location_t, tree, tree, tree, bool, bool, int);
95 static void output_init_element (tree, bool, tree, tree, int, bool); 100 static void output_init_element (tree, tree, bool, tree, tree, int, bool);
96 static void output_pending_init_elements (int); 101 static void output_pending_init_elements (int);
97 static int set_designator (int); 102 static int set_designator (int);
98 static void push_range_stack (tree); 103 static void push_range_stack (tree);
99 static void add_pending_init (tree, tree, bool); 104 static void add_pending_init (tree, tree, tree, bool);
100 static void set_nonincremental_init (void); 105 static void set_nonincremental_init (void);
101 static void set_nonincremental_init_from_string (tree); 106 static void set_nonincremental_init_from_string (tree);
102 static tree find_init_member (tree); 107 static tree find_init_member (tree);
103 static void readonly_error (tree, enum lvalue_use); 108 static void readonly_error (tree, enum lvalue_use);
109 static void readonly_warning (tree, enum lvalue_use);
104 static int lvalue_or_else (const_tree, enum lvalue_use); 110 static int lvalue_or_else (const_tree, enum lvalue_use);
105 static int lvalue_p (const_tree);
106 static void record_maybe_used_decl (tree); 111 static void record_maybe_used_decl (tree);
107 static int comptypes_internal (const_tree, const_tree); 112 static int comptypes_internal (const_tree, const_tree, bool *);
108 113
109 /* Return true if EXP is a null pointer constant, false otherwise. */ 114 /* Return true if EXP is a null pointer constant, false otherwise. */
110 115
111 static bool 116 static bool
112 null_pointer_constant_p (const_tree expr) 117 null_pointer_constant_p (const_tree expr)
120 && (INTEGRAL_TYPE_P (type) 125 && (INTEGRAL_TYPE_P (type)
121 || (TREE_CODE (type) == POINTER_TYPE 126 || (TREE_CODE (type) == POINTER_TYPE
122 && VOID_TYPE_P (TREE_TYPE (type)) 127 && VOID_TYPE_P (TREE_TYPE (type))
123 && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED))); 128 && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
124 } 129 }
130
131 /* EXPR may appear in an unevaluated part of an integer constant
132 expression, but not in an evaluated part. Wrap it in a
133 C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
134 INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR. */
135
136 static tree
137 note_integer_operands (tree expr)
138 {
139 tree ret;
140 if (TREE_CODE (expr) == INTEGER_CST && in_late_binary_op)
141 {
142 ret = copy_node (expr);
143 TREE_OVERFLOW (ret) = 1;
144 }
145 else
146 {
147 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL_TREE, expr);
148 C_MAYBE_CONST_EXPR_INT_OPERANDS (ret) = 1;
149 }
150 return ret;
151 }
152
153 /* Having checked whether EXPR may appear in an unevaluated part of an
154 integer constant expression and found that it may, remove any
155 C_MAYBE_CONST_EXPR noting this fact and return the resulting
156 expression. */
157
158 static inline tree
159 remove_c_maybe_const_expr (tree expr)
160 {
161 if (TREE_CODE (expr) == C_MAYBE_CONST_EXPR)
162 return C_MAYBE_CONST_EXPR_EXPR (expr);
163 else
164 return expr;
165 }
166
125 /* This is a cache to hold if two types are compatible or not. */ 167 /* This is a cache to hold if two types are compatible or not. */
126 168
127 struct tagged_tu_seen_cache { 169 struct tagged_tu_seen_cache {
128 const struct tagged_tu_seen_cache * next; 170 const struct tagged_tu_seen_cache * next;
129 const_tree t1; 171 const_tree t1;
240 } 282 }
241 283
242 return type; 284 return type;
243 } 285 }
244 286
287 /* Return true if between two named address spaces, whether there is a superset
288 named address space that encompasses both address spaces. If there is a
289 superset, return which address space is the superset. */
290
291 static bool
292 addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
293 {
294 if (as1 == as2)
295 {
296 *common = as1;
297 return true;
298 }
299 else if (targetm.addr_space.subset_p (as1, as2))
300 {
301 *common = as2;
302 return true;
303 }
304 else if (targetm.addr_space.subset_p (as2, as1))
305 {
306 *common = as1;
307 return true;
308 }
309 else
310 return false;
311 }
312
245 /* Return a variant of TYPE which has all the type qualifiers of LIKE 313 /* Return a variant of TYPE which has all the type qualifiers of LIKE
246 as well as those of TYPE. */ 314 as well as those of TYPE. */
247 315
248 static tree 316 static tree
249 qualify_type (tree type, tree like) 317 qualify_type (tree type, tree like)
250 { 318 {
319 addr_space_t as_type = TYPE_ADDR_SPACE (type);
320 addr_space_t as_like = TYPE_ADDR_SPACE (like);
321 addr_space_t as_common;
322
323 /* If the two named address spaces are different, determine the common
324 superset address space. If there isn't one, raise an error. */
325 if (!addr_space_superset (as_type, as_like, &as_common))
326 {
327 as_common = as_type;
328 error ("%qT and %qT are in disjoint named address spaces",
329 type, like);
330 }
331
251 return c_build_qualified_type (type, 332 return c_build_qualified_type (type,
252 TYPE_QUALS (type) | TYPE_QUALS (like)); 333 TYPE_QUALS_NO_ADDR_SPACE (type)
334 | TYPE_QUALS_NO_ADDR_SPACE (like)
335 | ENCODE_QUAL_ADDR_SPACE (as_common));
253 } 336 }
254 337
255 /* Return true iff the given tree T is a variable length array. */ 338 /* Return true iff the given tree T is a variable length array. */
256 339
257 bool 340 bool
327 bool d1_variable, d2_variable; 410 bool d1_variable, d2_variable;
328 bool d1_zero, d2_zero; 411 bool d1_zero, d2_zero;
329 bool t1_complete, t2_complete; 412 bool t1_complete, t2_complete;
330 413
331 /* We should not have any type quals on arrays at all. */ 414 /* We should not have any type quals on arrays at all. */
332 gcc_assert (!TYPE_QUALS (t1) && !TYPE_QUALS (t2)); 415 gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1)
416 && !TYPE_QUALS_NO_ADDR_SPACE (t2));
333 417
334 t1_complete = COMPLETE_TYPE_P (t1); 418 t1_complete = COMPLETE_TYPE_P (t1);
335 t2_complete = COMPLETE_TYPE_P (t2); 419 t2_complete = COMPLETE_TYPE_P (t2);
336 420
337 d1_zero = d1 == 0 || !TYPE_MAX_VALUE (d1); 421 d1_zero = d1 == 0 || !TYPE_MAX_VALUE (d1);
480 mv3 = TYPE_MAIN_VARIANT (mv3); 564 mv3 = TYPE_MAIN_VARIANT (mv3);
481 if (comptypes (mv3, mv2)) 565 if (comptypes (mv3, mv2))
482 { 566 {
483 TREE_VALUE (n) = composite_type (TREE_TYPE (memb), 567 TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
484 TREE_VALUE (p2)); 568 TREE_VALUE (p2));
485 pedwarn (input_location, OPT_pedantic, 569 pedwarn (input_location, OPT_pedantic,
486 "function types not truly compatible in ISO C"); 570 "function types not truly compatible in ISO C");
487 goto parm_done; 571 goto parm_done;
488 } 572 }
489 } 573 }
490 } 574 }
505 mv3 = TYPE_MAIN_VARIANT (mv3); 589 mv3 = TYPE_MAIN_VARIANT (mv3);
506 if (comptypes (mv3, mv1)) 590 if (comptypes (mv3, mv1))
507 { 591 {
508 TREE_VALUE (n) = composite_type (TREE_TYPE (memb), 592 TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
509 TREE_VALUE (p1)); 593 TREE_VALUE (p1));
510 pedwarn (input_location, OPT_pedantic, 594 pedwarn (input_location, OPT_pedantic,
511 "function types not truly compatible in ISO C"); 595 "function types not truly compatible in ISO C");
512 goto parm_done; 596 goto parm_done;
513 } 597 }
514 } 598 }
515 } 599 }
541 tree attributes; 625 tree attributes;
542 tree pointed_to_1, mv1; 626 tree pointed_to_1, mv1;
543 tree pointed_to_2, mv2; 627 tree pointed_to_2, mv2;
544 tree target; 628 tree target;
545 unsigned target_quals; 629 unsigned target_quals;
630 addr_space_t as1, as2, as_common;
631 int quals1, quals2;
546 632
547 /* Save time if the two types are the same. */ 633 /* Save time if the two types are the same. */
548 634
549 if (t1 == t2) return t1; 635 if (t1 == t2) return t1;
550 636
572 target = composite_type (mv1, mv2); 658 target = composite_type (mv1, mv2);
573 659
574 /* For function types do not merge const qualifiers, but drop them 660 /* For function types do not merge const qualifiers, but drop them
575 if used inconsistently. The middle-end uses these to mark const 661 if used inconsistently. The middle-end uses these to mark const
576 and noreturn functions. */ 662 and noreturn functions. */
663 quals1 = TYPE_QUALS_NO_ADDR_SPACE (pointed_to_1);
664 quals2 = TYPE_QUALS_NO_ADDR_SPACE (pointed_to_2);
665
577 if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE) 666 if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
578 target_quals = TYPE_QUALS (pointed_to_1) & TYPE_QUALS (pointed_to_2); 667 target_quals = (quals1 & quals2);
579 else 668 else
580 target_quals = TYPE_QUALS (pointed_to_1) | TYPE_QUALS (pointed_to_2); 669 target_quals = (quals1 | quals2);
670
671 /* If the two named address spaces are different, determine the common
672 superset address space. This is guaranteed to exist due to the
673 assumption that comp_target_type returned non-zero. */
674 as1 = TYPE_ADDR_SPACE (pointed_to_1);
675 as2 = TYPE_ADDR_SPACE (pointed_to_2);
676 if (!addr_space_superset (as1, as2, &as_common))
677 gcc_unreachable ();
678
679 target_quals |= ENCODE_QUAL_ADDR_SPACE (as_common);
680
581 t1 = build_pointer_type (c_build_qualified_type (target, target_quals)); 681 t1 = build_pointer_type (c_build_qualified_type (target, target_quals));
582 return build_type_attribute_variant (t1, attributes); 682 return build_type_attribute_variant (t1, attributes);
583 } 683 }
584 684
585 /* Return the common type for two arithmetic types under the usual 685 /* Return the common type for two arithmetic types under the usual
873 comptypes (tree type1, tree type2) 973 comptypes (tree type1, tree type2)
874 { 974 {
875 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base; 975 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
876 int val; 976 int val;
877 977
878 val = comptypes_internal (type1, type2); 978 val = comptypes_internal (type1, type2, NULL);
979 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
980
981 return val;
982 }
983
984 /* Like comptypes, but if it returns non-zero because enum and int are
985 compatible, it sets *ENUM_AND_INT_P to true. */
986
987 static int
988 comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
989 {
990 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
991 int val;
992
993 val = comptypes_internal (type1, type2, enum_and_int_p);
879 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1); 994 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
880 995
881 return val; 996 return val;
882 } 997 }
883 998
884 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment 999 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
885 or various other operations. Return 2 if they are compatible 1000 or various other operations. Return 2 if they are compatible
886 but a warning may be needed if you use them together. This 1001 but a warning may be needed if you use them together. If
887 differs from comptypes, in that we don't free the seen types. */ 1002 ENUM_AND_INT_P is not NULL, and one type is an enum and the other a
1003 compatible integer type, then this sets *ENUM_AND_INT_P to true;
1004 *ENUM_AND_INT_P is never set to false. This differs from
1005 comptypes, in that we don't free the seen types. */
888 1006
889 static int 1007 static int
890 comptypes_internal (const_tree type1, const_tree type2) 1008 comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p)
891 { 1009 {
892 const_tree t1 = type1; 1010 const_tree t1 = type1;
893 const_tree t2 = type2; 1011 const_tree t2 = type2;
894 int attrval, val; 1012 int attrval, val;
895 1013
913 /* Enumerated types are compatible with integer types, but this is 1031 /* Enumerated types are compatible with integer types, but this is
914 not transitive: two enumerated types in the same translation unit 1032 not transitive: two enumerated types in the same translation unit
915 are compatible with each other only if they are the same type. */ 1033 are compatible with each other only if they are the same type. */
916 1034
917 if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE) 1035 if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE)
918 t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1)); 1036 {
1037 t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1));
1038 if (enum_and_int_p != NULL && TREE_CODE (t2) != VOID_TYPE)
1039 *enum_and_int_p = true;
1040 }
919 else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE) 1041 else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE)
920 t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2)); 1042 {
1043 t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2));
1044 if (enum_and_int_p != NULL && TREE_CODE (t1) != VOID_TYPE)
1045 *enum_and_int_p = true;
1046 }
921 1047
922 if (t1 == t2) 1048 if (t1 == t2)
923 return 1; 1049 return 1;
924 1050
925 /* Different classes of types can't be compatible. */ 1051 /* Different classes of types can't be compatible. */
953 /* Do not remove mode or aliasing information. */ 1079 /* Do not remove mode or aliasing information. */
954 if (TYPE_MODE (t1) != TYPE_MODE (t2) 1080 if (TYPE_MODE (t1) != TYPE_MODE (t2)
955 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) 1081 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
956 break; 1082 break;
957 val = (TREE_TYPE (t1) == TREE_TYPE (t2) 1083 val = (TREE_TYPE (t1) == TREE_TYPE (t2)
958 ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2))); 1084 ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1085 enum_and_int_p));
959 break; 1086 break;
960 1087
961 case FUNCTION_TYPE: 1088 case FUNCTION_TYPE:
962 val = function_types_compatible_p (t1, t2); 1089 val = function_types_compatible_p (t1, t2, enum_and_int_p);
963 break; 1090 break;
964 1091
965 case ARRAY_TYPE: 1092 case ARRAY_TYPE:
966 { 1093 {
967 tree d1 = TYPE_DOMAIN (t1); 1094 tree d1 = TYPE_DOMAIN (t1);
970 bool d1_zero, d2_zero; 1097 bool d1_zero, d2_zero;
971 val = 1; 1098 val = 1;
972 1099
973 /* Target types must match incl. qualifiers. */ 1100 /* Target types must match incl. qualifiers. */
974 if (TREE_TYPE (t1) != TREE_TYPE (t2) 1101 if (TREE_TYPE (t1) != TREE_TYPE (t2)
975 && 0 == (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2)))) 1102 && 0 == (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1103 enum_and_int_p)))
976 return 0; 1104 return 0;
977 1105
978 /* Sizes must match unless one is missing or variable. */ 1106 /* Sizes must match unless one is missing or variable. */
979 if (d1 == 0 || d2 == 0 || d1 == d2) 1107 if (d1 == 0 || d2 == 0 || d1 == d2)
980 break; 1108 break;
1014 if (! attribute_list_contained (a1, a2) 1142 if (! attribute_list_contained (a1, a2)
1015 && ! attribute_list_contained (a2, a1)) 1143 && ! attribute_list_contained (a2, a1))
1016 break; 1144 break;
1017 1145
1018 if (attrval != 2) 1146 if (attrval != 2)
1019 return tagged_types_tu_compatible_p (t1, t2); 1147 return tagged_types_tu_compatible_p (t1, t2, enum_and_int_p);
1020 val = tagged_types_tu_compatible_p (t1, t2); 1148 val = tagged_types_tu_compatible_p (t1, t2, enum_and_int_p);
1021 } 1149 }
1022 break; 1150 break;
1023 1151
1024 case VECTOR_TYPE: 1152 case VECTOR_TYPE:
1025 val = TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2) 1153 val = (TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
1026 && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2)); 1154 && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1155 enum_and_int_p));
1027 break; 1156 break;
1028 1157
1029 default: 1158 default:
1030 break; 1159 break;
1031 } 1160 }
1032 return attrval == 2 && val == 1 ? 2 : val; 1161 return attrval == 2 && val == 1 ? 2 : val;
1033 } 1162 }
1034 1163
1035 /* Return 1 if TTL and TTR are pointers to types that are equivalent, 1164 /* Return 1 if TTL and TTR are pointers to types that are equivalent, ignoring
1036 ignoring their qualifiers. */ 1165 their qualifiers, except for named address spaces. If the pointers point to
1166 different named addresses, then we must determine if one address space is a
1167 subset of the other. */
1037 1168
1038 static int 1169 static int
1039 comp_target_types (tree ttl, tree ttr) 1170 comp_target_types (location_t location, tree ttl, tree ttr)
1040 { 1171 {
1041 int val; 1172 int val;
1042 tree mvl, mvr; 1173 tree mvl = TREE_TYPE (ttl);
1174 tree mvr = TREE_TYPE (ttr);
1175 addr_space_t asl = TYPE_ADDR_SPACE (mvl);
1176 addr_space_t asr = TYPE_ADDR_SPACE (mvr);
1177 addr_space_t as_common;
1178 bool enum_and_int_p;
1179
1180 /* Fail if pointers point to incompatible address spaces. */
1181 if (!addr_space_superset (asl, asr, &as_common))
1182 return 0;
1043 1183
1044 /* Do not lose qualifiers on element types of array types that are 1184 /* Do not lose qualifiers on element types of array types that are
1045 pointer targets by taking their TYPE_MAIN_VARIANT. */ 1185 pointer targets by taking their TYPE_MAIN_VARIANT. */
1046 mvl = TREE_TYPE (ttl);
1047 mvr = TREE_TYPE (ttr);
1048 if (TREE_CODE (mvl) != ARRAY_TYPE) 1186 if (TREE_CODE (mvl) != ARRAY_TYPE)
1049 mvl = TYPE_MAIN_VARIANT (mvl); 1187 mvl = TYPE_MAIN_VARIANT (mvl);
1050 if (TREE_CODE (mvr) != ARRAY_TYPE) 1188 if (TREE_CODE (mvr) != ARRAY_TYPE)
1051 mvr = TYPE_MAIN_VARIANT (mvr); 1189 mvr = TYPE_MAIN_VARIANT (mvr);
1052 val = comptypes (mvl, mvr); 1190 enum_and_int_p = false;
1191 val = comptypes_check_enum_int (mvl, mvr, &enum_and_int_p);
1053 1192
1054 if (val == 2) 1193 if (val == 2)
1055 pedwarn (input_location, OPT_pedantic, "types are not quite compatible"); 1194 pedwarn (location, OPT_pedantic, "types are not quite compatible");
1195
1196 if (val == 1 && enum_and_int_p && warn_cxx_compat)
1197 warning_at (location, OPT_Wc___compat,
1198 "pointer target types incompatible in C++");
1199
1056 return val; 1200 return val;
1057 } 1201 }
1058 1202
1059 /* Subroutines of `comptypes'. */ 1203 /* Subroutines of `comptypes'. */
1060 1204
1138 1282
1139 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are 1283 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are
1140 compatible. If the two types are not the same (which has been 1284 compatible. If the two types are not the same (which has been
1141 checked earlier), this can only happen when multiple translation 1285 checked earlier), this can only happen when multiple translation
1142 units are being compiled. See C99 6.2.7 paragraph 1 for the exact 1286 units are being compiled. See C99 6.2.7 paragraph 1 for the exact
1143 rules. */ 1287 rules. ENUM_AND_INT_P is as in comptypes_internal. */
1144 1288
1145 static int 1289 static int
1146 tagged_types_tu_compatible_p (const_tree t1, const_tree t2) 1290 tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
1291 bool *enum_and_int_p)
1147 { 1292 {
1148 tree s1, s2; 1293 tree s1, s2;
1149 bool needs_warning = false; 1294 bool needs_warning = false;
1150 1295
1151 /* We have to verify that the tags of the types are the same. This 1296 /* We have to verify that the tags of the types are the same. This
1251 { 1396 {
1252 int result; 1397 int result;
1253 1398
1254 if (DECL_NAME (s1) != DECL_NAME (s2)) 1399 if (DECL_NAME (s1) != DECL_NAME (s2))
1255 break; 1400 break;
1256 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2)); 1401 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
1402 enum_and_int_p);
1257 1403
1258 if (result != 1 && !DECL_NAME (s1)) 1404 if (result != 1 && !DECL_NAME (s1))
1259 break; 1405 break;
1260 if (result == 0) 1406 if (result == 0)
1261 { 1407 {
1286 for (s2 = TYPE_FIELDS (t2); s2; s2 = TREE_CHAIN (s2)) 1432 for (s2 = TYPE_FIELDS (t2); s2; s2 = TREE_CHAIN (s2))
1287 if (DECL_NAME (s1) == DECL_NAME (s2)) 1433 if (DECL_NAME (s1) == DECL_NAME (s2))
1288 { 1434 {
1289 int result; 1435 int result;
1290 1436
1291 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2)); 1437 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
1438 enum_and_int_p);
1292 1439
1293 if (result != 1 && !DECL_NAME (s1)) 1440 if (result != 1 && !DECL_NAME (s1))
1294 continue; 1441 continue;
1295 if (result == 0) 1442 if (result == 0)
1296 { 1443 {
1328 { 1475 {
1329 int result; 1476 int result;
1330 if (TREE_CODE (s1) != TREE_CODE (s2) 1477 if (TREE_CODE (s1) != TREE_CODE (s2)
1331 || DECL_NAME (s1) != DECL_NAME (s2)) 1478 || DECL_NAME (s1) != DECL_NAME (s2))
1332 break; 1479 break;
1333 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2)); 1480 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
1481 enum_and_int_p);
1334 if (result == 0) 1482 if (result == 0)
1335 break; 1483 break;
1336 if (result == 2) 1484 if (result == 2)
1337 needs_warning = true; 1485 needs_warning = true;
1338 1486
1356 /* Return 1 if two function types F1 and F2 are compatible. 1504 /* Return 1 if two function types F1 and F2 are compatible.
1357 If either type specifies no argument types, 1505 If either type specifies no argument types,
1358 the other must specify a fixed number of self-promoting arg types. 1506 the other must specify a fixed number of self-promoting arg types.
1359 Otherwise, if one type specifies only the number of arguments, 1507 Otherwise, if one type specifies only the number of arguments,
1360 the other must specify that number of self-promoting arg types. 1508 the other must specify that number of self-promoting arg types.
1361 Otherwise, the argument types must match. */ 1509 Otherwise, the argument types must match.
1510 ENUM_AND_INT_P is as in comptypes_internal. */
1362 1511
1363 static int 1512 static int
1364 function_types_compatible_p (const_tree f1, const_tree f2) 1513 function_types_compatible_p (const_tree f1, const_tree f2,
1514 bool *enum_and_int_p)
1365 { 1515 {
1366 tree args1, args2; 1516 tree args1, args2;
1367 /* 1 if no need for warning yet, 2 if warning cause has been seen. */ 1517 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1368 int val = 1; 1518 int val = 1;
1369 int val1; 1519 int val1;
1380 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1), 1530 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
1381 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE); 1531 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
1382 if (TYPE_VOLATILE (ret2)) 1532 if (TYPE_VOLATILE (ret2))
1383 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2), 1533 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
1384 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE); 1534 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
1385 val = comptypes_internal (ret1, ret2); 1535 val = comptypes_internal (ret1, ret2, enum_and_int_p);
1386 if (val == 0) 1536 if (val == 0)
1387 return 0; 1537 return 0;
1388 1538
1389 args1 = TYPE_ARG_TYPES (f1); 1539 args1 = TYPE_ARG_TYPES (f1);
1390 args2 = TYPE_ARG_TYPES (f2); 1540 args2 = TYPE_ARG_TYPES (f2);
1398 return 0; 1548 return 0;
1399 /* If one of these types comes from a non-prototype fn definition, 1549 /* If one of these types comes from a non-prototype fn definition,
1400 compare that with the other type's arglist. 1550 compare that with the other type's arglist.
1401 If they don't match, ask for a warning (but no error). */ 1551 If they don't match, ask for a warning (but no error). */
1402 if (TYPE_ACTUAL_ARG_TYPES (f1) 1552 if (TYPE_ACTUAL_ARG_TYPES (f1)
1403 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1))) 1553 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1),
1554 enum_and_int_p))
1404 val = 2; 1555 val = 2;
1405 return val; 1556 return val;
1406 } 1557 }
1407 if (args2 == 0) 1558 if (args2 == 0)
1408 { 1559 {
1409 if (!self_promoting_args_p (args1)) 1560 if (!self_promoting_args_p (args1))
1410 return 0; 1561 return 0;
1411 if (TYPE_ACTUAL_ARG_TYPES (f2) 1562 if (TYPE_ACTUAL_ARG_TYPES (f2)
1412 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2))) 1563 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2),
1564 enum_and_int_p))
1413 val = 2; 1565 val = 2;
1414 return val; 1566 return val;
1415 } 1567 }
1416 1568
1417 /* Both types have argument lists: compare them and propagate results. */ 1569 /* Both types have argument lists: compare them and propagate results. */
1418 val1 = type_lists_compatible_p (args1, args2); 1570 val1 = type_lists_compatible_p (args1, args2, enum_and_int_p);
1419 return val1 != 1 ? val1 : val; 1571 return val1 != 1 ? val1 : val;
1420 } 1572 }
1421 1573
1422 /* Check two lists of types for compatibility, 1574 /* Check two lists of types for compatibility, returning 0 for
1423 returning 0 for incompatible, 1 for compatible, 1575 incompatible, 1 for compatible, or 2 for compatible with
1424 or 2 for compatible with warning. */ 1576 warning. ENUM_AND_INT_P is as in comptypes_internal. */
1425 1577
1426 static int 1578 static int
1427 type_lists_compatible_p (const_tree args1, const_tree args2) 1579 type_lists_compatible_p (const_tree args1, const_tree args2,
1580 bool *enum_and_int_p)
1428 { 1581 {
1429 /* 1 if no need for warning yet, 2 if warning cause has been seen. */ 1582 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1430 int val = 1; 1583 int val = 1;
1431 int newval = 0; 1584 int newval = 0;
1432 1585
1461 } 1614 }
1462 /* If one of the lists has an error marker, ignore this arg. */ 1615 /* If one of the lists has an error marker, ignore this arg. */
1463 else if (TREE_CODE (a1) == ERROR_MARK 1616 else if (TREE_CODE (a1) == ERROR_MARK
1464 || TREE_CODE (a2) == ERROR_MARK) 1617 || TREE_CODE (a2) == ERROR_MARK)
1465 ; 1618 ;
1466 else if (!(newval = comptypes_internal (mv1, mv2))) 1619 else if (!(newval = comptypes_internal (mv1, mv2, enum_and_int_p)))
1467 { 1620 {
1468 /* Allow wait (union {union wait *u; int *i} *) 1621 /* Allow wait (union {union wait *u; int *i} *)
1469 and wait (union wait *) to be compatible. */ 1622 and wait (union wait *) to be compatible. */
1470 if (TREE_CODE (a1) == UNION_TYPE 1623 if (TREE_CODE (a1) == UNION_TYPE
1471 && (TYPE_NAME (a1) == 0 1624 && (TYPE_NAME (a1) == 0
1480 { 1633 {
1481 tree mv3 = TREE_TYPE (memb); 1634 tree mv3 = TREE_TYPE (memb);
1482 if (mv3 && mv3 != error_mark_node 1635 if (mv3 && mv3 != error_mark_node
1483 && TREE_CODE (mv3) != ARRAY_TYPE) 1636 && TREE_CODE (mv3) != ARRAY_TYPE)
1484 mv3 = TYPE_MAIN_VARIANT (mv3); 1637 mv3 = TYPE_MAIN_VARIANT (mv3);
1485 if (comptypes_internal (mv3, mv2)) 1638 if (comptypes_internal (mv3, mv2, enum_and_int_p))
1486 break; 1639 break;
1487 } 1640 }
1488 if (memb == 0) 1641 if (memb == 0)
1489 return 0; 1642 return 0;
1490 } 1643 }
1501 { 1654 {
1502 tree mv3 = TREE_TYPE (memb); 1655 tree mv3 = TREE_TYPE (memb);
1503 if (mv3 && mv3 != error_mark_node 1656 if (mv3 && mv3 != error_mark_node
1504 && TREE_CODE (mv3) != ARRAY_TYPE) 1657 && TREE_CODE (mv3) != ARRAY_TYPE)
1505 mv3 = TYPE_MAIN_VARIANT (mv3); 1658 mv3 = TYPE_MAIN_VARIANT (mv3);
1506 if (comptypes_internal (mv3, mv1)) 1659 if (comptypes_internal (mv3, mv1, enum_and_int_p))
1507 break; 1660 break;
1508 } 1661 }
1509 if (memb == 0) 1662 if (memb == 0)
1510 return 0; 1663 return 0;
1511 } 1664 }
1537 error ("arithmetic on pointer to an incomplete type"); 1690 error ("arithmetic on pointer to an incomplete type");
1538 return size_one_node; 1691 return size_one_node;
1539 } 1692 }
1540 1693
1541 /* Convert in case a char is more than one unit. */ 1694 /* Convert in case a char is more than one unit. */
1542 return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type), 1695 return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
1543 size_int (TYPE_PRECISION (char_type_node) 1696 size_int (TYPE_PRECISION (char_type_node)
1544 / BITS_PER_UNIT)); 1697 / BITS_PER_UNIT));
1545 } 1698 }
1546 1699
1547 /* Return either DECL or its known constant value (if it has one). */ 1700 /* Return either DECL or its known constant value (if it has one). */
1548 1701
1549 tree 1702 tree
1566 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR) 1719 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
1567 return DECL_INITIAL (decl); 1720 return DECL_INITIAL (decl);
1568 return decl; 1721 return decl;
1569 } 1722 }
1570 1723
1571 /* Return either DECL or its known constant value (if it has one), but
1572 return DECL if pedantic or DECL has mode BLKmode. This is for
1573 bug-compatibility with the old behavior of decl_constant_value
1574 (before GCC 3.0); every use of this function is a bug and it should
1575 be removed before GCC 3.1. It is not appropriate to use pedantic
1576 in a way that affects optimization, and BLKmode is probably not the
1577 right test for avoiding misoptimizations either. */
1578
1579 static tree
1580 decl_constant_value_for_broken_optimization (tree decl)
1581 {
1582 tree ret;
1583
1584 if (pedantic || DECL_MODE (decl) == BLKmode)
1585 return decl;
1586
1587 ret = decl_constant_value (decl);
1588 /* Avoid unwanted tree sharing between the initializer and current
1589 function's body where the tree can be modified e.g. by the
1590 gimplifier. */
1591 if (ret != decl && TREE_STATIC (decl))
1592 ret = unshare_expr (ret);
1593 return ret;
1594 }
1595
1596 /* Convert the array expression EXP to a pointer. */ 1724 /* Convert the array expression EXP to a pointer. */
1597 static tree 1725 static tree
1598 array_to_pointer_conversion (tree exp) 1726 array_to_pointer_conversion (location_t loc, tree exp)
1599 { 1727 {
1600 tree orig_exp = exp; 1728 tree orig_exp = exp;
1601 tree type = TREE_TYPE (exp); 1729 tree type = TREE_TYPE (exp);
1602 tree adr; 1730 tree adr;
1603 tree restype = TREE_TYPE (type); 1731 tree restype = TREE_TYPE (type);
1613 ptrtype = build_pointer_type (restype); 1741 ptrtype = build_pointer_type (restype);
1614 1742
1615 if (TREE_CODE (exp) == INDIRECT_REF) 1743 if (TREE_CODE (exp) == INDIRECT_REF)
1616 return convert (ptrtype, TREE_OPERAND (exp, 0)); 1744 return convert (ptrtype, TREE_OPERAND (exp, 0));
1617 1745
1618 if (TREE_CODE (exp) == VAR_DECL) 1746 adr = build_unary_op (loc, ADDR_EXPR, exp, 1);
1619 {
1620 /* We are making an ADDR_EXPR of ptrtype. This is a valid
1621 ADDR_EXPR because it's the best way of representing what
1622 happens in C when we take the address of an array and place
1623 it in a pointer to the element type. */
1624 adr = build1 (ADDR_EXPR, ptrtype, exp);
1625 if (!c_mark_addressable (exp))
1626 return error_mark_node;
1627 TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */
1628 return adr;
1629 }
1630
1631 /* This way is better for a COMPONENT_REF since it can
1632 simplify the offset for a component. */
1633 adr = build_unary_op (EXPR_LOCATION (exp), ADDR_EXPR, exp, 1);
1634 return convert (ptrtype, adr); 1747 return convert (ptrtype, adr);
1635 } 1748 }
1636 1749
1637 /* Convert the function expression EXP to a pointer. */ 1750 /* Convert the function expression EXP to a pointer. */
1638 static tree 1751 static tree
1639 function_to_pointer_conversion (tree exp) 1752 function_to_pointer_conversion (location_t loc, tree exp)
1640 { 1753 {
1641 tree orig_exp = exp; 1754 tree orig_exp = exp;
1642 1755
1643 gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE); 1756 gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
1644 1757
1645 STRIP_TYPE_NOPS (exp); 1758 STRIP_TYPE_NOPS (exp);
1646 1759
1647 if (TREE_NO_WARNING (orig_exp)) 1760 if (TREE_NO_WARNING (orig_exp))
1648 TREE_NO_WARNING (exp) = 1; 1761 TREE_NO_WARNING (exp) = 1;
1649 1762
1650 return build_unary_op (EXPR_LOCATION (exp), ADDR_EXPR, exp, 0); 1763 return build_unary_op (loc, ADDR_EXPR, exp, 0);
1651 } 1764 }
1652 1765
1653 /* Perform the default conversion of arrays and functions to pointers. 1766 /* Perform the default conversion of arrays and functions to pointers.
1654 Return the result of converting EXP. For any other expression, just 1767 Return the result of converting EXP. For any other expression, just
1655 return EXP after removing NOPs. */ 1768 return EXP.
1769
1770 LOC is the location of the expression. */
1656 1771
1657 struct c_expr 1772 struct c_expr
1658 default_function_array_conversion (struct c_expr exp) 1773 default_function_array_conversion (location_t loc, struct c_expr exp)
1659 { 1774 {
1660 tree orig_exp = exp.value; 1775 tree orig_exp = exp.value;
1661 tree type = TREE_TYPE (exp.value); 1776 tree type = TREE_TYPE (exp.value);
1662 enum tree_code code = TREE_CODE (type); 1777 enum tree_code code = TREE_CODE (type);
1663 1778
1688 be used correctly inside sizeof or as a statement expression. 1803 be used correctly inside sizeof or as a statement expression.
1689 Thus, do not give an error here; an error will result later. */ 1804 Thus, do not give an error here; an error will result later. */
1690 return exp; 1805 return exp;
1691 } 1806 }
1692 1807
1693 exp.value = array_to_pointer_conversion (exp.value); 1808 exp.value = array_to_pointer_conversion (loc, exp.value);
1694 } 1809 }
1695 break; 1810 break;
1696 case FUNCTION_TYPE: 1811 case FUNCTION_TYPE:
1697 exp.value = function_to_pointer_conversion (exp.value); 1812 exp.value = function_to_pointer_conversion (loc, exp.value);
1698 break; 1813 break;
1699 default: 1814 default:
1700 STRIP_TYPE_NOPS (exp.value);
1701 if (TREE_NO_WARNING (orig_exp))
1702 TREE_NO_WARNING (exp.value) = 1;
1703 break; 1815 break;
1704 } 1816 }
1705 1817
1706 return exp; 1818 return exp;
1707 } 1819 }
1763 default_conversion (tree exp) 1875 default_conversion (tree exp)
1764 { 1876 {
1765 tree orig_exp; 1877 tree orig_exp;
1766 tree type = TREE_TYPE (exp); 1878 tree type = TREE_TYPE (exp);
1767 enum tree_code code = TREE_CODE (type); 1879 enum tree_code code = TREE_CODE (type);
1880 tree promoted_type;
1768 1881
1769 /* Functions and arrays have been converted during parsing. */ 1882 /* Functions and arrays have been converted during parsing. */
1770 gcc_assert (code != FUNCTION_TYPE); 1883 gcc_assert (code != FUNCTION_TYPE);
1771 if (code == ARRAY_TYPE) 1884 if (code == ARRAY_TYPE)
1772 return exp; 1885 return exp;
1773 1886
1774 /* Constants can be used directly unless they're not loadable. */ 1887 /* Constants can be used directly unless they're not loadable. */
1775 if (TREE_CODE (exp) == CONST_DECL) 1888 if (TREE_CODE (exp) == CONST_DECL)
1776 exp = DECL_INITIAL (exp); 1889 exp = DECL_INITIAL (exp);
1777 1890
1778 /* Replace a nonvolatile const static variable with its value unless
1779 it is an array, in which case we must be sure that taking the
1780 address of the array produces consistent results. */
1781 else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE)
1782 {
1783 exp = decl_constant_value_for_broken_optimization (exp);
1784 type = TREE_TYPE (exp);
1785 }
1786
1787 /* Strip no-op conversions. */ 1891 /* Strip no-op conversions. */
1788 orig_exp = exp; 1892 orig_exp = exp;
1789 STRIP_TYPE_NOPS (exp); 1893 STRIP_TYPE_NOPS (exp);
1790 1894
1791 if (TREE_NO_WARNING (orig_exp)) 1895 if (TREE_NO_WARNING (orig_exp))
1798 } 1902 }
1799 1903
1800 exp = require_complete_type (exp); 1904 exp = require_complete_type (exp);
1801 if (exp == error_mark_node) 1905 if (exp == error_mark_node)
1802 return error_mark_node; 1906 return error_mark_node;
1907
1908 promoted_type = targetm.promoted_type (type);
1909 if (promoted_type)
1910 return convert (promoted_type, exp);
1803 1911
1804 if (INTEGRAL_TYPE_P (type)) 1912 if (INTEGRAL_TYPE_P (type))
1805 return perform_integral_promotions (exp); 1913 return perform_integral_promotions (exp);
1806 1914
1807 return exp; 1915 return exp;
1900 } 2008 }
1901 2009
1902 return tree_cons (NULL_TREE, field, NULL_TREE); 2010 return tree_cons (NULL_TREE, field, NULL_TREE);
1903 } 2011 }
1904 2012
1905 /* Make an expression to refer to the COMPONENT field of 2013 /* Make an expression to refer to the COMPONENT field of structure or
1906 structure or union value DATUM. COMPONENT is an IDENTIFIER_NODE. */ 2014 union value DATUM. COMPONENT is an IDENTIFIER_NODE. LOC is the
2015 location of the COMPONENT_REF. */
1907 2016
1908 tree 2017 tree
1909 build_component_ref (tree datum, tree component) 2018 build_component_ref (location_t loc, tree datum, tree component)
1910 { 2019 {
1911 tree type = TREE_TYPE (datum); 2020 tree type = TREE_TYPE (datum);
1912 enum tree_code code = TREE_CODE (type); 2021 enum tree_code code = TREE_CODE (type);
1913 tree field = NULL; 2022 tree field = NULL;
1914 tree ref; 2023 tree ref;
2024 bool datum_lvalue = lvalue_p (datum);
1915 2025
1916 if (!objc_is_public (datum, component)) 2026 if (!objc_is_public (datum, component))
1917 return error_mark_node; 2027 return error_mark_node;
1918 2028
1919 /* See if there is a field or component with name COMPONENT. */ 2029 /* See if there is a field or component with name COMPONENT. */
1928 2038
1929 field = lookup_field (datum, component); 2039 field = lookup_field (datum, component);
1930 2040
1931 if (!field) 2041 if (!field)
1932 { 2042 {
1933 error ("%qT has no member named %qE", type, component); 2043 error_at (loc, "%qT has no member named %qE", type, component);
1934 return error_mark_node; 2044 return error_mark_node;
1935 } 2045 }
1936 2046
1937 /* Chain the COMPONENT_REFs if necessary down to the FIELD. 2047 /* Chain the COMPONENT_REFs if necessary down to the FIELD.
1938 This might be better solved in future the way the C++ front 2048 This might be better solved in future the way the C++ front
1942 do 2052 do
1943 { 2053 {
1944 tree subdatum = TREE_VALUE (field); 2054 tree subdatum = TREE_VALUE (field);
1945 int quals; 2055 int quals;
1946 tree subtype; 2056 tree subtype;
2057 bool use_datum_quals;
1947 2058
1948 if (TREE_TYPE (subdatum) == error_mark_node) 2059 if (TREE_TYPE (subdatum) == error_mark_node)
1949 return error_mark_node; 2060 return error_mark_node;
1950 2061
2062 /* If this is an rvalue, it does not have qualifiers in C
2063 standard terms and we must avoid propagating such
2064 qualifiers down to a non-lvalue array that is then
2065 converted to a pointer. */
2066 use_datum_quals = (datum_lvalue
2067 || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
2068
1951 quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum))); 2069 quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
1952 quals |= TYPE_QUALS (TREE_TYPE (datum)); 2070 if (use_datum_quals)
2071 quals |= TYPE_QUALS (TREE_TYPE (datum));
1953 subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals); 2072 subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
1954 2073
1955 ref = build3 (COMPONENT_REF, subtype, datum, subdatum, 2074 ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
1956 NULL_TREE); 2075 NULL_TREE);
1957 if (TREE_READONLY (datum) || TREE_READONLY (subdatum)) 2076 SET_EXPR_LOCATION (ref, loc);
2077 if (TREE_READONLY (subdatum)
2078 || (use_datum_quals && TREE_READONLY (datum)))
1958 TREE_READONLY (ref) = 1; 2079 TREE_READONLY (ref) = 1;
1959 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (subdatum)) 2080 if (TREE_THIS_VOLATILE (subdatum)
2081 || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
1960 TREE_THIS_VOLATILE (ref) = 1; 2082 TREE_THIS_VOLATILE (ref) = 1;
1961 2083
1962 if (TREE_DEPRECATED (subdatum)) 2084 if (TREE_DEPRECATED (subdatum))
1963 warn_deprecated_use (subdatum); 2085 warn_deprecated_use (subdatum, NULL_TREE);
1964 2086
1965 datum = ref; 2087 datum = ref;
1966 2088
1967 field = TREE_CHAIN (field); 2089 field = TREE_CHAIN (field);
1968 } 2090 }
1969 while (field); 2091 while (field);
1970 2092
1971 return ref; 2093 return ref;
1972 } 2094 }
1973 else if (code != ERROR_MARK) 2095 else if (code != ERROR_MARK)
1974 error ("request for member %qE in something not a structure or union", 2096 error_at (loc,
1975 component); 2097 "request for member %qE in something not a structure or union",
2098 component);
1976 2099
1977 return error_mark_node; 2100 return error_mark_node;
1978 } 2101 }
1979 2102
1980 /* Given an expression PTR for a pointer, return an expression 2103 /* Given an expression PTR for a pointer, return an expression
1982 ERRORSTRING is the name of the operator to appear in error messages. 2105 ERRORSTRING is the name of the operator to appear in error messages.
1983 2106
1984 LOC is the location to use for the generated tree. */ 2107 LOC is the location to use for the generated tree. */
1985 2108
1986 tree 2109 tree
1987 build_indirect_ref (location_t loc, tree ptr, const char *errorstring) 2110 build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
1988 { 2111 {
1989 tree pointer = default_conversion (ptr); 2112 tree pointer = default_conversion (ptr);
1990 tree type = TREE_TYPE (pointer); 2113 tree type = TREE_TYPE (pointer);
1991 tree ref; 2114 tree ref;
1992 2115
2021 if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE) 2144 if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE)
2022 { 2145 {
2023 error_at (loc, "dereferencing pointer to incomplete type"); 2146 error_at (loc, "dereferencing pointer to incomplete type");
2024 return error_mark_node; 2147 return error_mark_node;
2025 } 2148 }
2026 if (VOID_TYPE_P (t) && skip_evaluation == 0) 2149 if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
2027 warning_at (loc, 0, "dereferencing %<void *%> pointer"); 2150 warning_at (loc, 0, "dereferencing %<void *%> pointer");
2028 2151
2029 /* We *must* set TREE_READONLY when dereferencing a pointer to const, 2152 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
2030 so that we get the proper error message if the result is used 2153 so that we get the proper error message if the result is used
2031 to assign to. Also, &* is supposed to be a no-op. 2154 to assign to. Also, &* is supposed to be a no-op.
2040 protected_set_expr_location (ref, loc); 2163 protected_set_expr_location (ref, loc);
2041 return ref; 2164 return ref;
2042 } 2165 }
2043 } 2166 }
2044 else if (TREE_CODE (pointer) != ERROR_MARK) 2167 else if (TREE_CODE (pointer) != ERROR_MARK)
2045 error_at (loc, 2168 switch (errstring)
2046 "invalid type argument of %qs (have %qT)", errorstring, type); 2169 {
2170 case RO_ARRAY_INDEXING:
2171 error_at (loc,
2172 "invalid type argument of array indexing (have %qT)",
2173 type);
2174 break;
2175 case RO_UNARY_STAR:
2176 error_at (loc,
2177 "invalid type argument of unary %<*%> (have %qT)",
2178 type);
2179 break;
2180 case RO_ARROW:
2181 error_at (loc,
2182 "invalid type argument of %<->%> (have %qT)",
2183 type);
2184 break;
2185 default:
2186 gcc_unreachable ();
2187 }
2047 return error_mark_node; 2188 return error_mark_node;
2048 } 2189 }
2049 2190
2050 /* This handles expressions of the form "a[i]", which denotes 2191 /* This handles expressions of the form "a[i]", which denotes
2051 an array reference. 2192 an array reference.
2057 by functions). 2198 by functions).
2058 2199
2059 LOC is the location to use for the returned expression. */ 2200 LOC is the location to use for the returned expression. */
2060 2201
2061 tree 2202 tree
2062 build_array_ref (tree array, tree index, location_t loc) 2203 build_array_ref (location_t loc, tree array, tree index)
2063 { 2204 {
2064 tree ret; 2205 tree ret;
2065 bool swapped = false; 2206 bool swapped = false;
2066 if (TREE_TYPE (array) == error_mark_node 2207 if (TREE_TYPE (array) == error_mark_node
2067 || TREE_TYPE (index) == error_mark_node) 2208 || TREE_TYPE (index) == error_mark_node)
2136 { 2277 {
2137 tree foo = array; 2278 tree foo = array;
2138 while (TREE_CODE (foo) == COMPONENT_REF) 2279 while (TREE_CODE (foo) == COMPONENT_REF)
2139 foo = TREE_OPERAND (foo, 0); 2280 foo = TREE_OPERAND (foo, 0);
2140 if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo)) 2281 if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo))
2141 pedwarn (loc, OPT_pedantic, 2282 pedwarn (loc, OPT_pedantic,
2142 "ISO C forbids subscripting %<register%> array"); 2283 "ISO C forbids subscripting %<register%> array");
2143 else if (!flag_isoc99 && !lvalue_p (foo)) 2284 else if (!flag_isoc99 && !lvalue_p (foo))
2144 pedwarn (loc, OPT_pedantic, 2285 pedwarn (loc, OPT_pedantic,
2145 "ISO C90 forbids subscripting non-lvalue array"); 2286 "ISO C90 forbids subscripting non-lvalue array");
2146 } 2287 }
2147 2288
2148 type = TREE_TYPE (TREE_TYPE (array)); 2289 type = TREE_TYPE (TREE_TYPE (array));
2149 rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE); 2290 rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
2160 /* This was added by rms on 16 Nov 91. 2301 /* This was added by rms on 16 Nov 91.
2161 It fixes vol struct foo *a; a->elts[1] 2302 It fixes vol struct foo *a; a->elts[1]
2162 in an inline function. 2303 in an inline function.
2163 Hope it doesn't break something else. */ 2304 Hope it doesn't break something else. */
2164 | TREE_THIS_VOLATILE (array)); 2305 | TREE_THIS_VOLATILE (array));
2165 ret = require_complete_type (fold (rval)); 2306 ret = require_complete_type (rval);
2166 protected_set_expr_location (ret, loc); 2307 protected_set_expr_location (ret, loc);
2167 return ret; 2308 return ret;
2168 } 2309 }
2169 else 2310 else
2170 { 2311 {
2176 gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE); 2317 gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
2177 gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE); 2318 gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
2178 2319
2179 return build_indirect_ref 2320 return build_indirect_ref
2180 (loc, build_binary_op (loc, PLUS_EXPR, ar, index, 0), 2321 (loc, build_binary_op (loc, PLUS_EXPR, ar, index, 0),
2181 "array indexing"); 2322 RO_ARRAY_INDEXING);
2182 } 2323 }
2183 } 2324 }
2184 2325
2185 /* Build an external reference to identifier ID. FUN indicates 2326 /* Build an external reference to identifier ID. FUN indicates
2186 whether this will be used for a function call. LOC is the source 2327 whether this will be used for a function call. LOC is the source
2187 location of the identifier. */ 2328 location of the identifier. This sets *TYPE to the type of the
2329 identifier, which is not the same as the type of the returned value
2330 for CONST_DECLs defined as enum constants. If the type of the
2331 identifier is not available, *TYPE is set to NULL. */
2188 tree 2332 tree
2189 build_external_ref (tree id, int fun, location_t loc) 2333 build_external_ref (location_t loc, tree id, int fun, tree *type)
2190 { 2334 {
2191 tree ref; 2335 tree ref;
2192 tree decl = lookup_name (id); 2336 tree decl = lookup_name (id);
2193 2337
2194 /* In Objective-C, an instance variable (ivar) may be preferred to 2338 /* In Objective-C, an instance variable (ivar) may be preferred to
2195 whatever lookup_name() found. */ 2339 whatever lookup_name() found. */
2196 decl = objc_lookup_ivar (decl, id); 2340 decl = objc_lookup_ivar (decl, id);
2197 2341
2342 *type = NULL;
2198 if (decl && decl != error_mark_node) 2343 if (decl && decl != error_mark_node)
2199 ref = decl; 2344 {
2345 ref = decl;
2346 *type = TREE_TYPE (ref);
2347 }
2200 else if (fun) 2348 else if (fun)
2201 /* Implicit function declaration. */ 2349 /* Implicit function declaration. */
2202 ref = implicitly_declare (id); 2350 ref = implicitly_declare (loc, id);
2203 else if (decl == error_mark_node) 2351 else if (decl == error_mark_node)
2204 /* Don't complain about something that's already been 2352 /* Don't complain about something that's already been
2205 complained about. */ 2353 complained about. */
2206 return error_mark_node; 2354 return error_mark_node;
2207 else 2355 else
2208 { 2356 {
2209 undeclared_variable (id, loc); 2357 undeclared_variable (loc, id);
2210 return error_mark_node; 2358 return error_mark_node;
2211 } 2359 }
2212 2360
2213 if (TREE_TYPE (ref) == error_mark_node) 2361 if (TREE_TYPE (ref) == error_mark_node)
2214 return error_mark_node; 2362 return error_mark_node;
2215 2363
2216 if (TREE_DEPRECATED (ref)) 2364 if (TREE_DEPRECATED (ref))
2217 warn_deprecated_use (ref); 2365 warn_deprecated_use (ref, NULL_TREE);
2218 2366
2219 /* Recursive call does not count as usage. */ 2367 /* Recursive call does not count as usage. */
2220 if (ref != current_function_decl) 2368 if (ref != current_function_decl)
2221 { 2369 {
2222 TREE_USED (ref) = 1; 2370 TREE_USED (ref) = 1;
2223 } 2371 }
2224 2372
2225 if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof) 2373 if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof)
2233 } 2381 }
2234 2382
2235 if (TREE_CODE (ref) == CONST_DECL) 2383 if (TREE_CODE (ref) == CONST_DECL)
2236 { 2384 {
2237 used_types_insert (TREE_TYPE (ref)); 2385 used_types_insert (TREE_TYPE (ref));
2386
2387 if (warn_cxx_compat
2388 && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
2389 && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
2390 {
2391 warning_at (loc, OPT_Wc___compat,
2392 ("enum constant defined in struct or union "
2393 "is not visible in C++"));
2394 inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
2395 }
2396
2238 ref = DECL_INITIAL (ref); 2397 ref = DECL_INITIAL (ref);
2239 TREE_CONSTANT (ref) = 1; 2398 TREE_CONSTANT (ref) = 1;
2240 } 2399 }
2241 else if (current_function_decl != 0 2400 else if (current_function_decl != 0
2242 && !DECL_FILE_SCOPE_P (current_function_decl) 2401 && !DECL_FILE_SCOPE_P (current_function_decl)
2257 && DECL_EXTERNAL (current_function_decl) 2416 && DECL_EXTERNAL (current_function_decl)
2258 && VAR_OR_FUNCTION_DECL_P (ref) 2417 && VAR_OR_FUNCTION_DECL_P (ref)
2259 && (TREE_CODE (ref) != VAR_DECL || TREE_STATIC (ref)) 2418 && (TREE_CODE (ref) != VAR_DECL || TREE_STATIC (ref))
2260 && ! TREE_PUBLIC (ref) 2419 && ! TREE_PUBLIC (ref)
2261 && DECL_CONTEXT (ref) != current_function_decl) 2420 && DECL_CONTEXT (ref) != current_function_decl)
2262 pedwarn (loc, 0, "%qD is static but used in inline function %qD " 2421 record_inline_static (loc, current_function_decl, ref,
2263 "which is not static", ref, current_function_decl); 2422 csi_internal);
2264 2423
2265 return ref; 2424 return ref;
2266 } 2425 }
2267 2426
2268 /* Record details of decls possibly used inside sizeof or typeof. */ 2427 /* Record details of decls possibly used inside sizeof or typeof. */
2319 } 2478 }
2320 2479
2321 /* Return the result of sizeof applied to EXPR. */ 2480 /* Return the result of sizeof applied to EXPR. */
2322 2481
2323 struct c_expr 2482 struct c_expr
2324 c_expr_sizeof_expr (struct c_expr expr) 2483 c_expr_sizeof_expr (location_t loc, struct c_expr expr)
2325 { 2484 {
2326 struct c_expr ret; 2485 struct c_expr ret;
2327 if (expr.value == error_mark_node) 2486 if (expr.value == error_mark_node)
2328 { 2487 {
2329 ret.value = error_mark_node; 2488 ret.value = error_mark_node;
2330 ret.original_code = ERROR_MARK; 2489 ret.original_code = ERROR_MARK;
2490 ret.original_type = NULL;
2331 pop_maybe_used (false); 2491 pop_maybe_used (false);
2332 } 2492 }
2333 else 2493 else
2334 { 2494 {
2335 ret.value = c_sizeof (TREE_TYPE (expr.value)); 2495 bool expr_const_operands = true;
2496 tree folded_expr = c_fully_fold (expr.value, require_constant_value,
2497 &expr_const_operands);
2498 ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
2336 ret.original_code = ERROR_MARK; 2499 ret.original_code = ERROR_MARK;
2337 if (c_vla_type_p (TREE_TYPE (expr.value))) 2500 ret.original_type = NULL;
2501 if (c_vla_type_p (TREE_TYPE (folded_expr)))
2338 { 2502 {
2339 /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */ 2503 /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */
2340 ret.value = build2 (COMPOUND_EXPR, TREE_TYPE (ret.value), expr.value, ret.value); 2504 ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
2341 } 2505 folded_expr, ret.value);
2342 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr.value))); 2506 C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
2507 SET_EXPR_LOCATION (ret.value, loc);
2508 }
2509 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
2343 } 2510 }
2344 return ret; 2511 return ret;
2345 } 2512 }
2346 2513
2347 /* Return the result of sizeof applied to T, a structure for the type 2514 /* Return the result of sizeof applied to T, a structure for the type
2348 name passed to sizeof (rather than the type itself). */ 2515 name passed to sizeof (rather than the type itself). LOC is the
2516 location of the original expression. */
2349 2517
2350 struct c_expr 2518 struct c_expr
2351 c_expr_sizeof_type (struct c_type_name *t) 2519 c_expr_sizeof_type (location_t loc, struct c_type_name *t)
2352 { 2520 {
2353 tree type; 2521 tree type;
2354 struct c_expr ret; 2522 struct c_expr ret;
2355 type = groktypename (t); 2523 tree type_expr = NULL_TREE;
2356 ret.value = c_sizeof (type); 2524 bool type_expr_const = true;
2525 type = groktypename (t, &type_expr, &type_expr_const);
2526 ret.value = c_sizeof (loc, type);
2357 ret.original_code = ERROR_MARK; 2527 ret.original_code = ERROR_MARK;
2528 ret.original_type = NULL;
2529 if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
2530 && c_vla_type_p (type))
2531 {
2532 /* If the type is a [*] array, it is a VLA but is represented as
2533 having a size of zero. In such a case we must ensure that
2534 the result of sizeof does not get folded to a constant by
2535 c_fully_fold, because if the size is evaluated the result is
2536 not constant and so constraints on zero or negative size
2537 arrays must not be applied when this sizeof call is inside
2538 another array declarator. */
2539 if (!type_expr)
2540 type_expr = integer_zero_node;
2541 ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
2542 type_expr, ret.value);
2543 C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
2544 }
2358 pop_maybe_used (type != error_mark_node 2545 pop_maybe_used (type != error_mark_node
2359 ? C_TYPE_VARIABLE_SIZE (type) : false); 2546 ? C_TYPE_VARIABLE_SIZE (type) : false);
2360 return ret; 2547 return ret;
2361 } 2548 }
2362 2549
2363 /* Build a function call to function FUNCTION with parameters PARAMS. 2550 /* Build a function call to function FUNCTION with parameters PARAMS.
2551 The function call is at LOC.
2364 PARAMS is a list--a chain of TREE_LIST nodes--in which the 2552 PARAMS is a list--a chain of TREE_LIST nodes--in which the
2365 TREE_VALUE of each node is a parameter-expression. 2553 TREE_VALUE of each node is a parameter-expression.
2366 FUNCTION's data type may be a function type or a pointer-to-function. */ 2554 FUNCTION's data type may be a function type or a pointer-to-function. */
2367 2555
2368 tree 2556 tree
2369 build_function_call (tree function, tree params) 2557 build_function_call (location_t loc, tree function, tree params)
2558 {
2559 VEC(tree,gc) *vec;
2560 tree ret;
2561
2562 vec = VEC_alloc (tree, gc, list_length (params));
2563 for (; params; params = TREE_CHAIN (params))
2564 VEC_quick_push (tree, vec, TREE_VALUE (params));
2565 ret = build_function_call_vec (loc, function, vec, NULL);
2566 VEC_free (tree, gc, vec);
2567 return ret;
2568 }
2569
2570 /* Build a function call to function FUNCTION with parameters PARAMS.
2571 ORIGTYPES, if not NULL, is a vector of types; each element is
2572 either NULL or the original type of the corresponding element in
2573 PARAMS. The original type may differ from TREE_TYPE of the
2574 parameter for enums. FUNCTION's data type may be a function type
2575 or pointer-to-function. This function changes the elements of
2576 PARAMS. */
2577
2578 tree
2579 build_function_call_vec (location_t loc, tree function, VEC(tree,gc) *params,
2580 VEC(tree,gc) *origtypes)
2370 { 2581 {
2371 tree fntype, fundecl = 0; 2582 tree fntype, fundecl = 0;
2372 tree name = NULL_TREE, result; 2583 tree name = NULL_TREE, result;
2373 tree tem; 2584 tree tem;
2374 int nargs; 2585 int nargs;
2375 tree *argarray; 2586 tree *argarray;
2376 2587
2377 2588
2378 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */ 2589 /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */
2379 STRIP_TYPE_NOPS (function); 2590 STRIP_TYPE_NOPS (function);
2380 2591
2381 /* Convert anything with function type to a pointer-to-function. */ 2592 /* Convert anything with function type to a pointer-to-function. */
2383 { 2594 {
2384 /* Implement type-directed function overloading for builtins. 2595 /* Implement type-directed function overloading for builtins.
2385 resolve_overloaded_builtin and targetm.resolve_overloaded_builtin 2596 resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
2386 handle all the type checking. The result is a complete expression 2597 handle all the type checking. The result is a complete expression
2387 that implements this function call. */ 2598 that implements this function call. */
2388 tem = resolve_overloaded_builtin (function, params); 2599 tem = resolve_overloaded_builtin (loc, function, params);
2389 if (tem) 2600 if (tem)
2390 return tem; 2601 return tem;
2391 2602
2392 name = DECL_NAME (function); 2603 name = DECL_NAME (function);
2393 fundecl = function; 2604 fundecl = function;
2394 } 2605 }
2395 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE) 2606 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
2396 function = function_to_pointer_conversion (function); 2607 function = function_to_pointer_conversion (loc, function);
2397 2608
2398 /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF 2609 /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
2399 expressions, like those used for ObjC messenger dispatches. */ 2610 expressions, like those used for ObjC messenger dispatches. */
2400 function = objc_rewrite_function_call (function, params); 2611 if (!VEC_empty (tree, params))
2612 function = objc_rewrite_function_call (function,
2613 VEC_index (tree, params, 0));
2614
2615 function = c_fully_fold (function, false, NULL);
2401 2616
2402 fntype = TREE_TYPE (function); 2617 fntype = TREE_TYPE (function);
2403 2618
2404 if (TREE_CODE (fntype) == ERROR_MARK) 2619 if (TREE_CODE (fntype) == ERROR_MARK)
2405 return error_mark_node; 2620 return error_mark_node;
2406 2621
2407 if (!(TREE_CODE (fntype) == POINTER_TYPE 2622 if (!(TREE_CODE (fntype) == POINTER_TYPE
2408 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)) 2623 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
2409 { 2624 {
2410 error ("called object %qE is not a function", function); 2625 error_at (loc, "called object %qE is not a function", function);
2411 return error_mark_node; 2626 return error_mark_node;
2412 } 2627 }
2413 2628
2414 if (fundecl && TREE_THIS_VOLATILE (fundecl)) 2629 if (fundecl && TREE_THIS_VOLATILE (fundecl))
2415 current_function_returns_abnormally = 1; 2630 current_function_returns_abnormally = 1;
2418 fntype = TREE_TYPE (fntype); 2633 fntype = TREE_TYPE (fntype);
2419 2634
2420 /* Convert the parameters to the types declared in the 2635 /* Convert the parameters to the types declared in the
2421 function prototype, or apply default promotions. */ 2636 function prototype, or apply default promotions. */
2422 2637
2423 nargs = list_length (params); 2638 nargs = convert_arguments (TYPE_ARG_TYPES (fntype), params, origtypes,
2424 argarray = (tree *) alloca (nargs * sizeof (tree)); 2639 function, fundecl);
2425 nargs = convert_arguments (nargs, argarray, TYPE_ARG_TYPES (fntype),
2426 params, function, fundecl);
2427 if (nargs < 0) 2640 if (nargs < 0)
2428 return error_mark_node; 2641 return error_mark_node;
2429 2642
2430 /* Check that the function is called through a compatible prototype. 2643 /* Check that the function is called through a compatible prototype.
2431 If it is not, replace the call by a trap, wrapped up in a compound 2644 If it is not, replace the call by a trap, wrapped up in a compound
2436 && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR 2649 && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
2437 && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL 2650 && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
2438 && !comptypes (fntype, TREE_TYPE (tem))) 2651 && !comptypes (fntype, TREE_TYPE (tem)))
2439 { 2652 {
2440 tree return_type = TREE_TYPE (fntype); 2653 tree return_type = TREE_TYPE (fntype);
2441 tree trap = build_function_call (built_in_decls[BUILT_IN_TRAP], 2654 tree trap = build_function_call (loc, built_in_decls[BUILT_IN_TRAP],
2442 NULL_TREE); 2655 NULL_TREE);
2443 int i; 2656 int i;
2444 2657
2445 /* This situation leads to run-time undefined behavior. We can't, 2658 /* This situation leads to run-time undefined behavior. We can't,
2446 therefore, simply error unless we can prove that all possible 2659 therefore, simply error unless we can prove that all possible
2447 executions of the program must execute the code. */ 2660 executions of the program must execute the code. */
2448 if (warning (0, "function called through a non-compatible type")) 2661 if (warning_at (loc, 0, "function called through a non-compatible type"))
2449 /* We can, however, treat "undefined" any way we please. 2662 /* We can, however, treat "undefined" any way we please.
2450 Call abort to encourage the user to fix the program. */ 2663 Call abort to encourage the user to fix the program. */
2451 inform (input_location, "if this code is reached, the program will abort"); 2664 inform (loc, "if this code is reached, the program will abort");
2452 /* Before the abort, allow the function arguments to exit or 2665 /* Before the abort, allow the function arguments to exit or
2453 call longjmp. */ 2666 call longjmp. */
2454 for (i = 0; i < nargs; i++) 2667 for (i = 0; i < nargs; i++)
2455 trap = build2 (COMPOUND_EXPR, void_type_node, argarray[i], trap); 2668 trap = build2 (COMPOUND_EXPR, void_type_node,
2669 VEC_index (tree, params, i), trap);
2456 2670
2457 if (VOID_TYPE_P (return_type)) 2671 if (VOID_TYPE_P (return_type))
2458 return trap; 2672 {
2673 if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
2674 pedwarn (loc, 0,
2675 "function with qualified void return type called");
2676 return trap;
2677 }
2459 else 2678 else
2460 { 2679 {
2461 tree rhs; 2680 tree rhs;
2462 2681
2463 if (AGGREGATE_TYPE_P (return_type)) 2682 if (AGGREGATE_TYPE_P (return_type))
2464 rhs = build_compound_literal (return_type, 2683 rhs = build_compound_literal (loc, return_type,
2465 build_constructor (return_type, 0)); 2684 build_constructor (return_type, 0),
2685 false);
2466 else 2686 else
2467 rhs = fold_convert (return_type, integer_zero_node); 2687 rhs = fold_convert_loc (loc, return_type, integer_zero_node);
2468 2688
2469 return build2 (COMPOUND_EXPR, return_type, trap, rhs); 2689 return require_complete_type (build2 (COMPOUND_EXPR, return_type,
2470 } 2690 trap, rhs));
2471 } 2691 }
2692 }
2693
2694 argarray = VEC_address (tree, params);
2472 2695
2473 /* Check that arguments to builtin functions match the expectations. */ 2696 /* Check that arguments to builtin functions match the expectations. */
2474 if (fundecl 2697 if (fundecl
2475 && DECL_BUILT_IN (fundecl) 2698 && DECL_BUILT_IN (fundecl)
2476 && DECL_BUILT_IN_CLASS (fundecl) == BUILT_IN_NORMAL 2699 && DECL_BUILT_IN_CLASS (fundecl) == BUILT_IN_NORMAL
2479 2702
2480 /* Check that the arguments to the function are valid. */ 2703 /* Check that the arguments to the function are valid. */
2481 check_function_arguments (TYPE_ATTRIBUTES (fntype), nargs, argarray, 2704 check_function_arguments (TYPE_ATTRIBUTES (fntype), nargs, argarray,
2482 TYPE_ARG_TYPES (fntype)); 2705 TYPE_ARG_TYPES (fntype));
2483 2706
2484 if (require_constant_value) 2707 if (name != NULL_TREE
2485 { 2708 && !strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10))
2486 result = fold_build_call_array_initializer (TREE_TYPE (fntype), 2709 {
2487 function, nargs, argarray); 2710 if (require_constant_value)
2488 if (TREE_CONSTANT (result) 2711 result =
2489 && (name == NULL_TREE 2712 fold_build_call_array_initializer_loc (loc, TREE_TYPE (fntype),
2490 || strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10) != 0)) 2713 function, nargs, argarray);
2491 pedwarn_init (input_location, 0, "initializer element is not constant"); 2714 else
2715 result = fold_build_call_array_loc (loc, TREE_TYPE (fntype),
2716 function, nargs, argarray);
2717 if (TREE_CODE (result) == NOP_EXPR
2718 && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
2719 STRIP_TYPE_NOPS (result);
2492 } 2720 }
2493 else 2721 else
2494 result = fold_build_call_array (TREE_TYPE (fntype), 2722 result = build_call_array_loc (loc, TREE_TYPE (fntype),
2495 function, nargs, argarray); 2723 function, nargs, argarray);
2496 2724
2497 if (VOID_TYPE_P (TREE_TYPE (result))) 2725 if (VOID_TYPE_P (TREE_TYPE (result)))
2498 return result; 2726 {
2727 if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
2728 pedwarn (loc, 0,
2729 "function with qualified void return type called");
2730 return result;
2731 }
2499 return require_complete_type (result); 2732 return require_complete_type (result);
2500 } 2733 }
2501 2734
2502 /* Convert the argument expressions in the list VALUES 2735 /* Convert the argument expressions in the vector VALUES
2503 to the types in the list TYPELIST. The resulting arguments are 2736 to the types in the list TYPELIST.
2504 stored in the array ARGARRAY which has size NARGS.
2505 2737
2506 If TYPELIST is exhausted, or when an element has NULL as its type, 2738 If TYPELIST is exhausted, or when an element has NULL as its type,
2507 perform the default conversions. 2739 perform the default conversions.
2508 2740
2509 PARMLIST is the chain of parm decls for the function being called. 2741 ORIGTYPES is the original types of the expressions in VALUES. This
2510 It may be 0, if that info is not available. 2742 holds the type of enum values which have been converted to integral
2511 It is used only for generating error messages. 2743 types. It may be NULL.
2512 2744
2513 FUNCTION is a tree for the called function. It is used only for 2745 FUNCTION is a tree for the called function. It is used only for
2514 error messages, where it is formatted with %qE. 2746 error messages, where it is formatted with %qE.
2515 2747
2516 This is also where warnings about wrong number of args are generated. 2748 This is also where warnings about wrong number of args are generated.
2517 2749
2518 VALUES is a chain of TREE_LIST nodes with the elements of the list
2519 in the TREE_VALUE slots of those nodes.
2520
2521 Returns the actual number of arguments processed (which may be less 2750 Returns the actual number of arguments processed (which may be less
2522 than NARGS in some error situations), or -1 on failure. */ 2751 than the length of VALUES in some error situations), or -1 on
2752 failure. */
2523 2753
2524 static int 2754 static int
2525 convert_arguments (int nargs, tree *argarray, 2755 convert_arguments (tree typelist, VEC(tree,gc) *values,
2526 tree typelist, tree values, tree function, tree fundecl) 2756 VEC(tree,gc) *origtypes, tree function, tree fundecl)
2527 { 2757 {
2528 tree typetail, valtail; 2758 tree typetail, val;
2529 int parmnum; 2759 unsigned int parmnum;
2530 bool error_args = false; 2760 bool error_args = false;
2531 const bool type_generic = fundecl 2761 const bool type_generic = fundecl
2532 && lookup_attribute ("type generic", TYPE_ATTRIBUTES(TREE_TYPE (fundecl))); 2762 && lookup_attribute ("type generic", TYPE_ATTRIBUTES(TREE_TYPE (fundecl)));
2763 bool type_generic_remove_excess_precision = false;
2533 tree selector; 2764 tree selector;
2534 2765
2535 /* Change pointer to function to the function itself for 2766 /* Change pointer to function to the function itself for
2536 diagnostics. */ 2767 diagnostics. */
2537 if (TREE_CODE (function) == ADDR_EXPR 2768 if (TREE_CODE (function) == ADDR_EXPR
2539 function = TREE_OPERAND (function, 0); 2770 function = TREE_OPERAND (function, 0);
2540 2771
2541 /* Handle an ObjC selector specially for diagnostics. */ 2772 /* Handle an ObjC selector specially for diagnostics. */
2542 selector = objc_message_selector (); 2773 selector = objc_message_selector ();
2543 2774
2775 /* For type-generic built-in functions, determine whether excess
2776 precision should be removed (classification) or not
2777 (comparison). */
2778 if (type_generic
2779 && DECL_BUILT_IN (fundecl)
2780 && DECL_BUILT_IN_CLASS (fundecl) == BUILT_IN_NORMAL)
2781 {
2782 switch (DECL_FUNCTION_CODE (fundecl))
2783 {
2784 case BUILT_IN_ISFINITE:
2785 case BUILT_IN_ISINF:
2786 case BUILT_IN_ISINF_SIGN:
2787 case BUILT_IN_ISNAN:
2788 case BUILT_IN_ISNORMAL:
2789 case BUILT_IN_FPCLASSIFY:
2790 type_generic_remove_excess_precision = true;
2791 break;
2792
2793 default:
2794 type_generic_remove_excess_precision = false;
2795 break;
2796 }
2797 }
2798
2544 /* Scan the given expressions and types, producing individual 2799 /* Scan the given expressions and types, producing individual
2545 converted arguments and storing them in ARGARRAY. */ 2800 converted arguments. */
2546 2801
2547 for (valtail = values, typetail = typelist, parmnum = 0; 2802 for (typetail = typelist, parmnum = 0;
2548 valtail; 2803 VEC_iterate (tree, values, parmnum, val);
2549 valtail = TREE_CHAIN (valtail), parmnum++) 2804 ++parmnum)
2550 { 2805 {
2551 tree type = typetail ? TREE_VALUE (typetail) : 0; 2806 tree type = typetail ? TREE_VALUE (typetail) : 0;
2552 tree val = TREE_VALUE (valtail); 2807 tree valtype = TREE_TYPE (val);
2553 tree rname = function; 2808 tree rname = function;
2554 int argnum = parmnum + 1; 2809 int argnum = parmnum + 1;
2555 const char *invalid_func_diag; 2810 const char *invalid_func_diag;
2811 bool excess_precision = false;
2812 bool npc;
2813 tree parmval;
2556 2814
2557 if (type == void_type_node) 2815 if (type == void_type_node)
2558 { 2816 {
2559 error ("too many arguments to function %qE", function); 2817 error ("too many arguments to function %qE", function);
2560 return parmnum; 2818 return parmnum;
2564 { 2822 {
2565 rname = selector; 2823 rname = selector;
2566 argnum -= 2; 2824 argnum -= 2;
2567 } 2825 }
2568 2826
2827 npc = null_pointer_constant_p (val);
2828
2829 /* If there is excess precision and a prototype, convert once to
2830 the required type rather than converting via the semantic
2831 type. Likewise without a prototype a float value represented
2832 as long double should be converted once to double. But for
2833 type-generic classification functions excess precision must
2834 be removed here. */
2835 if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
2836 && (type || !type_generic || !type_generic_remove_excess_precision))
2837 {
2838 val = TREE_OPERAND (val, 0);
2839 excess_precision = true;
2840 }
2841 val = c_fully_fold (val, false, NULL);
2569 STRIP_TYPE_NOPS (val); 2842 STRIP_TYPE_NOPS (val);
2570 2843
2571 val = require_complete_type (val); 2844 val = require_complete_type (val);
2572 2845
2573 if (type != 0) 2846 if (type != 0)
2574 { 2847 {
2575 /* Formal parm type is specified by a function prototype. */ 2848 /* Formal parm type is specified by a function prototype. */
2576 tree parmval;
2577 2849
2578 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) 2850 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
2579 { 2851 {
2580 error ("type of formal parameter %d is incomplete", parmnum + 1); 2852 error ("type of formal parameter %d is incomplete", parmnum + 1);
2581 parmval = val; 2853 parmval = val;
2582 } 2854 }
2583 else 2855 else
2584 { 2856 {
2857 tree origtype;
2858
2585 /* Optionally warn about conversions that 2859 /* Optionally warn about conversions that
2586 differ from the default conversions. */ 2860 differ from the default conversions. */
2587 if (warn_traditional_conversion || warn_traditional) 2861 if (warn_traditional_conversion || warn_traditional)
2588 { 2862 {
2589 unsigned int formal_prec = TYPE_PRECISION (type); 2863 unsigned int formal_prec = TYPE_PRECISION (type);
2590 2864
2591 if (INTEGRAL_TYPE_P (type) 2865 if (INTEGRAL_TYPE_P (type)
2592 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE) 2866 && TREE_CODE (valtype) == REAL_TYPE)
2593 warning (0, "passing argument %d of %qE as integer " 2867 warning (0, "passing argument %d of %qE as integer "
2594 "rather than floating due to prototype", 2868 "rather than floating due to prototype",
2595 argnum, rname); 2869 argnum, rname);
2596 if (INTEGRAL_TYPE_P (type) 2870 if (INTEGRAL_TYPE_P (type)
2597 && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE) 2871 && TREE_CODE (valtype) == COMPLEX_TYPE)
2598 warning (0, "passing argument %d of %qE as integer " 2872 warning (0, "passing argument %d of %qE as integer "
2599 "rather than complex due to prototype", 2873 "rather than complex due to prototype",
2600 argnum, rname); 2874 argnum, rname);
2601 else if (TREE_CODE (type) == COMPLEX_TYPE 2875 else if (TREE_CODE (type) == COMPLEX_TYPE
2602 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE) 2876 && TREE_CODE (valtype) == REAL_TYPE)
2603 warning (0, "passing argument %d of %qE as complex " 2877 warning (0, "passing argument %d of %qE as complex "
2604 "rather than floating due to prototype", 2878 "rather than floating due to prototype",
2605 argnum, rname); 2879 argnum, rname);
2606 else if (TREE_CODE (type) == REAL_TYPE 2880 else if (TREE_CODE (type) == REAL_TYPE
2607 && INTEGRAL_TYPE_P (TREE_TYPE (val))) 2881 && INTEGRAL_TYPE_P (valtype))
2608 warning (0, "passing argument %d of %qE as floating " 2882 warning (0, "passing argument %d of %qE as floating "
2609 "rather than integer due to prototype", 2883 "rather than integer due to prototype",
2610 argnum, rname); 2884 argnum, rname);
2611 else if (TREE_CODE (type) == COMPLEX_TYPE 2885 else if (TREE_CODE (type) == COMPLEX_TYPE
2612 && INTEGRAL_TYPE_P (TREE_TYPE (val))) 2886 && INTEGRAL_TYPE_P (valtype))
2613 warning (0, "passing argument %d of %qE as complex " 2887 warning (0, "passing argument %d of %qE as complex "
2614 "rather than integer due to prototype", 2888 "rather than integer due to prototype",
2615 argnum, rname); 2889 argnum, rname);
2616 else if (TREE_CODE (type) == REAL_TYPE 2890 else if (TREE_CODE (type) == REAL_TYPE
2617 && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE) 2891 && TREE_CODE (valtype) == COMPLEX_TYPE)
2618 warning (0, "passing argument %d of %qE as floating " 2892 warning (0, "passing argument %d of %qE as floating "
2619 "rather than complex due to prototype", 2893 "rather than complex due to prototype",
2620 argnum, rname); 2894 argnum, rname);
2621 /* ??? At some point, messages should be written about 2895 /* ??? At some point, messages should be written about
2622 conversions between complex types, but that's too messy 2896 conversions between complex types, but that's too messy
2623 to do now. */ 2897 to do now. */
2624 else if (TREE_CODE (type) == REAL_TYPE 2898 else if (TREE_CODE (type) == REAL_TYPE
2625 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE) 2899 && TREE_CODE (valtype) == REAL_TYPE)
2626 { 2900 {
2627 /* Warn if any argument is passed as `float', 2901 /* Warn if any argument is passed as `float',
2628 since without a prototype it would be `double'. */ 2902 since without a prototype it would be `double'. */
2629 if (formal_prec == TYPE_PRECISION (float_type_node) 2903 if (formal_prec == TYPE_PRECISION (float_type_node)
2630 && type != dfloat32_type_node) 2904 && type != dfloat32_type_node)
2634 2908
2635 /* Warn if mismatch between argument and prototype 2909 /* Warn if mismatch between argument and prototype
2636 for decimal float types. Warn of conversions with 2910 for decimal float types. Warn of conversions with
2637 binary float types and of precision narrowing due to 2911 binary float types and of precision narrowing due to
2638 prototype. */ 2912 prototype. */
2639 else if (type != TREE_TYPE (val) 2913 else if (type != valtype
2640 && (type == dfloat32_type_node 2914 && (type == dfloat32_type_node
2641 || type == dfloat64_type_node 2915 || type == dfloat64_type_node
2642 || type == dfloat128_type_node 2916 || type == dfloat128_type_node
2643 || TREE_TYPE (val) == dfloat32_type_node 2917 || valtype == dfloat32_type_node
2644 || TREE_TYPE (val) == dfloat64_type_node 2918 || valtype == dfloat64_type_node
2645 || TREE_TYPE (val) == dfloat128_type_node) 2919 || valtype == dfloat128_type_node)
2646 && (formal_prec 2920 && (formal_prec
2647 <= TYPE_PRECISION (TREE_TYPE (val)) 2921 <= TYPE_PRECISION (valtype)
2648 || (type == dfloat128_type_node 2922 || (type == dfloat128_type_node
2649 && (TREE_TYPE (val) 2923 && (valtype
2650 != dfloat64_type_node 2924 != dfloat64_type_node
2651 && (TREE_TYPE (val) 2925 && (valtype
2652 != dfloat32_type_node))) 2926 != dfloat32_type_node)))
2653 || (type == dfloat64_type_node 2927 || (type == dfloat64_type_node
2654 && (TREE_TYPE (val) 2928 && (valtype
2655 != dfloat32_type_node)))) 2929 != dfloat32_type_node))))
2656 warning (0, "passing argument %d of %qE as %qT " 2930 warning (0, "passing argument %d of %qE as %qT "
2657 "rather than %qT due to prototype", 2931 "rather than %qT due to prototype",
2658 argnum, rname, type, TREE_TYPE (val)); 2932 argnum, rname, type, valtype);
2659 2933
2660 } 2934 }
2661 /* Detect integer changing in width or signedness. 2935 /* Detect integer changing in width or signedness.
2662 These warnings are only activated with 2936 These warnings are only activated with
2663 -Wtraditional-conversion, not with -Wtraditional. */ 2937 -Wtraditional-conversion, not with -Wtraditional. */
2664 else if (warn_traditional_conversion && INTEGRAL_TYPE_P (type) 2938 else if (warn_traditional_conversion && INTEGRAL_TYPE_P (type)
2665 && INTEGRAL_TYPE_P (TREE_TYPE (val))) 2939 && INTEGRAL_TYPE_P (valtype))
2666 { 2940 {
2667 tree would_have_been = default_conversion (val); 2941 tree would_have_been = default_conversion (val);
2668 tree type1 = TREE_TYPE (would_have_been); 2942 tree type1 = TREE_TYPE (would_have_been);
2669 2943
2670 if (TREE_CODE (type) == ENUMERAL_TYPE 2944 if (TREE_CODE (type) == ENUMERAL_TYPE
2671 && (TYPE_MAIN_VARIANT (type) 2945 && (TYPE_MAIN_VARIANT (type)
2672 == TYPE_MAIN_VARIANT (TREE_TYPE (val)))) 2946 == TYPE_MAIN_VARIANT (valtype)))
2673 /* No warning if function asks for enum 2947 /* No warning if function asks for enum
2674 and the actual arg is that enum type. */ 2948 and the actual arg is that enum type. */
2675 ; 2949 ;
2676 else if (formal_prec != TYPE_PRECISION (type1)) 2950 else if (formal_prec != TYPE_PRECISION (type1))
2677 warning (OPT_Wtraditional_conversion, "passing argument %d of %qE " 2951 warning (OPT_Wtraditional_conversion,
2952 "passing argument %d of %qE "
2678 "with different width due to prototype", 2953 "with different width due to prototype",
2679 argnum, rname); 2954 argnum, rname);
2680 else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1)) 2955 else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
2681 ; 2956 ;
2682 /* Don't complain if the formal parameter type 2957 /* Don't complain if the formal parameter type
2691 ; 2966 ;
2692 /* If the value is extended from a narrower 2967 /* If the value is extended from a narrower
2693 unsigned type, it doesn't matter whether we 2968 unsigned type, it doesn't matter whether we
2694 pass it as signed or unsigned; the value 2969 pass it as signed or unsigned; the value
2695 certainly is the same either way. */ 2970 certainly is the same either way. */
2696 else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type) 2971 else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
2697 && TYPE_UNSIGNED (TREE_TYPE (val))) 2972 && TYPE_UNSIGNED (valtype))
2698 ; 2973 ;
2699 else if (TYPE_UNSIGNED (type)) 2974 else if (TYPE_UNSIGNED (type))
2700 warning (OPT_Wtraditional_conversion, "passing argument %d of %qE " 2975 warning (OPT_Wtraditional_conversion,
2976 "passing argument %d of %qE "
2701 "as unsigned due to prototype", 2977 "as unsigned due to prototype",
2702 argnum, rname); 2978 argnum, rname);
2703 else 2979 else
2704 warning (OPT_Wtraditional_conversion, "passing argument %d of %qE " 2980 warning (OPT_Wtraditional_conversion,
2981 "passing argument %d of %qE "
2705 "as signed due to prototype", argnum, rname); 2982 "as signed due to prototype", argnum, rname);
2706 } 2983 }
2707 } 2984 }
2708 2985
2709 parmval = convert_for_assignment (type, val, ic_argpass, 2986 /* Possibly restore an EXCESS_PRECISION_EXPR for the
2987 sake of better warnings from convert_and_check. */
2988 if (excess_precision)
2989 val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
2990 origtype = (origtypes == NULL
2991 ? NULL_TREE
2992 : VEC_index (tree, origtypes, parmnum));
2993 parmval = convert_for_assignment (input_location, type, val,
2994 origtype, ic_argpass, npc,
2710 fundecl, function, 2995 fundecl, function,
2711 parmnum + 1); 2996 parmnum + 1);
2712 2997
2713 if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0) 2998 if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0)
2714 && INTEGRAL_TYPE_P (type) 2999 && INTEGRAL_TYPE_P (type)
2715 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) 3000 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
2716 parmval = default_conversion (parmval); 3001 parmval = default_conversion (parmval);
2717 } 3002 }
2718 argarray[parmnum] = parmval; 3003 }
2719 } 3004 else if (TREE_CODE (valtype) == REAL_TYPE
2720 else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE 3005 && (TYPE_PRECISION (valtype)
2721 && (TYPE_PRECISION (TREE_TYPE (val))
2722 < TYPE_PRECISION (double_type_node)) 3006 < TYPE_PRECISION (double_type_node))
2723 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (val)))) 3007 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
2724 { 3008 {
2725 if (type_generic) 3009 if (type_generic)
2726 argarray[parmnum] = val; 3010 parmval = val;
2727 else 3011 else
2728 /* Convert `float' to `double'. */ 3012 /* Convert `float' to `double'. */
2729 argarray[parmnum] = convert (double_type_node, val); 3013 parmval = convert (double_type_node, val);
2730 } 3014 }
3015 else if (excess_precision && !type_generic)
3016 /* A "double" argument with excess precision being passed
3017 without a prototype or in variable arguments. */
3018 parmval = convert (valtype, val);
2731 else if ((invalid_func_diag = 3019 else if ((invalid_func_diag =
2732 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val))) 3020 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
2733 { 3021 {
2734 error (invalid_func_diag); 3022 error (invalid_func_diag);
2735 return -1; 3023 return -1;
2736 } 3024 }
2737 else 3025 else
2738 /* Convert `short' and `char' to full-size `int'. */ 3026 /* Convert `short' and `char' to full-size `int'. */
2739 argarray[parmnum] = default_conversion (val); 3027 parmval = default_conversion (val);
2740 3028
2741 if (argarray[parmnum] == error_mark_node) 3029 VEC_replace (tree, values, parmnum, parmval);
3030 if (parmval == error_mark_node)
2742 error_args = true; 3031 error_args = true;
2743 3032
2744 if (typetail) 3033 if (typetail)
2745 typetail = TREE_CHAIN (typetail); 3034 typetail = TREE_CHAIN (typetail);
2746 } 3035 }
2747 3036
2748 gcc_assert (parmnum == nargs); 3037 gcc_assert (parmnum == VEC_length (tree, values));
2749 3038
2750 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node) 3039 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
2751 { 3040 {
2752 error ("too few arguments to function %qE", function); 3041 error ("too few arguments to function %qE", function);
2753 return -1; 3042 return -1;
2754 } 3043 }
2755 3044
2756 return error_args ? -1 : parmnum; 3045 return error_args ? -1 : (int) parmnum;
2757 } 3046 }
2758 3047
2759 /* This is the entry point used by the parser to build unary operators 3048 /* This is the entry point used by the parser to build unary operators
2760 in the input. CODE, a tree_code, specifies the unary operator, and 3049 in the input. CODE, a tree_code, specifies the unary operator, and
2761 ARG is the operand. For unary plus, the C parser currently uses 3050 ARG is the operand. For unary plus, the C parser currently uses
2763 3052
2764 LOC is the location to use for the tree generated. 3053 LOC is the location to use for the tree generated.
2765 */ 3054 */
2766 3055
2767 struct c_expr 3056 struct c_expr
2768 parser_build_unary_op (enum tree_code code, struct c_expr arg, location_t loc) 3057 parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
2769 { 3058 {
2770 struct c_expr result; 3059 struct c_expr result;
2771 3060
2772 result.value = build_unary_op (loc, code, arg.value, 0); 3061 result.value = build_unary_op (loc, code, arg.value, 0);
2773 result.original_code = code; 3062 result.original_code = code;
2774 3063 result.original_type = NULL;
3064
2775 if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value)) 3065 if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
2776 overflow_warning (result.value); 3066 overflow_warning (loc, result.value);
2777 3067
2778 return result; 3068 return result;
2779 } 3069 }
2780 3070
2781 /* This is the entry point used by the parser to build binary operators 3071 /* This is the entry point used by the parser to build binary operators
2792 { 3082 {
2793 struct c_expr result; 3083 struct c_expr result;
2794 3084
2795 enum tree_code code1 = arg1.original_code; 3085 enum tree_code code1 = arg1.original_code;
2796 enum tree_code code2 = arg2.original_code; 3086 enum tree_code code2 = arg2.original_code;
3087 tree type1 = (arg1.original_type
3088 ? arg1.original_type
3089 : TREE_TYPE (arg1.value));
3090 tree type2 = (arg2.original_type
3091 ? arg2.original_type
3092 : TREE_TYPE (arg2.value));
2797 3093
2798 result.value = build_binary_op (location, code, 3094 result.value = build_binary_op (location, code,
2799 arg1.value, arg2.value, 1); 3095 arg1.value, arg2.value, 1);
2800 result.original_code = code; 3096 result.original_code = code;
3097 result.original_type = NULL;
2801 3098
2802 if (TREE_CODE (result.value) == ERROR_MARK) 3099 if (TREE_CODE (result.value) == ERROR_MARK)
2803 return result; 3100 return result;
2804 3101
2805 if (location != UNKNOWN_LOCATION) 3102 if (location != UNKNOWN_LOCATION)
2808 /* Check for cases such as x+y<<z which users are likely 3105 /* Check for cases such as x+y<<z which users are likely
2809 to misinterpret. */ 3106 to misinterpret. */
2810 if (warn_parentheses) 3107 if (warn_parentheses)
2811 warn_about_parentheses (code, code1, arg1.value, code2, arg2.value); 3108 warn_about_parentheses (code, code1, arg1.value, code2, arg2.value);
2812 3109
2813 if (TREE_CODE_CLASS (code1) != tcc_comparison) 3110 if (warn_logical_op)
2814 warn_logical_operator (code, arg1.value, arg2.value); 3111 warn_logical_operator (input_location, code, TREE_TYPE (result.value),
3112 code1, arg1.value, code2, arg2.value);
2815 3113
2816 /* Warn about comparisons against string literals, with the exception 3114 /* Warn about comparisons against string literals, with the exception
2817 of testing for equality or inequality of a string literal with NULL. */ 3115 of testing for equality or inequality of a string literal with NULL. */
2818 if (code == EQ_EXPR || code == NE_EXPR) 3116 if (code == EQ_EXPR || code == NE_EXPR)
2819 { 3117 {
2820 if ((code1 == STRING_CST && !integer_zerop (arg2.value)) 3118 if ((code1 == STRING_CST && !integer_zerop (arg2.value))
2821 || (code2 == STRING_CST && !integer_zerop (arg1.value))) 3119 || (code2 == STRING_CST && !integer_zerop (arg1.value)))
2822 warning (OPT_Waddress, "comparison with string literal results in unspecified behavior"); 3120 warning_at (location, OPT_Waddress,
3121 "comparison with string literal results in unspecified behavior");
2823 } 3122 }
2824 else if (TREE_CODE_CLASS (code) == tcc_comparison 3123 else if (TREE_CODE_CLASS (code) == tcc_comparison
2825 && (code1 == STRING_CST || code2 == STRING_CST)) 3124 && (code1 == STRING_CST || code2 == STRING_CST))
2826 warning (OPT_Waddress, "comparison with string literal results in unspecified behavior"); 3125 warning_at (location, OPT_Waddress,
2827 3126 "comparison with string literal results in unspecified behavior");
2828 if (TREE_OVERFLOW_P (result.value) 3127
2829 && !TREE_OVERFLOW_P (arg1.value) 3128 if (TREE_OVERFLOW_P (result.value)
3129 && !TREE_OVERFLOW_P (arg1.value)
2830 && !TREE_OVERFLOW_P (arg2.value)) 3130 && !TREE_OVERFLOW_P (arg2.value))
2831 overflow_warning (result.value); 3131 overflow_warning (location, result.value);
3132
3133 /* Warn about comparisons of different enum types. */
3134 if (warn_enum_compare
3135 && TREE_CODE_CLASS (code) == tcc_comparison
3136 && TREE_CODE (type1) == ENUMERAL_TYPE
3137 && TREE_CODE (type2) == ENUMERAL_TYPE
3138 && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
3139 warning_at (location, OPT_Wenum_compare,
3140 "comparison between %qT and %qT",
3141 type1, type2);
2832 3142
2833 return result; 3143 return result;
2834 } 3144 }
2835 3145
2836 /* Return a tree for the difference of pointers OP0 and OP1. 3146 /* Return a tree for the difference of pointers OP0 and OP1.
2837 The resulting tree has type int. */ 3147 The resulting tree has type int. */
2838 3148
2839 static tree 3149 static tree
2840 pointer_diff (tree op0, tree op1) 3150 pointer_diff (location_t loc, tree op0, tree op1)
2841 { 3151 {
2842 tree restype = ptrdiff_type_node; 3152 tree restype = ptrdiff_type_node;
2843 3153 tree result, inttype;
3154
3155 addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
3156 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
2844 tree target_type = TREE_TYPE (TREE_TYPE (op0)); 3157 tree target_type = TREE_TYPE (TREE_TYPE (op0));
2845 tree con0, con1, lit0, lit1; 3158 tree con0, con1, lit0, lit1;
2846 tree orig_op1 = op1; 3159 tree orig_op1 = op1;
2847 3160
3161 /* If the operands point into different address spaces, we need to
3162 explicitly convert them to pointers into the common address space
3163 before we can subtract the numerical address values. */
3164 if (as0 != as1)
3165 {
3166 addr_space_t as_common;
3167 tree common_type;
3168
3169 /* Determine the common superset address space. This is guaranteed
3170 to exist because the caller verified that comp_target_types
3171 returned non-zero. */
3172 if (!addr_space_superset (as0, as1, &as_common))
3173 gcc_unreachable ();
3174
3175 common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1));
3176 op0 = convert (common_type, op0);
3177 op1 = convert (common_type, op1);
3178 }
3179
3180 /* Determine integer type to perform computations in. This will usually
3181 be the same as the result type (ptrdiff_t), but may need to be a wider
3182 type if pointers for the address space are wider than ptrdiff_t. */
3183 if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
3184 inttype = lang_hooks.types.type_for_size
3185 (TYPE_PRECISION (TREE_TYPE (op0)), 0);
3186 else
3187 inttype = restype;
3188
3189
2848 if (TREE_CODE (target_type) == VOID_TYPE) 3190 if (TREE_CODE (target_type) == VOID_TYPE)
2849 pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 3191 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
2850 "pointer of type %<void *%> used in subtraction"); 3192 "pointer of type %<void *%> used in subtraction");
2851 if (TREE_CODE (target_type) == FUNCTION_TYPE) 3193 if (TREE_CODE (target_type) == FUNCTION_TYPE)
2852 pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 3194 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
2853 "pointer to a function used in subtraction"); 3195 "pointer to a function used in subtraction");
2854 3196
2855 /* If the conversion to ptrdiff_type does anything like widening or 3197 /* If the conversion to ptrdiff_type does anything like widening or
2856 converting a partial to an integral mode, we get a convert_expression 3198 converting a partial to an integral mode, we get a convert_expression
2857 that is in the way to do any simplifications. 3199 that is in the way to do any simplifications.
2899 /* First do the subtraction as integers; 3241 /* First do the subtraction as integers;
2900 then drop through to build the divide operator. 3242 then drop through to build the divide operator.
2901 Do not do default conversions on the minus operator 3243 Do not do default conversions on the minus operator
2902 in case restype is a short type. */ 3244 in case restype is a short type. */
2903 3245
2904 op0 = build_binary_op (input_location, 3246 op0 = build_binary_op (loc,
2905 MINUS_EXPR, convert (restype, op0), 3247 MINUS_EXPR, convert (inttype, op0),
2906 convert (restype, op1), 0); 3248 convert (inttype, op1), 0);
2907 /* This generates an error if op1 is pointer to incomplete type. */ 3249 /* This generates an error if op1 is pointer to incomplete type. */
2908 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1)))) 3250 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
2909 error ("arithmetic on pointer to an incomplete type"); 3251 error_at (loc, "arithmetic on pointer to an incomplete type");
2910 3252
2911 /* This generates an error if op0 is pointer to incomplete type. */ 3253 /* This generates an error if op0 is pointer to incomplete type. */
2912 op1 = c_size_in_bytes (target_type); 3254 op1 = c_size_in_bytes (target_type);
2913 3255
2914 /* Divide by the size, in easiest possible way. */ 3256 /* Divide by the size, in easiest possible way. */
2915 return fold_build2 (EXACT_DIV_EXPR, restype, op0, convert (restype, op1)); 3257 result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
3258 op0, convert (inttype, op1));
3259
3260 /* Convert to final result type if necessary. */
3261 return convert (restype, result);
2916 } 3262 }
2917 3263
2918 /* Construct and perhaps optimize a tree representation 3264 /* Construct and perhaps optimize a tree representation
2919 for a unary operation. CODE, a tree_code, specifies the operation 3265 for a unary operation. CODE, a tree_code, specifies the operation
2920 and XARG is the operand. 3266 and XARG is the operand.
2934 tree arg = xarg; 3280 tree arg = xarg;
2935 tree argtype = 0; 3281 tree argtype = 0;
2936 enum tree_code typecode; 3282 enum tree_code typecode;
2937 tree val; 3283 tree val;
2938 tree ret = error_mark_node; 3284 tree ret = error_mark_node;
3285 tree eptype = NULL_TREE;
2939 int noconvert = flag; 3286 int noconvert = flag;
2940 const char *invalid_op_diag; 3287 const char *invalid_op_diag;
3288 bool int_operands;
3289
3290 int_operands = EXPR_INT_CONST_OPERANDS (xarg);
3291 if (int_operands)
3292 arg = remove_c_maybe_const_expr (arg);
2941 3293
2942 if (code != ADDR_EXPR) 3294 if (code != ADDR_EXPR)
2943 arg = require_complete_type (arg); 3295 arg = require_complete_type (arg);
2944 3296
2945 typecode = TREE_CODE (TREE_TYPE (arg)); 3297 typecode = TREE_CODE (TREE_TYPE (arg));
2951 if ((invalid_op_diag 3303 if ((invalid_op_diag
2952 = targetm.invalid_unary_op (code, TREE_TYPE (xarg)))) 3304 = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
2953 { 3305 {
2954 error_at (location, invalid_op_diag); 3306 error_at (location, invalid_op_diag);
2955 return error_mark_node; 3307 return error_mark_node;
3308 }
3309
3310 if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
3311 {
3312 eptype = TREE_TYPE (arg);
3313 arg = TREE_OPERAND (arg, 0);
2956 } 3314 }
2957 3315
2958 switch (code) 3316 switch (code)
2959 { 3317 {
2960 case CONVERT_EXPR: 3318 case CONVERT_EXPR:
2968 error_at (location, "wrong type argument to unary plus"); 3326 error_at (location, "wrong type argument to unary plus");
2969 return error_mark_node; 3327 return error_mark_node;
2970 } 3328 }
2971 else if (!noconvert) 3329 else if (!noconvert)
2972 arg = default_conversion (arg); 3330 arg = default_conversion (arg);
2973 arg = non_lvalue (arg); 3331 arg = non_lvalue_loc (location, arg);
2974 break; 3332 break;
2975 3333
2976 case NEGATE_EXPR: 3334 case NEGATE_EXPR:
2977 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE 3335 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2978 || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE 3336 || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
2995 arg = default_conversion (arg); 3353 arg = default_conversion (arg);
2996 } 3354 }
2997 else if (typecode == COMPLEX_TYPE) 3355 else if (typecode == COMPLEX_TYPE)
2998 { 3356 {
2999 code = CONJ_EXPR; 3357 code = CONJ_EXPR;
3000 pedwarn (location, OPT_pedantic, 3358 pedwarn (location, OPT_pedantic,
3001 "ISO C does not support %<~%> for complex conjugation"); 3359 "ISO C does not support %<~%> for complex conjugation");
3002 if (!noconvert) 3360 if (!noconvert)
3003 arg = default_conversion (arg); 3361 arg = default_conversion (arg);
3004 } 3362 }
3005 else 3363 else
3039 error_at (location, 3397 error_at (location,
3040 "wrong type argument to unary exclamation mark"); 3398 "wrong type argument to unary exclamation mark");
3041 return error_mark_node; 3399 return error_mark_node;
3042 } 3400 }
3043 arg = c_objc_common_truthvalue_conversion (location, arg); 3401 arg = c_objc_common_truthvalue_conversion (location, arg);
3044 ret = invert_truthvalue (arg); 3402 ret = invert_truthvalue_loc (location, arg);
3403 /* If the TRUTH_NOT_EXPR has been folded, reset the location. */
3404 if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
3405 location = EXPR_LOCATION (ret);
3045 goto return_build_unary_op; 3406 goto return_build_unary_op;
3046 3407
3047 case REALPART_EXPR: 3408 case REALPART_EXPR:
3048 if (TREE_CODE (arg) == COMPLEX_CST) 3409 if (TREE_CODE (arg) == COMPLEX_CST)
3049 ret = TREE_REALPART (arg); 3410 ret = TREE_REALPART (arg);
3050 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE) 3411 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
3051 ret = fold_build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg); 3412 ret = fold_build1_loc (location,
3413 REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
3052 else 3414 else
3053 ret = arg; 3415 ret = arg;
3416 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
3417 eptype = TREE_TYPE (eptype);
3054 goto return_build_unary_op; 3418 goto return_build_unary_op;
3055 3419
3056 case IMAGPART_EXPR: 3420 case IMAGPART_EXPR:
3057 if (TREE_CODE (arg) == COMPLEX_CST) 3421 if (TREE_CODE (arg) == COMPLEX_CST)
3058 ret = TREE_IMAGPART (arg); 3422 ret = TREE_IMAGPART (arg);
3059 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE) 3423 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
3060 ret = fold_build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg); 3424 ret = fold_build1_loc (location,
3425 IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
3061 else 3426 else
3062 ret = omit_one_operand (TREE_TYPE (arg), integer_zero_node, arg); 3427 ret = omit_one_operand_loc (location, TREE_TYPE (arg),
3428 integer_zero_node, arg);
3429 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
3430 eptype = TREE_TYPE (eptype);
3063 goto return_build_unary_op; 3431 goto return_build_unary_op;
3064 3432
3065 case PREINCREMENT_EXPR: 3433 case PREINCREMENT_EXPR:
3066 case POSTINCREMENT_EXPR: 3434 case POSTINCREMENT_EXPR:
3067 case PREDECREMENT_EXPR: 3435 case PREDECREMENT_EXPR:
3068 case POSTDECREMENT_EXPR: 3436 case POSTDECREMENT_EXPR:
3069 3437
3438 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
3439 {
3440 tree inner = build_unary_op (location, code,
3441 C_MAYBE_CONST_EXPR_EXPR (arg), flag);
3442 if (inner == error_mark_node)
3443 return error_mark_node;
3444 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
3445 C_MAYBE_CONST_EXPR_PRE (arg), inner);
3446 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
3447 C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
3448 goto return_build_unary_op;
3449 }
3450
3451 /* Complain about anything that is not a true lvalue. */
3452 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
3453 || code == POSTINCREMENT_EXPR)
3454 ? lv_increment
3455 : lv_decrement)))
3456 return error_mark_node;
3457
3458 if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
3459 {
3460 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
3461 warning_at (location, OPT_Wc___compat,
3462 "increment of enumeration value is invalid in C++");
3463 else
3464 warning_at (location, OPT_Wc___compat,
3465 "decrement of enumeration value is invalid in C++");
3466 }
3467
3468 /* Ensure the argument is fully folded inside any SAVE_EXPR. */
3469 arg = c_fully_fold (arg, false, NULL);
3470
3070 /* Increment or decrement the real part of the value, 3471 /* Increment or decrement the real part of the value,
3071 and don't change the imaginary part. */ 3472 and don't change the imaginary part. */
3072 if (typecode == COMPLEX_TYPE) 3473 if (typecode == COMPLEX_TYPE)
3073 { 3474 {
3074 tree real, imag; 3475 tree real, imag;
3075 3476
3076 pedwarn (location, OPT_pedantic, 3477 pedwarn (location, OPT_pedantic,
3077 "ISO C does not support %<++%> and %<--%> on complex types"); 3478 "ISO C does not support %<++%> and %<--%> on complex types");
3078 3479
3079 arg = stabilize_reference (arg); 3480 arg = stabilize_reference (arg);
3080 real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg, 1); 3481 real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg, 1);
3081 imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg, 1); 3482 imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg, 1);
3122 } 3523 }
3123 else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE 3524 else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
3124 || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE) 3525 || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE)
3125 { 3526 {
3126 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) 3527 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
3127 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 3528 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
3128 "wrong type argument to increment"); 3529 "wrong type argument to increment");
3129 else 3530 else
3130 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 3531 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
3131 "wrong type argument to decrement"); 3532 "wrong type argument to decrement");
3132 } 3533 }
3133 3534
3134 inc = c_size_in_bytes (TREE_TYPE (argtype)); 3535 inc = c_size_in_bytes (TREE_TYPE (argtype));
3135 inc = fold_convert (sizetype, inc); 3536 inc = fold_convert_loc (location, sizetype, inc);
3136 } 3537 }
3137 else if (FRACT_MODE_P (TYPE_MODE (argtype))) 3538 else if (FRACT_MODE_P (TYPE_MODE (argtype)))
3138 { 3539 {
3139 /* For signed fract types, we invert ++ to -- or 3540 /* For signed fract types, we invert ++ to -- or
3140 -- to ++, and change inc from 1 to -1, because 3541 -- to ++, and change inc from 1 to -1, because
3157 { 3558 {
3158 inc = integer_one_node; 3559 inc = integer_one_node;
3159 inc = convert (argtype, inc); 3560 inc = convert (argtype, inc);
3160 } 3561 }
3161 3562
3162 /* Complain about anything else that is not a true lvalue. */
3163 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
3164 || code == POSTINCREMENT_EXPR)
3165 ? lv_increment
3166 : lv_decrement)))
3167 return error_mark_node;
3168
3169 /* Report a read-only lvalue. */ 3563 /* Report a read-only lvalue. */
3170 if (TREE_READONLY (arg)) 3564 if (TYPE_READONLY (argtype))
3171 { 3565 {
3172 readonly_error (arg, 3566 readonly_error (arg,
3173 ((code == PREINCREMENT_EXPR 3567 ((code == PREINCREMENT_EXPR
3174 || code == POSTINCREMENT_EXPR) 3568 || code == POSTINCREMENT_EXPR)
3175 ? lv_increment : lv_decrement)); 3569 ? lv_increment : lv_decrement));
3176 return error_mark_node; 3570 return error_mark_node;
3177 } 3571 }
3572 else if (TREE_READONLY (arg))
3573 readonly_warning (arg,
3574 ((code == PREINCREMENT_EXPR
3575 || code == POSTINCREMENT_EXPR)
3576 ? lv_increment : lv_decrement));
3178 3577
3179 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE) 3578 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
3180 val = boolean_increment (code, arg); 3579 val = boolean_increment (code, arg);
3181 else 3580 else
3182 val = build2 (code, TREE_TYPE (arg), arg, inc); 3581 val = build2 (code, TREE_TYPE (arg), arg, inc);
3188 } 3587 }
3189 3588
3190 case ADDR_EXPR: 3589 case ADDR_EXPR:
3191 /* Note that this operation never does default_conversion. */ 3590 /* Note that this operation never does default_conversion. */
3192 3591
3592 /* The operand of unary '&' must be an lvalue (which excludes
3593 expressions of type void), or, in C99, the result of a [] or
3594 unary '*' operator. */
3595 if (VOID_TYPE_P (TREE_TYPE (arg))
3596 && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
3597 && (TREE_CODE (arg) != INDIRECT_REF
3598 || !flag_isoc99))
3599 pedwarn (location, 0, "taking address of expression of type %<void%>");
3600
3193 /* Let &* cancel out to simplify resulting code. */ 3601 /* Let &* cancel out to simplify resulting code. */
3194 if (TREE_CODE (arg) == INDIRECT_REF) 3602 if (TREE_CODE (arg) == INDIRECT_REF)
3195 { 3603 {
3196 /* Don't let this be an lvalue. */ 3604 /* Don't let this be an lvalue. */
3197 if (lvalue_p (TREE_OPERAND (arg, 0))) 3605 if (lvalue_p (TREE_OPERAND (arg, 0)))
3198 return non_lvalue (TREE_OPERAND (arg, 0)); 3606 return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
3199 ret = TREE_OPERAND (arg, 0); 3607 ret = TREE_OPERAND (arg, 0);
3200 goto return_build_unary_op; 3608 goto return_build_unary_op;
3201 } 3609 }
3202 3610
3203 /* For &x[y], return x+y */ 3611 /* For &x[y], return x+y */
3206 tree op0 = TREE_OPERAND (arg, 0); 3614 tree op0 = TREE_OPERAND (arg, 0);
3207 if (!c_mark_addressable (op0)) 3615 if (!c_mark_addressable (op0))
3208 return error_mark_node; 3616 return error_mark_node;
3209 return build_binary_op (location, PLUS_EXPR, 3617 return build_binary_op (location, PLUS_EXPR,
3210 (TREE_CODE (TREE_TYPE (op0)) == ARRAY_TYPE 3618 (TREE_CODE (TREE_TYPE (op0)) == ARRAY_TYPE
3211 ? array_to_pointer_conversion (op0) 3619 ? array_to_pointer_conversion (location,
3620 op0)
3212 : op0), 3621 : op0),
3213 TREE_OPERAND (arg, 1), 1); 3622 TREE_OPERAND (arg, 1), 1);
3214 } 3623 }
3215 3624
3216 /* Anything not already handled and not a true memory reference 3625 /* Anything not already handled and not a true memory reference
3217 or a non-lvalue array is an error. */ 3626 or a non-lvalue array is an error. */
3218 else if (typecode != FUNCTION_TYPE && !flag 3627 else if (typecode != FUNCTION_TYPE && !flag
3219 && !lvalue_or_else (arg, lv_addressof)) 3628 && !lvalue_or_else (arg, lv_addressof))
3220 return error_mark_node; 3629 return error_mark_node;
3630
3631 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
3632 folding later. */
3633 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
3634 {
3635 tree inner = build_unary_op (location, code,
3636 C_MAYBE_CONST_EXPR_EXPR (arg), flag);
3637 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
3638 C_MAYBE_CONST_EXPR_PRE (arg), inner);
3639 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
3640 C_MAYBE_CONST_EXPR_NON_CONST (ret)
3641 = C_MAYBE_CONST_EXPR_NON_CONST (arg);
3642 goto return_build_unary_op;
3643 }
3221 3644
3222 /* Ordinary case; arg is a COMPONENT_REF or a decl. */ 3645 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3223 argtype = TREE_TYPE (arg); 3646 argtype = TREE_TYPE (arg);
3224 3647
3225 /* If the lvalue is const or volatile, merge that into the type 3648 /* If the lvalue is const or volatile, merge that into the type
3244 when we have proper support for integer constant expressions. */ 3667 when we have proper support for integer constant expressions. */
3245 val = get_base_address (arg); 3668 val = get_base_address (arg);
3246 if (val && TREE_CODE (val) == INDIRECT_REF 3669 if (val && TREE_CODE (val) == INDIRECT_REF
3247 && TREE_CONSTANT (TREE_OPERAND (val, 0))) 3670 && TREE_CONSTANT (TREE_OPERAND (val, 0)))
3248 { 3671 {
3249 tree op0 = fold_convert (sizetype, fold_offsetof (arg, val)), op1; 3672 tree op0 = fold_convert_loc (location, sizetype,
3250 3673 fold_offsetof (arg, val)), op1;
3251 op1 = fold_convert (argtype, TREE_OPERAND (val, 0)); 3674
3252 ret = fold_build2 (POINTER_PLUS_EXPR, argtype, op1, op0); 3675 op1 = fold_convert_loc (location, argtype, TREE_OPERAND (val, 0));
3676 ret = fold_build2_loc (location, POINTER_PLUS_EXPR, argtype, op1, op0);
3253 goto return_build_unary_op; 3677 goto return_build_unary_op;
3254 } 3678 }
3255 3679
3256 val = build1 (ADDR_EXPR, argtype, arg); 3680 val = build1 (ADDR_EXPR, argtype, arg);
3257 3681
3262 gcc_unreachable (); 3686 gcc_unreachable ();
3263 } 3687 }
3264 3688
3265 if (argtype == 0) 3689 if (argtype == 0)
3266 argtype = TREE_TYPE (arg); 3690 argtype = TREE_TYPE (arg);
3267 ret = require_constant_value ? fold_build1_initializer (code, argtype, arg) 3691 if (TREE_CODE (arg) == INTEGER_CST)
3268 : fold_build1 (code, argtype, arg); 3692 ret = (require_constant_value
3693 ? fold_build1_initializer_loc (location, code, argtype, arg)
3694 : fold_build1_loc (location, code, argtype, arg));
3695 else
3696 ret = build1 (code, argtype, arg);
3269 return_build_unary_op: 3697 return_build_unary_op:
3270 gcc_assert (ret != error_mark_node); 3698 gcc_assert (ret != error_mark_node);
3699 if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
3700 && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
3701 ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
3702 else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
3703 ret = note_integer_operands (ret);
3704 if (eptype)
3705 ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
3271 protected_set_expr_location (ret, location); 3706 protected_set_expr_location (ret, location);
3272 return ret; 3707 return ret;
3273 } 3708 }
3274 3709
3275 /* Return nonzero if REF is an lvalue valid for this language. 3710 /* Return nonzero if REF is an lvalue valid for this language.
3276 Lvalues can be assigned, unless their type has TYPE_READONLY. 3711 Lvalues can be assigned, unless their type has TYPE_READONLY.
3277 Lvalues can have their address taken, unless they have C_DECL_REGISTER. */ 3712 Lvalues can have their address taken, unless they have C_DECL_REGISTER. */
3278 3713
3279 static int 3714 bool
3280 lvalue_p (const_tree ref) 3715 lvalue_p (const_tree ref)
3281 { 3716 {
3282 const enum tree_code code = TREE_CODE (ref); 3717 const enum tree_code code = TREE_CODE (ref);
3283 3718
3284 switch (code) 3719 switch (code)
3285 { 3720 {
3286 case REALPART_EXPR: 3721 case REALPART_EXPR:
3287 case IMAGPART_EXPR: 3722 case IMAGPART_EXPR:
3288 case COMPONENT_REF: 3723 case COMPONENT_REF:
3289 return lvalue_p (TREE_OPERAND (ref, 0)); 3724 return lvalue_p (TREE_OPERAND (ref, 0));
3725
3726 case C_MAYBE_CONST_EXPR:
3727 return lvalue_p (TREE_OPERAND (ref, 1));
3290 3728
3291 case COMPOUND_LITERAL_EXPR: 3729 case COMPOUND_LITERAL_EXPR:
3292 case STRING_CST: 3730 case STRING_CST:
3293 return 1; 3731 return 1;
3294 3732
3343 error (READONLY_MSG (G_("assignment of read-only location %qE"), 3781 error (READONLY_MSG (G_("assignment of read-only location %qE"),
3344 G_("increment of read-only location %qE"), 3782 G_("increment of read-only location %qE"),
3345 G_("decrement of read-only location %qE"), 3783 G_("decrement of read-only location %qE"),
3346 G_("read-only location %qE used as %<asm%> output")), 3784 G_("read-only location %qE used as %<asm%> output")),
3347 arg); 3785 arg);
3786 }
3787
3788 /* Give a warning for storing in something that is read-only in GCC
3789 terms but not const in ISO C terms. */
3790
3791 static void
3792 readonly_warning (tree arg, enum lvalue_use use)
3793 {
3794 switch (use)
3795 {
3796 case lv_assign:
3797 warning (0, "assignment of read-only location %qE", arg);
3798 break;
3799 case lv_increment:
3800 warning (0, "increment of read-only location %qE", arg);
3801 break;
3802 case lv_decrement:
3803 warning (0, "decrement of read-only location %qE", arg);
3804 break;
3805 default:
3806 gcc_unreachable ();
3807 }
3808 return;
3348 } 3809 }
3349 3810
3350 3811
3351 /* Return nonzero if REF is an lvalue valid for this language; 3812 /* Return nonzero if REF is an lvalue valid for this language;
3352 otherwise, print an error message and return zero. USE says 3813 otherwise, print an error message and return zero. USE says
3428 default: 3889 default:
3429 return true; 3890 return true;
3430 } 3891 }
3431 } 3892 }
3432 3893
3433 /* Build and return a conditional expression IFEXP ? OP1 : OP2. */ 3894 /* Build and return a conditional expression IFEXP ? OP1 : OP2. If
3895 IFEXP_BCP then the condition is a call to __builtin_constant_p, and
3896 if folded to an integer constant then the unselected half may
3897 contain arbitrary operations not normally permitted in constant
3898 expressions. Set the location of the expression to LOC. */
3434 3899
3435 tree 3900 tree
3436 build_conditional_expr (tree ifexp, tree op1, tree op2) 3901 build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
3902 tree op1, tree op1_original_type, tree op2,
3903 tree op2_original_type)
3437 { 3904 {
3438 tree type1; 3905 tree type1;
3439 tree type2; 3906 tree type2;
3440 enum tree_code code1; 3907 enum tree_code code1;
3441 enum tree_code code2; 3908 enum tree_code code2;
3442 tree result_type = NULL; 3909 tree result_type = NULL;
3910 tree ep_result_type = NULL;
3443 tree orig_op1 = op1, orig_op2 = op2; 3911 tree orig_op1 = op1, orig_op2 = op2;
3912 bool int_const, op1_int_operands, op2_int_operands, int_operands;
3913 bool ifexp_int_operands;
3914 tree ret;
3444 bool objc_ok; 3915 bool objc_ok;
3916
3917 op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
3918 if (op1_int_operands)
3919 op1 = remove_c_maybe_const_expr (op1);
3920 op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
3921 if (op2_int_operands)
3922 op2 = remove_c_maybe_const_expr (op2);
3923 ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
3924 if (ifexp_int_operands)
3925 ifexp = remove_c_maybe_const_expr (ifexp);
3445 3926
3446 /* Promote both alternatives. */ 3927 /* Promote both alternatives. */
3447 3928
3448 if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE) 3929 if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
3449 op1 = default_conversion (op1); 3930 op1 = default_conversion (op1);
3462 3943
3463 /* C90 does not permit non-lvalue arrays in conditional expressions. 3944 /* C90 does not permit non-lvalue arrays in conditional expressions.
3464 In C99 they will be pointers by now. */ 3945 In C99 they will be pointers by now. */
3465 if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE) 3946 if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
3466 { 3947 {
3467 error ("non-lvalue array in conditional expression"); 3948 error_at (colon_loc, "non-lvalue array in conditional expression");
3468 return error_mark_node; 3949 return error_mark_node;
3469 } 3950 }
3470 3951
3471 objc_ok = objc_compare_types (type1, type2, -3, NULL_TREE); 3952 objc_ok = objc_compare_types (type1, type2, -3, NULL_TREE);
3953
3954 if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
3955 || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
3956 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
3957 || code1 == COMPLEX_TYPE)
3958 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
3959 || code2 == COMPLEX_TYPE))
3960 {
3961 ep_result_type = c_common_type (type1, type2);
3962 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
3963 {
3964 op1 = TREE_OPERAND (op1, 0);
3965 type1 = TREE_TYPE (op1);
3966 gcc_assert (TREE_CODE (type1) == code1);
3967 }
3968 if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
3969 {
3970 op2 = TREE_OPERAND (op2, 0);
3971 type2 = TREE_TYPE (op2);
3972 gcc_assert (TREE_CODE (type2) == code2);
3973 }
3974 }
3975
3976 if (warn_cxx_compat)
3977 {
3978 tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
3979 tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
3980
3981 if (TREE_CODE (t1) == ENUMERAL_TYPE
3982 && TREE_CODE (t2) == ENUMERAL_TYPE
3983 && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
3984 warning_at (colon_loc, OPT_Wc___compat,
3985 ("different enum types in conditional is "
3986 "invalid in C++: %qT vs %qT"),
3987 t1, t2);
3988 }
3472 3989
3473 /* Quickly detect the usual case where op1 and op2 have the same type 3990 /* Quickly detect the usual case where op1 and op2 have the same type
3474 after promotion. */ 3991 after promotion. */
3475 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)) 3992 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
3476 { 3993 {
3489 /* If -Wsign-compare, warn here if type1 and type2 have 4006 /* If -Wsign-compare, warn here if type1 and type2 have
3490 different signedness. We'll promote the signed to unsigned 4007 different signedness. We'll promote the signed to unsigned
3491 and later code won't know it used to be different. 4008 and later code won't know it used to be different.
3492 Do this check on the original types, so that explicit casts 4009 Do this check on the original types, so that explicit casts
3493 will be considered, but default promotions won't. */ 4010 will be considered, but default promotions won't. */
3494 if (warn_sign_compare && !skip_evaluation) 4011 if (c_inhibit_evaluation_warnings == 0)
3495 { 4012 {
3496 int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1)); 4013 int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
3497 int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2)); 4014 int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
3498 4015
3499 if (unsigned_op1 ^ unsigned_op2) 4016 if (unsigned_op1 ^ unsigned_op2)
3503 /* Do not warn if the result type is signed, since the 4020 /* Do not warn if the result type is signed, since the
3504 signed type will only be chosen if it can represent 4021 signed type will only be chosen if it can represent
3505 all the values of the unsigned type. */ 4022 all the values of the unsigned type. */
3506 if (!TYPE_UNSIGNED (result_type)) 4023 if (!TYPE_UNSIGNED (result_type))
3507 /* OK */; 4024 /* OK */;
3508 /* Do not warn if the signed quantity is an unsuffixed
3509 integer literal (or some static constant expression
3510 involving such literals) and it is non-negative. */
3511 else if ((unsigned_op2
3512 && tree_expr_nonnegative_warnv_p (op1, &ovf))
3513 || (unsigned_op1
3514 && tree_expr_nonnegative_warnv_p (op2, &ovf)))
3515 /* OK */;
3516 else 4025 else
3517 warning (OPT_Wsign_compare, "signed and unsigned type in conditional expression"); 4026 {
4027 bool op1_maybe_const = true;
4028 bool op2_maybe_const = true;
4029
4030 /* Do not warn if the signed quantity is an
4031 unsuffixed integer literal (or some static
4032 constant expression involving such literals) and
4033 it is non-negative. This warning requires the
4034 operands to be folded for best results, so do
4035 that folding in this case even without
4036 warn_sign_compare to avoid warning options
4037 possibly affecting code generation. */
4038 c_inhibit_evaluation_warnings
4039 += (ifexp == truthvalue_false_node);
4040 op1 = c_fully_fold (op1, require_constant_value,
4041 &op1_maybe_const);
4042 c_inhibit_evaluation_warnings
4043 -= (ifexp == truthvalue_false_node);
4044
4045 c_inhibit_evaluation_warnings
4046 += (ifexp == truthvalue_true_node);
4047 op2 = c_fully_fold (op2, require_constant_value,
4048 &op2_maybe_const);
4049 c_inhibit_evaluation_warnings
4050 -= (ifexp == truthvalue_true_node);
4051
4052 if (warn_sign_compare)
4053 {
4054 if ((unsigned_op2
4055 && tree_expr_nonnegative_warnv_p (op1, &ovf))
4056 || (unsigned_op1
4057 && tree_expr_nonnegative_warnv_p (op2, &ovf)))
4058 /* OK */;
4059 else
4060 warning_at (colon_loc, OPT_Wsign_compare,
4061 ("signed and unsigned type in "
4062 "conditional expression"));
4063 }
4064 if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
4065 op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
4066 if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
4067 op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
4068 }
3518 } 4069 }
3519 } 4070 }
3520 } 4071 }
3521 else if (code1 == VOID_TYPE || code2 == VOID_TYPE) 4072 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
3522 { 4073 {
3523 if (code1 != VOID_TYPE || code2 != VOID_TYPE) 4074 if (code1 != VOID_TYPE || code2 != VOID_TYPE)
3524 pedwarn (input_location, OPT_pedantic, 4075 pedwarn (colon_loc, OPT_pedantic,
3525 "ISO C forbids conditional expr with only one void side"); 4076 "ISO C forbids conditional expr with only one void side");
3526 result_type = void_type_node; 4077 result_type = void_type_node;
3527 } 4078 }
3528 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE) 4079 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
3529 { 4080 {
3530 if (comp_target_types (type1, type2)) 4081 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
4082 addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
4083 addr_space_t as_common;
4084
4085 if (comp_target_types (colon_loc, type1, type2))
3531 result_type = common_pointer_type (type1, type2); 4086 result_type = common_pointer_type (type1, type2);
3532 else if (null_pointer_constant_p (orig_op1)) 4087 else if (null_pointer_constant_p (orig_op1))
3533 result_type = qualify_type (type2, type1); 4088 result_type = type2;
3534 else if (null_pointer_constant_p (orig_op2)) 4089 else if (null_pointer_constant_p (orig_op2))
3535 result_type = qualify_type (type1, type2); 4090 result_type = type1;
4091 else if (!addr_space_superset (as1, as2, &as_common))
4092 {
4093 error_at (colon_loc, "pointers to disjoint address spaces "
4094 "used in conditional expression");
4095 return error_mark_node;
4096 }
3536 else if (VOID_TYPE_P (TREE_TYPE (type1))) 4097 else if (VOID_TYPE_P (TREE_TYPE (type1)))
3537 { 4098 {
3538 if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE) 4099 if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
3539 pedwarn (input_location, OPT_pedantic, 4100 pedwarn (colon_loc, OPT_pedantic,
3540 "ISO C forbids conditional expr between " 4101 "ISO C forbids conditional expr between "
3541 "%<void *%> and function pointer"); 4102 "%<void *%> and function pointer");
3542 result_type = build_pointer_type (qualify_type (TREE_TYPE (type1), 4103 result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
3543 TREE_TYPE (type2))); 4104 TREE_TYPE (type2)));
3544 } 4105 }
3545 else if (VOID_TYPE_P (TREE_TYPE (type2))) 4106 else if (VOID_TYPE_P (TREE_TYPE (type2)))
3546 { 4107 {
3547 if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE) 4108 if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
3548 pedwarn (input_location, OPT_pedantic, 4109 pedwarn (colon_loc, OPT_pedantic,
3549 "ISO C forbids conditional expr between " 4110 "ISO C forbids conditional expr between "
3550 "%<void *%> and function pointer"); 4111 "%<void *%> and function pointer");
3551 result_type = build_pointer_type (qualify_type (TREE_TYPE (type2), 4112 result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
3552 TREE_TYPE (type1))); 4113 TREE_TYPE (type1)));
3553 } 4114 }
3554 else 4115 else
3555 { 4116 {
4117 int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
4118
3556 if (!objc_ok) 4119 if (!objc_ok)
3557 pedwarn (input_location, 0, 4120 pedwarn (colon_loc, 0,
3558 "pointer type mismatch in conditional expression"); 4121 "pointer type mismatch in conditional expression");
3559 result_type = build_pointer_type (void_type_node); 4122 result_type = build_pointer_type
4123 (build_qualified_type (void_type_node, qual));
3560 } 4124 }
3561 } 4125 }
3562 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE) 4126 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
3563 { 4127 {
3564 if (!null_pointer_constant_p (orig_op2)) 4128 if (!null_pointer_constant_p (orig_op2))
3565 pedwarn (input_location, 0, 4129 pedwarn (colon_loc, 0,
3566 "pointer/integer type mismatch in conditional expression"); 4130 "pointer/integer type mismatch in conditional expression");
3567 else 4131 else
3568 { 4132 {
3569 op2 = null_pointer_node; 4133 op2 = null_pointer_node;
3570 } 4134 }
3571 result_type = type1; 4135 result_type = type1;
3572 } 4136 }
3573 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE) 4137 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
3574 { 4138 {
3575 if (!null_pointer_constant_p (orig_op1)) 4139 if (!null_pointer_constant_p (orig_op1))
3576 pedwarn (input_location, 0, 4140 pedwarn (colon_loc, 0,
3577 "pointer/integer type mismatch in conditional expression"); 4141 "pointer/integer type mismatch in conditional expression");
3578 else 4142 else
3579 { 4143 {
3580 op1 = null_pointer_node; 4144 op1 = null_pointer_node;
3581 } 4145 }
3586 { 4150 {
3587 if (flag_cond_mismatch) 4151 if (flag_cond_mismatch)
3588 result_type = void_type_node; 4152 result_type = void_type_node;
3589 else 4153 else
3590 { 4154 {
3591 error ("type mismatch in conditional expression"); 4155 error_at (colon_loc, "type mismatch in conditional expression");
3592 return error_mark_node; 4156 return error_mark_node;
3593 } 4157 }
3594 } 4158 }
3595 4159
3596 /* Merge const and volatile flags of the incoming types. */ 4160 /* Merge const and volatile flags of the incoming types. */
3597 result_type 4161 result_type
3598 = build_type_variant (result_type, 4162 = build_type_variant (result_type,
3599 TREE_READONLY (op1) || TREE_READONLY (op2), 4163 TYPE_READONLY (type1) || TYPE_READONLY (type2),
3600 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2)); 4164 TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
3601 4165
3602 if (result_type != TREE_TYPE (op1)) 4166 if (result_type != type1)
3603 op1 = convert_and_check (result_type, op1); 4167 op1 = convert_and_check (result_type, op1);
3604 if (result_type != TREE_TYPE (op2)) 4168 if (result_type != type2)
3605 op2 = convert_and_check (result_type, op2); 4169 op2 = convert_and_check (result_type, op2);
3606 4170
3607 return fold_build3 (COND_EXPR, result_type, ifexp, op1, op2); 4171 if (ifexp_bcp && ifexp == truthvalue_true_node)
4172 {
4173 op2_int_operands = true;
4174 op1 = c_fully_fold (op1, require_constant_value, NULL);
4175 }
4176 if (ifexp_bcp && ifexp == truthvalue_false_node)
4177 {
4178 op1_int_operands = true;
4179 op2 = c_fully_fold (op2, require_constant_value, NULL);
4180 }
4181 int_const = int_operands = (ifexp_int_operands
4182 && op1_int_operands
4183 && op2_int_operands);
4184 if (int_operands)
4185 {
4186 int_const = ((ifexp == truthvalue_true_node
4187 && TREE_CODE (orig_op1) == INTEGER_CST
4188 && !TREE_OVERFLOW (orig_op1))
4189 || (ifexp == truthvalue_false_node
4190 && TREE_CODE (orig_op2) == INTEGER_CST
4191 && !TREE_OVERFLOW (orig_op2)));
4192 }
4193 if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
4194 ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
4195 else
4196 {
4197 ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
4198 if (int_operands)
4199 ret = note_integer_operands (ret);
4200 }
4201 if (ep_result_type)
4202 ret = build1 (EXCESS_PRECISION_EXPR, ep_result_type, ret);
4203
4204 protected_set_expr_location (ret, colon_loc);
4205 return ret;
3608 } 4206 }
3609 4207
3610 /* Return a compound expression that performs two expressions and 4208 /* Return a compound expression that performs two expressions and
3611 returns the value of the second of them. */ 4209 returns the value of the second of them.
4210
4211 LOC is the location of the COMPOUND_EXPR. */
3612 4212
3613 tree 4213 tree
3614 build_compound_expr (tree expr1, tree expr2) 4214 build_compound_expr (location_t loc, tree expr1, tree expr2)
3615 { 4215 {
4216 bool expr1_int_operands, expr2_int_operands;
4217 tree eptype = NULL_TREE;
4218 tree ret;
4219
4220 expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
4221 if (expr1_int_operands)
4222 expr1 = remove_c_maybe_const_expr (expr1);
4223 expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
4224 if (expr2_int_operands)
4225 expr2 = remove_c_maybe_const_expr (expr2);
4226
4227 if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
4228 expr1 = TREE_OPERAND (expr1, 0);
4229 if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
4230 {
4231 eptype = TREE_TYPE (expr2);
4232 expr2 = TREE_OPERAND (expr2, 0);
4233 }
4234
3616 if (!TREE_SIDE_EFFECTS (expr1)) 4235 if (!TREE_SIDE_EFFECTS (expr1))
3617 { 4236 {
3618 /* The left-hand operand of a comma expression is like an expression 4237 /* The left-hand operand of a comma expression is like an expression
3619 statement: with -Wunused, we should warn if it doesn't have 4238 statement: with -Wunused, we should warn if it doesn't have
3620 any side-effects, unless it was explicitly cast to (void). */ 4239 any side-effects, unless it was explicitly cast to (void). */
3626 else if (VOID_TYPE_P (TREE_TYPE (expr1)) 4245 else if (VOID_TYPE_P (TREE_TYPE (expr1))
3627 && TREE_CODE (expr1) == COMPOUND_EXPR 4246 && TREE_CODE (expr1) == COMPOUND_EXPR
3628 && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1))) 4247 && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
3629 ; /* (void) a, (void) b, c */ 4248 ; /* (void) a, (void) b, c */
3630 else 4249 else
3631 warning (OPT_Wunused_value, 4250 warning_at (loc, OPT_Wunused_value,
3632 "left-hand operand of comma expression has no effect"); 4251 "left-hand operand of comma expression has no effect");
3633 } 4252 }
3634 } 4253 }
3635 4254
3636 /* With -Wunused, we should also warn if the left-hand operand does have 4255 /* With -Wunused, we should also warn if the left-hand operand does have
3637 side-effects, but computes a value which is not used. For example, in 4256 side-effects, but computes a value which is not used. For example, in
3638 `foo() + bar(), baz()' the result of the `+' operator is not used, 4257 `foo() + bar(), baz()' the result of the `+' operator is not used,
3639 so we should issue a warning. */ 4258 so we should issue a warning. */
3640 else if (warn_unused_value) 4259 else if (warn_unused_value)
3641 warn_if_unused_value (expr1, input_location); 4260 warn_if_unused_value (expr1, loc);
3642 4261
3643 if (expr2 == error_mark_node) 4262 if (expr2 == error_mark_node)
3644 return error_mark_node; 4263 return error_mark_node;
3645 4264
3646 return build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2); 4265 ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
3647 } 4266
3648 4267 if (flag_isoc99
3649 /* Build an expression representing a cast to type TYPE of expression EXPR. */ 4268 && expr1_int_operands
4269 && expr2_int_operands)
4270 ret = note_integer_operands (ret);
4271
4272 if (eptype)
4273 ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
4274
4275 protected_set_expr_location (ret, loc);
4276 return ret;
4277 }
4278
4279 /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to
4280 which we are casting. OTYPE is the type of the expression being
4281 cast. Both TYPE and OTYPE are pointer types. -Wcast-qual appeared
4282 on the command line. Named address space qualifiers are not handled
4283 here, because they result in different warnings. */
4284
4285 static void
4286 handle_warn_cast_qual (tree type, tree otype)
4287 {
4288 tree in_type = type;
4289 tree in_otype = otype;
4290 int added = 0;
4291 int discarded = 0;
4292 bool is_const;
4293
4294 /* Check that the qualifiers on IN_TYPE are a superset of the
4295 qualifiers of IN_OTYPE. The outermost level of POINTER_TYPE
4296 nodes is uninteresting and we stop as soon as we hit a
4297 non-POINTER_TYPE node on either type. */
4298 do
4299 {
4300 in_otype = TREE_TYPE (in_otype);
4301 in_type = TREE_TYPE (in_type);
4302
4303 /* GNU C allows cv-qualified function types. 'const' means the
4304 function is very pure, 'volatile' means it can't return. We
4305 need to warn when such qualifiers are added, not when they're
4306 taken away. */
4307 if (TREE_CODE (in_otype) == FUNCTION_TYPE
4308 && TREE_CODE (in_type) == FUNCTION_TYPE)
4309 added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
4310 & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
4311 else
4312 discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
4313 & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
4314 }
4315 while (TREE_CODE (in_type) == POINTER_TYPE
4316 && TREE_CODE (in_otype) == POINTER_TYPE);
4317
4318 if (added)
4319 warning (OPT_Wcast_qual, "cast adds new qualifiers to function type");
4320
4321 if (discarded)
4322 /* There are qualifiers present in IN_OTYPE that are not present
4323 in IN_TYPE. */
4324 warning (OPT_Wcast_qual,
4325 "cast discards qualifiers from pointer target type");
4326
4327 if (added || discarded)
4328 return;
4329
4330 /* A cast from **T to const **T is unsafe, because it can cause a
4331 const value to be changed with no additional warning. We only
4332 issue this warning if T is the same on both sides, and we only
4333 issue the warning if there are the same number of pointers on
4334 both sides, as otherwise the cast is clearly unsafe anyhow. A
4335 cast is unsafe when a qualifier is added at one level and const
4336 is not present at all outer levels.
4337
4338 To issue this warning, we check at each level whether the cast
4339 adds new qualifiers not already seen. We don't need to special
4340 case function types, as they won't have the same
4341 TYPE_MAIN_VARIANT. */
4342
4343 if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
4344 return;
4345 if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
4346 return;
4347
4348 in_type = type;
4349 in_otype = otype;
4350 is_const = TYPE_READONLY (TREE_TYPE (in_type));
4351 do
4352 {
4353 in_type = TREE_TYPE (in_type);
4354 in_otype = TREE_TYPE (in_otype);
4355 if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
4356 && !is_const)
4357 {
4358 warning (OPT_Wcast_qual,
4359 ("new qualifiers in middle of multi-level non-const cast "
4360 "are unsafe"));
4361 break;
4362 }
4363 if (is_const)
4364 is_const = TYPE_READONLY (in_type);
4365 }
4366 while (TREE_CODE (in_type) == POINTER_TYPE);
4367 }
4368
4369 /* Build an expression representing a cast to type TYPE of expression EXPR.
4370 LOC is the location of the cast-- typically the open paren of the cast. */
3650 4371
3651 tree 4372 tree
3652 build_c_cast (tree type, tree expr) 4373 build_c_cast (location_t loc, tree type, tree expr)
3653 { 4374 {
3654 tree value = expr; 4375 tree value;
4376
4377 if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
4378 expr = TREE_OPERAND (expr, 0);
4379
4380 value = expr;
3655 4381
3656 if (type == error_mark_node || expr == error_mark_node) 4382 if (type == error_mark_node || expr == error_mark_node)
3657 return error_mark_node; 4383 return error_mark_node;
3658 4384
3659 /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing 4385 /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
3664 4390
3665 type = TYPE_MAIN_VARIANT (type); 4391 type = TYPE_MAIN_VARIANT (type);
3666 4392
3667 if (TREE_CODE (type) == ARRAY_TYPE) 4393 if (TREE_CODE (type) == ARRAY_TYPE)
3668 { 4394 {
3669 error ("cast specifies array type"); 4395 error_at (loc, "cast specifies array type");
3670 return error_mark_node; 4396 return error_mark_node;
3671 } 4397 }
3672 4398
3673 if (TREE_CODE (type) == FUNCTION_TYPE) 4399 if (TREE_CODE (type) == FUNCTION_TYPE)
3674 { 4400 {
3675 error ("cast specifies function type"); 4401 error_at (loc, "cast specifies function type");
3676 return error_mark_node; 4402 return error_mark_node;
3677 } 4403 }
3678 4404
3679 if (!VOID_TYPE_P (type)) 4405 if (!VOID_TYPE_P (type))
3680 { 4406 {
3685 4411
3686 if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value))) 4412 if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
3687 { 4413 {
3688 if (TREE_CODE (type) == RECORD_TYPE 4414 if (TREE_CODE (type) == RECORD_TYPE
3689 || TREE_CODE (type) == UNION_TYPE) 4415 || TREE_CODE (type) == UNION_TYPE)
3690 pedwarn (input_location, OPT_pedantic, 4416 pedwarn (loc, OPT_pedantic,
3691 "ISO C forbids casting nonscalar to the same type"); 4417 "ISO C forbids casting nonscalar to the same type");
3692 } 4418 }
3693 else if (TREE_CODE (type) == UNION_TYPE) 4419 else if (TREE_CODE (type) == UNION_TYPE)
3694 { 4420 {
3695 tree field; 4421 tree field;
3702 4428
3703 if (field) 4429 if (field)
3704 { 4430 {
3705 tree t; 4431 tree t;
3706 4432
3707 pedwarn (input_location, OPT_pedantic, 4433 pedwarn (loc, OPT_pedantic, "ISO C forbids casts to union type");
3708 "ISO C forbids casts to union type"); 4434 t = digest_init (loc, type,
3709 t = digest_init (type,
3710 build_constructor_single (type, field, value), 4435 build_constructor_single (type, field, value),
3711 true, 0); 4436 NULL_TREE, false, true, 0);
3712 TREE_CONSTANT (t) = TREE_CONSTANT (value); 4437 TREE_CONSTANT (t) = TREE_CONSTANT (value);
3713 return t; 4438 return t;
3714 } 4439 }
3715 error ("cast to union type from type not present in union"); 4440 error_at (loc, "cast to union type from type not present in union");
3716 return error_mark_node; 4441 return error_mark_node;
3717 } 4442 }
3718 else 4443 else
3719 { 4444 {
3720 tree otype, ovalue; 4445 tree otype, ovalue;
3721 4446
3722 if (type == void_type_node) 4447 if (type == void_type_node)
3723 return build1 (CONVERT_EXPR, type, value); 4448 {
4449 tree t = build1 (CONVERT_EXPR, type, value);
4450 SET_EXPR_LOCATION (t, loc);
4451 return t;
4452 }
3724 4453
3725 otype = TREE_TYPE (value); 4454 otype = TREE_TYPE (value);
3726 4455
3727 /* Optionally warn about potentially worrisome casts. */ 4456 /* Optionally warn about potentially worrisome casts. */
3728
3729 if (warn_cast_qual 4457 if (warn_cast_qual
3730 && TREE_CODE (type) == POINTER_TYPE 4458 && TREE_CODE (type) == POINTER_TYPE
3731 && TREE_CODE (otype) == POINTER_TYPE) 4459 && TREE_CODE (otype) == POINTER_TYPE)
3732 { 4460 handle_warn_cast_qual (type, otype);
3733 tree in_type = type; 4461
3734 tree in_otype = otype; 4462 /* Warn about conversions between pointers to disjoint
3735 int added = 0; 4463 address spaces. */
3736 int discarded = 0; 4464 if (TREE_CODE (type) == POINTER_TYPE
3737 4465 && TREE_CODE (otype) == POINTER_TYPE
3738 /* Check that the qualifiers on IN_TYPE are a superset of 4466 && !null_pointer_constant_p (value))
3739 the qualifiers of IN_OTYPE. The outermost level of 4467 {
3740 POINTER_TYPE nodes is uninteresting and we stop as soon 4468 addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
3741 as we hit a non-POINTER_TYPE node on either type. */ 4469 addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
3742 do 4470 addr_space_t as_common;
4471
4472 if (!addr_space_superset (as_to, as_from, &as_common))
3743 { 4473 {
3744 in_otype = TREE_TYPE (in_otype); 4474 if (ADDR_SPACE_GENERIC_P (as_from))
3745 in_type = TREE_TYPE (in_type); 4475 warning_at (loc, 0, "cast to %s address space pointer "
3746 4476 "from disjoint generic address space pointer",
3747 /* GNU C allows cv-qualified function types. 'const' 4477 c_addr_space_name (as_to));
3748 means the function is very pure, 'volatile' means it 4478
3749 can't return. We need to warn when such qualifiers 4479 else if (ADDR_SPACE_GENERIC_P (as_to))
3750 are added, not when they're taken away. */ 4480 warning_at (loc, 0, "cast to generic address space pointer "
3751 if (TREE_CODE (in_otype) == FUNCTION_TYPE 4481 "from disjoint %s address space pointer",
3752 && TREE_CODE (in_type) == FUNCTION_TYPE) 4482 c_addr_space_name (as_from));
3753 added |= (TYPE_QUALS (in_type) & ~TYPE_QUALS (in_otype)); 4483
3754 else 4484 else
3755 discarded |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type)); 4485 warning_at (loc, 0, "cast to %s address space pointer "
4486 "from disjoint %s address space pointer",
4487 c_addr_space_name (as_to),
4488 c_addr_space_name (as_from));
3756 } 4489 }
3757 while (TREE_CODE (in_type) == POINTER_TYPE
3758 && TREE_CODE (in_otype) == POINTER_TYPE);
3759
3760 if (added)
3761 warning (OPT_Wcast_qual, "cast adds new qualifiers to function type");
3762
3763 if (discarded)
3764 /* There are qualifiers present in IN_OTYPE that are not
3765 present in IN_TYPE. */
3766 warning (OPT_Wcast_qual, "cast discards qualifiers from pointer target type");
3767 } 4490 }
3768 4491
3769 /* Warn about possible alignment problems. */ 4492 /* Warn about possible alignment problems. */
3770 if (STRICT_ALIGNMENT 4493 if (STRICT_ALIGNMENT
3771 && TREE_CODE (type) == POINTER_TYPE 4494 && TREE_CODE (type) == POINTER_TYPE
3776 restriction is unknown. */ 4499 restriction is unknown. */
3777 && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE 4500 && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
3778 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE) 4501 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
3779 && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode) 4502 && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
3780 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype))) 4503 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
3781 warning (OPT_Wcast_align, 4504 warning_at (loc, OPT_Wcast_align,
3782 "cast increases required alignment of target type"); 4505 "cast increases required alignment of target type");
3783 4506
3784 if (TREE_CODE (type) == INTEGER_TYPE 4507 if (TREE_CODE (type) == INTEGER_TYPE
3785 && TREE_CODE (otype) == POINTER_TYPE 4508 && TREE_CODE (otype) == POINTER_TYPE
3786 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)) 4509 && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
3787 /* Unlike conversion of integers to pointers, where the 4510 /* Unlike conversion of integers to pointers, where the
3788 warning is disabled for converting constants because 4511 warning is disabled for converting constants because
3789 of cases such as SIG_*, warn about converting constant 4512 of cases such as SIG_*, warn about converting constant
3790 pointers to integers. In some cases it may cause unwanted 4513 pointers to integers. In some cases it may cause unwanted
3791 sign extension, and a warning is appropriate. */ 4514 sign extension, and a warning is appropriate. */
3792 warning (OPT_Wpointer_to_int_cast, 4515 warning_at (loc, OPT_Wpointer_to_int_cast,
3793 "cast from pointer to integer of different size"); 4516 "cast from pointer to integer of different size");
3794 4517
3795 if (TREE_CODE (value) == CALL_EXPR 4518 if (TREE_CODE (value) == CALL_EXPR
3796 && TREE_CODE (type) != TREE_CODE (otype)) 4519 && TREE_CODE (type) != TREE_CODE (otype))
3797 warning (OPT_Wbad_function_cast, "cast from function call of type %qT " 4520 warning_at (loc, OPT_Wbad_function_cast,
3798 "to non-matching type %qT", otype, type); 4521 "cast from function call of type %qT "
4522 "to non-matching type %qT", otype, type);
3799 4523
3800 if (TREE_CODE (type) == POINTER_TYPE 4524 if (TREE_CODE (type) == POINTER_TYPE
3801 && TREE_CODE (otype) == INTEGER_TYPE 4525 && TREE_CODE (otype) == INTEGER_TYPE
3802 && TYPE_PRECISION (type) != TYPE_PRECISION (otype) 4526 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3803 /* Don't warn about converting any constant. */ 4527 /* Don't warn about converting any constant. */
3804 && !TREE_CONSTANT (value)) 4528 && !TREE_CONSTANT (value))
3805 warning (OPT_Wint_to_pointer_cast, "cast to pointer from integer " 4529 warning_at (loc,
3806 "of different size"); 4530 OPT_Wint_to_pointer_cast, "cast to pointer from integer "
4531 "of different size");
3807 4532
3808 if (warn_strict_aliasing <= 2) 4533 if (warn_strict_aliasing <= 2)
3809 strict_aliasing_warning (otype, type, expr); 4534 strict_aliasing_warning (otype, type, expr);
3810 4535
3811 /* If pedantic, warn for conversions between function and object 4536 /* If pedantic, warn for conversions between function and object
3814 if (pedantic 4539 if (pedantic
3815 && TREE_CODE (type) == POINTER_TYPE 4540 && TREE_CODE (type) == POINTER_TYPE
3816 && TREE_CODE (otype) == POINTER_TYPE 4541 && TREE_CODE (otype) == POINTER_TYPE
3817 && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE 4542 && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
3818 && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE) 4543 && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
3819 pedwarn (input_location, OPT_pedantic, "ISO C forbids " 4544 pedwarn (loc, OPT_pedantic, "ISO C forbids "
3820 "conversion of function pointer to object pointer type"); 4545 "conversion of function pointer to object pointer type");
3821 4546
3822 if (pedantic 4547 if (pedantic
3823 && TREE_CODE (type) == POINTER_TYPE 4548 && TREE_CODE (type) == POINTER_TYPE
3824 && TREE_CODE (otype) == POINTER_TYPE 4549 && TREE_CODE (otype) == POINTER_TYPE
3825 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE 4550 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
3826 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE 4551 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
3827 && !null_pointer_constant_p (value)) 4552 && !null_pointer_constant_p (value))
3828 pedwarn (input_location, OPT_pedantic, "ISO C forbids " 4553 pedwarn (loc, OPT_pedantic, "ISO C forbids "
3829 "conversion of object pointer to function pointer type"); 4554 "conversion of object pointer to function pointer type");
3830 4555
3831 ovalue = value; 4556 ovalue = value;
3832 value = convert (type, value); 4557 value = convert (type, value);
3833 4558
3834 /* Ignore any integer overflow caused by the cast. */ 4559 /* Ignore any integer overflow caused by the cast. */
3835 if (TREE_CODE (value) == INTEGER_CST) 4560 if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
3836 { 4561 {
3837 if (CONSTANT_CLASS_P (ovalue) && TREE_OVERFLOW (ovalue)) 4562 if (CONSTANT_CLASS_P (ovalue) && TREE_OVERFLOW (ovalue))
3838 { 4563 {
3839 if (!TREE_OVERFLOW (value)) 4564 if (!TREE_OVERFLOW (value))
3840 { 4565 {
3851 } 4576 }
3852 } 4577 }
3853 4578
3854 /* Don't let a cast be an lvalue. */ 4579 /* Don't let a cast be an lvalue. */
3855 if (value == expr) 4580 if (value == expr)
3856 value = non_lvalue (value); 4581 value = non_lvalue_loc (loc, value);
3857 4582
4583 /* Don't allow the results of casting to floating-point or complex
4584 types be confused with actual constants, or casts involving
4585 integer and pointer types other than direct integer-to-integer
4586 and integer-to-pointer be confused with integer constant
4587 expressions and null pointer constants. */
4588 if (TREE_CODE (value) == REAL_CST
4589 || TREE_CODE (value) == COMPLEX_CST
4590 || (TREE_CODE (value) == INTEGER_CST
4591 && !((TREE_CODE (expr) == INTEGER_CST
4592 && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
4593 || TREE_CODE (expr) == REAL_CST
4594 || TREE_CODE (expr) == COMPLEX_CST)))
4595 value = build1 (NOP_EXPR, type, value);
4596
4597 if (CAN_HAVE_LOCATION_P (value))
4598 SET_EXPR_LOCATION (value, loc);
3858 return value; 4599 return value;
3859 } 4600 }
3860 4601
3861 /* Interpret a cast of expression EXPR to type TYPE. */ 4602 /* Interpret a cast of expression EXPR to type TYPE. LOC is the
4603 location of the open paren of the cast, or the position of the cast
4604 expr. */
3862 tree 4605 tree
3863 c_cast_expr (struct c_type_name *type_name, tree expr) 4606 c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
3864 { 4607 {
3865 tree type; 4608 tree type;
4609 tree type_expr = NULL_TREE;
4610 bool type_expr_const = true;
4611 tree ret;
3866 int saved_wsp = warn_strict_prototypes; 4612 int saved_wsp = warn_strict_prototypes;
3867 4613
3868 /* This avoids warnings about unprototyped casts on 4614 /* This avoids warnings about unprototyped casts on
3869 integers. E.g. "#define SIG_DFL (void(*)())0". */ 4615 integers. E.g. "#define SIG_DFL (void(*)())0". */
3870 if (TREE_CODE (expr) == INTEGER_CST) 4616 if (TREE_CODE (expr) == INTEGER_CST)
3871 warn_strict_prototypes = 0; 4617 warn_strict_prototypes = 0;
3872 type = groktypename (type_name); 4618 type = groktypename (type_name, &type_expr, &type_expr_const);
3873 warn_strict_prototypes = saved_wsp; 4619 warn_strict_prototypes = saved_wsp;
3874 4620
3875 return build_c_cast (type, expr); 4621 ret = build_c_cast (loc, type, expr);
4622 if (type_expr)
4623 {
4624 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
4625 C_MAYBE_CONST_EXPR_NON_CONST (ret) = !type_expr_const;
4626 SET_EXPR_LOCATION (ret, loc);
4627 }
4628
4629 if (CAN_HAVE_LOCATION_P (ret) && !EXPR_HAS_LOCATION (ret))
4630 SET_EXPR_LOCATION (ret, loc);
4631
4632 /* C++ does not permits types to be defined in a cast. */
4633 if (warn_cxx_compat && type_name->specs->tag_defined_p)
4634 warning_at (loc, OPT_Wc___compat,
4635 "defining a type in a cast is invalid in C++");
4636
4637 return ret;
3876 } 4638 }
3877 4639
3878 /* Build an assignment expression of lvalue LHS from value RHS. 4640 /* Build an assignment expression of lvalue LHS from value RHS.
4641 If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
4642 may differ from TREE_TYPE (LHS) for an enum bitfield.
3879 MODIFYCODE is the code for a binary operator that we use 4643 MODIFYCODE is the code for a binary operator that we use
3880 to combine the old value of LHS with RHS to get the new value. 4644 to combine the old value of LHS with RHS to get the new value.
3881 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. 4645 Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
3882 4646 If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
3883 LOCATION is the location of the MODIFYCODE operator. */ 4647 which may differ from TREE_TYPE (RHS) for an enum value.
4648
4649 LOCATION is the location of the MODIFYCODE operator.
4650 RHS_LOC is the location of the RHS. */
3884 4651
3885 tree 4652 tree
3886 build_modify_expr (location_t location, 4653 build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
3887 tree lhs, enum tree_code modifycode, tree rhs) 4654 enum tree_code modifycode,
4655 location_t rhs_loc, tree rhs, tree rhs_origtype)
3888 { 4656 {
3889 tree result; 4657 tree result;
3890 tree newrhs; 4658 tree newrhs;
4659 tree rhs_semantic_type = NULL_TREE;
3891 tree lhstype = TREE_TYPE (lhs); 4660 tree lhstype = TREE_TYPE (lhs);
3892 tree olhstype = lhstype; 4661 tree olhstype = lhstype;
4662 bool npc;
3893 4663
3894 /* Types that aren't fully specified cannot be used in assignments. */ 4664 /* Types that aren't fully specified cannot be used in assignments. */
3895 lhs = require_complete_type (lhs); 4665 lhs = require_complete_type (lhs);
3896 4666
3897 /* Avoid duplicate error messages from operands that had errors. */ 4667 /* Avoid duplicate error messages from operands that had errors. */
3899 return error_mark_node; 4669 return error_mark_node;
3900 4670
3901 if (!lvalue_or_else (lhs, lv_assign)) 4671 if (!lvalue_or_else (lhs, lv_assign))
3902 return error_mark_node; 4672 return error_mark_node;
3903 4673
3904 STRIP_TYPE_NOPS (rhs); 4674 if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
4675 {
4676 rhs_semantic_type = TREE_TYPE (rhs);
4677 rhs = TREE_OPERAND (rhs, 0);
4678 }
3905 4679
3906 newrhs = rhs; 4680 newrhs = rhs;
4681
4682 if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
4683 {
4684 tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
4685 lhs_origtype, modifycode, rhs_loc, rhs,
4686 rhs_origtype);
4687 if (inner == error_mark_node)
4688 return error_mark_node;
4689 result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
4690 C_MAYBE_CONST_EXPR_PRE (lhs), inner);
4691 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
4692 C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
4693 protected_set_expr_location (result, location);
4694 return result;
4695 }
3907 4696
3908 /* If a binary op has been requested, combine the old LHS value with the RHS 4697 /* If a binary op has been requested, combine the old LHS value with the RHS
3909 producing the value we should actually store into the LHS. */ 4698 producing the value we should actually store into the LHS. */
3910 4699
3911 if (modifycode != NOP_EXPR) 4700 if (modifycode != NOP_EXPR)
3912 { 4701 {
4702 lhs = c_fully_fold (lhs, false, NULL);
3913 lhs = stabilize_reference (lhs); 4703 lhs = stabilize_reference (lhs);
3914 newrhs = build_binary_op (location, 4704 newrhs = build_binary_op (location,
3915 modifycode, lhs, rhs, 1); 4705 modifycode, lhs, rhs, 1);
4706
4707 /* The original type of the right hand side is no longer
4708 meaningful. */
4709 rhs_origtype = NULL_TREE;
3916 } 4710 }
3917 4711
3918 /* Give an error for storing in something that is 'const'. */ 4712 /* Give an error for storing in something that is 'const'. */
3919 4713
3920 if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype) 4714 if (TYPE_READONLY (lhstype)
3921 || ((TREE_CODE (lhstype) == RECORD_TYPE 4715 || ((TREE_CODE (lhstype) == RECORD_TYPE
3922 || TREE_CODE (lhstype) == UNION_TYPE) 4716 || TREE_CODE (lhstype) == UNION_TYPE)
3923 && C_TYPE_FIELDS_READONLY (lhstype))) 4717 && C_TYPE_FIELDS_READONLY (lhstype)))
3924 { 4718 {
3925 readonly_error (lhs, lv_assign); 4719 readonly_error (lhs, lv_assign);
3926 return error_mark_node; 4720 return error_mark_node;
3927 } 4721 }
4722 else if (TREE_READONLY (lhs))
4723 readonly_warning (lhs, lv_assign);
3928 4724
3929 /* If storing into a structure or union member, 4725 /* If storing into a structure or union member,
3930 it has probably been given type `int'. 4726 it has probably been given type `int'.
3931 Compute the type that would go with 4727 Compute the type that would go with
3932 the actual amount of storage the member occupies. */ 4728 the actual amount of storage the member occupies. */
3945 { 4741 {
3946 lhs = copy_node (lhs); 4742 lhs = copy_node (lhs);
3947 TREE_TYPE (lhs) = lhstype; 4743 TREE_TYPE (lhs) = lhstype;
3948 } 4744 }
3949 4745
3950 /* Convert new value to destination type. */ 4746 /* Issue -Wc++-compat warnings about an assignment to an enum type
3951 4747 when LHS does not have its original type. This happens for,
3952 newrhs = convert_for_assignment (lhstype, newrhs, ic_assign, 4748 e.g., an enum bitfield in a struct. */
3953 NULL_TREE, NULL_TREE, 0); 4749 if (warn_cxx_compat
4750 && lhs_origtype != NULL_TREE
4751 && lhs_origtype != lhstype
4752 && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
4753 {
4754 tree checktype = (rhs_origtype != NULL_TREE
4755 ? rhs_origtype
4756 : TREE_TYPE (rhs));
4757 if (checktype != error_mark_node
4758 && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype))
4759 warning_at (location, OPT_Wc___compat,
4760 "enum conversion in assignment is invalid in C++");
4761 }
4762
4763 /* Convert new value to destination type. Fold it first, then
4764 restore any excess precision information, for the sake of
4765 conversion warnings. */
4766
4767 npc = null_pointer_constant_p (newrhs);
4768 newrhs = c_fully_fold (newrhs, false, NULL);
4769 if (rhs_semantic_type)
4770 newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
4771 newrhs = convert_for_assignment (location, lhstype, newrhs, rhs_origtype,
4772 ic_assign, npc, NULL_TREE, NULL_TREE, 0);
3954 if (TREE_CODE (newrhs) == ERROR_MARK) 4773 if (TREE_CODE (newrhs) == ERROR_MARK)
3955 return error_mark_node; 4774 return error_mark_node;
3956 4775
3957 /* Emit ObjC write barrier, if necessary. */ 4776 /* Emit ObjC write barrier, if necessary. */
3958 if (c_dialect_objc () && flag_objc_gc) 4777 if (c_dialect_objc () && flag_objc_gc)
3977 as the LHS argument. */ 4796 as the LHS argument. */
3978 4797
3979 if (olhstype == TREE_TYPE (result)) 4798 if (olhstype == TREE_TYPE (result))
3980 return result; 4799 return result;
3981 4800
3982 result = convert_for_assignment (olhstype, result, ic_assign, 4801 result = convert_for_assignment (location, olhstype, result, rhs_origtype,
3983 NULL_TREE, NULL_TREE, 0); 4802 ic_assign, false, NULL_TREE, NULL_TREE, 0);
3984 protected_set_expr_location (result, location); 4803 protected_set_expr_location (result, location);
3985 return result; 4804 return result;
3986 } 4805 }
3987 4806
3988 /* Convert value RHS to type TYPE as preparation for an assignment 4807 /* Convert value RHS to type TYPE as preparation for an assignment to
3989 to an lvalue of type TYPE. 4808 an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the
4809 original type of RHS; this differs from TREE_TYPE (RHS) for enum
4810 types. NULL_POINTER_CONSTANT says whether RHS was a null pointer
4811 constant before any folding.
3990 The real work of conversion is done by `convert'. 4812 The real work of conversion is done by `convert'.
3991 The purpose of this function is to generate error messages 4813 The purpose of this function is to generate error messages
3992 for assignments that are not allowed in C. 4814 for assignments that are not allowed in C.
3993 ERRTYPE says whether it is argument passing, assignment, 4815 ERRTYPE says whether it is argument passing, assignment,
3994 initialization or return. 4816 initialization or return.
3995 4817
4818 LOCATION is the location of the RHS.
3996 FUNCTION is a tree for the function being called. 4819 FUNCTION is a tree for the function being called.
3997 PARMNUM is the number of the argument, for printing in error messages. */ 4820 PARMNUM is the number of the argument, for printing in error messages. */
3998 4821
3999 static tree 4822 static tree
4000 convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, 4823 convert_for_assignment (location_t location, tree type, tree rhs,
4001 tree fundecl, tree function, int parmnum) 4824 tree origtype, enum impl_conv errtype,
4825 bool null_pointer_constant, tree fundecl,
4826 tree function, int parmnum)
4002 { 4827 {
4003 enum tree_code codel = TREE_CODE (type); 4828 enum tree_code codel = TREE_CODE (type);
4829 tree orig_rhs = rhs;
4004 tree rhstype; 4830 tree rhstype;
4005 enum tree_code coder; 4831 enum tree_code coder;
4006 tree rname = NULL_TREE; 4832 tree rname = NULL_TREE;
4007 bool objc_ok = false; 4833 bool objc_ok = false;
4008 4834
4026 } 4852 }
4027 4853
4028 /* This macro is used to emit diagnostics to ensure that all format 4854 /* This macro is used to emit diagnostics to ensure that all format
4029 strings are complete sentences, visible to gettext and checked at 4855 strings are complete sentences, visible to gettext and checked at
4030 compile time. */ 4856 compile time. */
4031 #define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \ 4857 #define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \
4032 do { \ 4858 do { \
4033 switch (errtype) \ 4859 switch (errtype) \
4034 { \ 4860 { \
4035 case ic_argpass: \ 4861 case ic_argpass: \
4036 if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \ 4862 if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \
4037 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \ 4863 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \
4038 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \ 4864 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \
4039 "expected %qT but argument is of type %qT", \ 4865 "expected %qT but argument is of type %qT", \
4040 type, rhstype); \ 4866 type, rhstype); \
4041 break; \ 4867 break; \
4042 case ic_assign: \ 4868 case ic_assign: \
4043 pedwarn (LOCATION, OPT, AS); \ 4869 pedwarn (LOCATION, OPT, AS); \
4044 break; \ 4870 break; \
4045 case ic_init: \ 4871 case ic_init: \
4046 pedwarn (LOCATION, OPT, IN); \ 4872 pedwarn (LOCATION, OPT, IN); \
4047 break; \ 4873 break; \
4048 case ic_return: \ 4874 case ic_return: \
4049 pedwarn (LOCATION, OPT, RE); \ 4875 pedwarn (LOCATION, OPT, RE); \
4050 break; \ 4876 break; \
4051 default: \ 4877 default: \
4052 gcc_unreachable (); \ 4878 gcc_unreachable (); \
4053 } \ 4879 } \
4054 } while (0) 4880 } while (0)
4055 4881
4056 STRIP_TYPE_NOPS (rhs); 4882 if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
4057 4883 rhs = TREE_OPERAND (rhs, 0);
4058 if (optimize && TREE_CODE (rhs) == VAR_DECL
4059 && TREE_CODE (TREE_TYPE (rhs)) != ARRAY_TYPE)
4060 rhs = decl_constant_value_for_broken_optimization (rhs);
4061 4884
4062 rhstype = TREE_TYPE (rhs); 4885 rhstype = TREE_TYPE (rhs);
4063 coder = TREE_CODE (rhstype); 4886 coder = TREE_CODE (rhstype);
4064 4887
4065 if (coder == ERROR_MARK) 4888 if (coder == ERROR_MARK)
4087 parmno = parmnum; 4910 parmno = parmnum;
4088 break; 4911 break;
4089 } 4912 }
4090 4913
4091 objc_ok = objc_compare_types (type, rhstype, parmno, rname); 4914 objc_ok = objc_compare_types (type, rhstype, parmno, rname);
4915 }
4916
4917 if (warn_cxx_compat)
4918 {
4919 tree checktype = origtype != NULL_TREE ? origtype : rhstype;
4920 if (checktype != error_mark_node
4921 && TREE_CODE (type) == ENUMERAL_TYPE
4922 && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
4923 {
4924 WARN_FOR_ASSIGNMENT (input_location, OPT_Wc___compat,
4925 G_("enum conversion when passing argument "
4926 "%d of %qE is invalid in C++"),
4927 G_("enum conversion in assignment is "
4928 "invalid in C++"),
4929 G_("enum conversion in initialization is "
4930 "invalid in C++"),
4931 G_("enum conversion in return is "
4932 "invalid in C++"));
4933 }
4092 } 4934 }
4093 4935
4094 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)) 4936 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
4095 return rhs; 4937 return rhs;
4096 4938
4099 /* Except for passing an argument to an unprototyped function, 4941 /* Except for passing an argument to an unprototyped function,
4100 this is a constraint violation. When passing an argument to 4942 this is a constraint violation. When passing an argument to
4101 an unprototyped function, it is compile-time undefined; 4943 an unprototyped function, it is compile-time undefined;
4102 making it a constraint in that case was rejected in 4944 making it a constraint in that case was rejected in
4103 DR#252. */ 4945 DR#252. */
4104 error ("void value not ignored as it ought to be"); 4946 error_at (location, "void value not ignored as it ought to be");
4105 return error_mark_node; 4947 return error_mark_node;
4106 } 4948 }
4107 rhs = require_complete_type (rhs); 4949 rhs = require_complete_type (rhs);
4108 if (rhs == error_mark_node) 4950 if (rhs == error_mark_node)
4109 return error_mark_node; 4951 return error_mark_node;
4113 if (codel == REFERENCE_TYPE 4955 if (codel == REFERENCE_TYPE
4114 && comptypes (TREE_TYPE (type), TREE_TYPE (rhs)) == 1) 4956 && comptypes (TREE_TYPE (type), TREE_TYPE (rhs)) == 1)
4115 { 4957 {
4116 if (!lvalue_p (rhs)) 4958 if (!lvalue_p (rhs))
4117 { 4959 {
4118 error ("cannot pass rvalue to reference parameter"); 4960 error_at (location, "cannot pass rvalue to reference parameter");
4119 return error_mark_node; 4961 return error_mark_node;
4120 } 4962 }
4121 if (!c_mark_addressable (rhs)) 4963 if (!c_mark_addressable (rhs))
4122 return error_mark_node; 4964 return error_mark_node;
4123 rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs); 4965 rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs);
4966 SET_EXPR_LOCATION (rhs, location);
4124 4967
4125 /* We already know that these two types are compatible, but they 4968 /* We already know that these two types are compatible, but they
4126 may not be exactly identical. In fact, `TREE_TYPE (type)' is 4969 may not be exactly identical. In fact, `TREE_TYPE (type)' is
4127 likely to be __builtin_va_list and `TREE_TYPE (rhs)' is 4970 likely to be __builtin_va_list and `TREE_TYPE (rhs)' is
4128 likely to be va_list, a typedef to __builtin_va_list, which 4971 likely to be va_list, a typedef to __builtin_va_list, which
4129 is different enough that it will cause problems later. */ 4972 is different enough that it will cause problems later. */
4130 if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type)) 4973 if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type))
4131 rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs); 4974 {
4975 rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs);
4976 SET_EXPR_LOCATION (rhs, location);
4977 }
4132 4978
4133 rhs = build1 (NOP_EXPR, type, rhs); 4979 rhs = build1 (NOP_EXPR, type, rhs);
4980 SET_EXPR_LOCATION (rhs, location);
4134 return rhs; 4981 return rhs;
4135 } 4982 }
4136 /* Some types can interconvert without explicit casts. */ 4983 /* Some types can interconvert without explicit casts. */
4137 else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE 4984 else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
4138 && vector_types_convertible_p (type, TREE_TYPE (rhs), true)) 4985 && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
4144 || codel == BOOLEAN_TYPE) 4991 || codel == BOOLEAN_TYPE)
4145 && (coder == INTEGER_TYPE || coder == REAL_TYPE 4992 && (coder == INTEGER_TYPE || coder == REAL_TYPE
4146 || coder == FIXED_POINT_TYPE 4993 || coder == FIXED_POINT_TYPE
4147 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE 4994 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
4148 || coder == BOOLEAN_TYPE)) 4995 || coder == BOOLEAN_TYPE))
4149 return convert_and_check (type, rhs); 4996 {
4997 tree ret;
4998 bool save = in_late_binary_op;
4999 if (codel == BOOLEAN_TYPE)
5000 in_late_binary_op = true;
5001 ret = convert_and_check (type, orig_rhs);
5002 if (codel == BOOLEAN_TYPE)
5003 in_late_binary_op = save;
5004 return ret;
5005 }
4150 5006
4151 /* Aggregates in different TUs might need conversion. */ 5007 /* Aggregates in different TUs might need conversion. */
4152 if ((codel == RECORD_TYPE || codel == UNION_TYPE) 5008 if ((codel == RECORD_TYPE || codel == UNION_TYPE)
4153 && codel == coder 5009 && codel == coder
4154 && comptypes (type, rhstype)) 5010 && comptypes (type, rhstype))
4180 /* Any non-function converts to a [const][volatile] void * 5036 /* Any non-function converts to a [const][volatile] void *
4181 and vice versa; otherwise, targets must be the same. 5037 and vice versa; otherwise, targets must be the same.
4182 Meanwhile, the lhs target must have all the qualifiers of 5038 Meanwhile, the lhs target must have all the qualifiers of
4183 the rhs. */ 5039 the rhs. */
4184 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) 5040 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
4185 || comp_target_types (memb_type, rhstype)) 5041 || comp_target_types (location, memb_type, rhstype))
4186 { 5042 {
4187 /* If this type won't generate any warnings, use it. */ 5043 /* If this type won't generate any warnings, use it. */
4188 if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr) 5044 if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
4189 || ((TREE_CODE (ttr) == FUNCTION_TYPE 5045 || ((TREE_CODE (ttr) == FUNCTION_TYPE
4190 && TREE_CODE (ttl) == FUNCTION_TYPE) 5046 && TREE_CODE (ttl) == FUNCTION_TYPE)
4199 marginal_memb = memb; 5055 marginal_memb = memb;
4200 } 5056 }
4201 } 5057 }
4202 5058
4203 /* Can convert integer zero to any pointer type. */ 5059 /* Can convert integer zero to any pointer type. */
4204 if (null_pointer_constant_p (rhs)) 5060 if (null_pointer_constant)
4205 { 5061 {
4206 rhs = null_pointer_node; 5062 rhs = null_pointer_node;
4207 break; 5063 break;
4208 } 5064 }
4209 } 5065 }
4225 /* Because const and volatile on functions are 5081 /* Because const and volatile on functions are
4226 restrictions that say the function will not do 5082 restrictions that say the function will not do
4227 certain things, it is okay to use a const or volatile 5083 certain things, it is okay to use a const or volatile
4228 function where an ordinary one is wanted, but not 5084 function where an ordinary one is wanted, but not
4229 vice-versa. */ 5085 vice-versa. */
4230 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr)) 5086 if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
4231 WARN_FOR_ASSIGNMENT (input_location, 0, 5087 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
5088 WARN_FOR_ASSIGNMENT (location, 0,
4232 G_("passing argument %d of %qE " 5089 G_("passing argument %d of %qE "
4233 "makes qualified function " 5090 "makes qualified function "
4234 "pointer from unqualified"), 5091 "pointer from unqualified"),
4235 G_("assignment makes qualified " 5092 G_("assignment makes qualified "
4236 "function pointer from " 5093 "function pointer from "
4239 "function pointer from " 5096 "function pointer from "
4240 "unqualified"), 5097 "unqualified"),
4241 G_("return makes qualified function " 5098 G_("return makes qualified function "
4242 "pointer from unqualified")); 5099 "pointer from unqualified"));
4243 } 5100 }
4244 else if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl)) 5101 else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
4245 WARN_FOR_ASSIGNMENT (input_location, 0, 5102 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
5103 WARN_FOR_ASSIGNMENT (location, 0,
4246 G_("passing argument %d of %qE discards " 5104 G_("passing argument %d of %qE discards "
4247 "qualifiers from pointer target type"), 5105 "qualifiers from pointer target type"),
4248 G_("assignment discards qualifiers " 5106 G_("assignment discards qualifiers "
4249 "from pointer target type"), 5107 "from pointer target type"),
4250 G_("initialization discards qualifiers " 5108 G_("initialization discards qualifiers "
4254 5112
4255 memb = marginal_memb; 5113 memb = marginal_memb;
4256 } 5114 }
4257 5115
4258 if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)) 5116 if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
4259 pedwarn (input_location, OPT_pedantic, 5117 pedwarn (location, OPT_pedantic,
4260 "ISO C prohibits argument conversion to union type"); 5118 "ISO C prohibits argument conversion to union type");
4261 5119
4262 rhs = fold_convert (TREE_TYPE (memb), rhs); 5120 rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
4263 return build_constructor_single (type, memb, rhs); 5121 return build_constructor_single (type, memb, rhs);
4264 } 5122 }
4265 } 5123 }
4266 5124
4267 /* Conversions among pointers */ 5125 /* Conversions among pointers */
4272 tree ttr = TREE_TYPE (rhstype); 5130 tree ttr = TREE_TYPE (rhstype);
4273 tree mvl = ttl; 5131 tree mvl = ttl;
4274 tree mvr = ttr; 5132 tree mvr = ttr;
4275 bool is_opaque_pointer; 5133 bool is_opaque_pointer;
4276 int target_cmp = 0; /* Cache comp_target_types () result. */ 5134 int target_cmp = 0; /* Cache comp_target_types () result. */
5135 addr_space_t asl;
5136 addr_space_t asr;
4277 5137
4278 if (TREE_CODE (mvl) != ARRAY_TYPE) 5138 if (TREE_CODE (mvl) != ARRAY_TYPE)
4279 mvl = TYPE_MAIN_VARIANT (mvl); 5139 mvl = TYPE_MAIN_VARIANT (mvl);
4280 if (TREE_CODE (mvr) != ARRAY_TYPE) 5140 if (TREE_CODE (mvr) != ARRAY_TYPE)
4281 mvr = TYPE_MAIN_VARIANT (mvr); 5141 mvr = TYPE_MAIN_VARIANT (mvr);
4288 5148
4289 int *p = NULL; 5149 int *p = NULL;
4290 5150
4291 where NULL is typically defined in C to be '(void *) 0'. */ 5151 where NULL is typically defined in C to be '(void *) 0'. */
4292 if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl)) 5152 if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
4293 warning (OPT_Wc___compat, "request for implicit conversion from " 5153 warning_at (location, OPT_Wc___compat,
4294 "%qT to %qT not permitted in C++", rhstype, type); 5154 "request for implicit conversion "
5155 "from %qT to %qT not permitted in C++", rhstype, type);
5156
5157 /* See if the pointers point to incompatible address spaces. */
5158 asl = TYPE_ADDR_SPACE (ttl);
5159 asr = TYPE_ADDR_SPACE (ttr);
5160 if (!null_pointer_constant_p (rhs)
5161 && asr != asl && !targetm.addr_space.subset_p (asr, asl))
5162 {
5163 switch (errtype)
5164 {
5165 case ic_argpass:
5166 error_at (location, "passing argument %d of %qE from pointer to "
5167 "non-enclosed address space", parmnum, rname);
5168 break;
5169 case ic_assign:
5170 error_at (location, "assignment from pointer to "
5171 "non-enclosed address space");
5172 break;
5173 case ic_init:
5174 error_at (location, "initialization from pointer to "
5175 "non-enclosed address space");
5176 break;
5177 case ic_return:
5178 error_at (location, "return from pointer to "
5179 "non-enclosed address space");
5180 break;
5181 default:
5182 gcc_unreachable ();
5183 }
5184 return error_mark_node;
5185 }
4295 5186
4296 /* Check if the right-hand side has a format attribute but the 5187 /* Check if the right-hand side has a format attribute but the
4297 left-hand side doesn't. */ 5188 left-hand side doesn't. */
4298 if (warn_missing_format_attribute 5189 if (warn_missing_format_attribute
4299 && check_missing_format_attribute (type, rhstype)) 5190 && check_missing_format_attribute (type, rhstype))
4300 { 5191 {
4301 switch (errtype) 5192 switch (errtype)
4302 { 5193 {
4303 case ic_argpass: 5194 case ic_argpass:
4304 warning (OPT_Wmissing_format_attribute, 5195 warning_at (location, OPT_Wmissing_format_attribute,
4305 "argument %d of %qE might be " 5196 "argument %d of %qE might be "
4306 "a candidate for a format attribute", 5197 "a candidate for a format attribute",
4307 parmnum, rname); 5198 parmnum, rname);
4308 break; 5199 break;
4309 case ic_assign: 5200 case ic_assign:
4310 warning (OPT_Wmissing_format_attribute, 5201 warning_at (location, OPT_Wmissing_format_attribute,
4311 "assignment left-hand side might be " 5202 "assignment left-hand side might be "
4312 "a candidate for a format attribute"); 5203 "a candidate for a format attribute");
4313 break; 5204 break;
4314 case ic_init: 5205 case ic_init:
4315 warning (OPT_Wmissing_format_attribute, 5206 warning_at (location, OPT_Wmissing_format_attribute,
4316 "initialization left-hand side might be " 5207 "initialization left-hand side might be "
4317 "a candidate for a format attribute"); 5208 "a candidate for a format attribute");
4318 break; 5209 break;
4319 case ic_return: 5210 case ic_return:
4320 warning (OPT_Wmissing_format_attribute, 5211 warning_at (location, OPT_Wmissing_format_attribute,
4321 "return type might be " 5212 "return type might be "
4322 "a candidate for a format attribute"); 5213 "a candidate for a format attribute");
4323 break; 5214 break;
4324 default: 5215 default:
4325 gcc_unreachable (); 5216 gcc_unreachable ();
4326 } 5217 }
4327 } 5218 }
4328 5219
4329 /* Any non-function converts to a [const][volatile] void * 5220 /* Any non-function converts to a [const][volatile] void *
4330 and vice versa; otherwise, targets must be the same. 5221 and vice versa; otherwise, targets must be the same.
4331 Meanwhile, the lhs target must have all the qualifiers of the rhs. */ 5222 Meanwhile, the lhs target must have all the qualifiers of the rhs. */
4332 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) 5223 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
4333 || (target_cmp = comp_target_types (type, rhstype)) 5224 || (target_cmp = comp_target_types (location, type, rhstype))
4334 || is_opaque_pointer 5225 || is_opaque_pointer
4335 || (c_common_unsigned_type (mvl) 5226 || (c_common_unsigned_type (mvl)
4336 == c_common_unsigned_type (mvr))) 5227 == c_common_unsigned_type (mvr)))
4337 { 5228 {
4338 if (pedantic 5229 if (pedantic
4339 && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE) 5230 && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
4340 || 5231 ||
4341 (VOID_TYPE_P (ttr) 5232 (VOID_TYPE_P (ttr)
4342 && !null_pointer_constant_p (rhs) 5233 && !null_pointer_constant
4343 && TREE_CODE (ttl) == FUNCTION_TYPE))) 5234 && TREE_CODE (ttl) == FUNCTION_TYPE)))
4344 WARN_FOR_ASSIGNMENT (input_location, OPT_pedantic, 5235 WARN_FOR_ASSIGNMENT (location, OPT_pedantic,
4345 G_("ISO C forbids passing argument %d of " 5236 G_("ISO C forbids passing argument %d of "
4346 "%qE between function pointer " 5237 "%qE between function pointer "
4347 "and %<void *%>"), 5238 "and %<void *%>"),
4348 G_("ISO C forbids assignment between " 5239 G_("ISO C forbids assignment between "
4349 "function pointer and %<void *%>"), 5240 "function pointer and %<void *%>"),
4354 /* Const and volatile mean something different for function types, 5245 /* Const and volatile mean something different for function types,
4355 so the usual warnings are not appropriate. */ 5246 so the usual warnings are not appropriate. */
4356 else if (TREE_CODE (ttr) != FUNCTION_TYPE 5247 else if (TREE_CODE (ttr) != FUNCTION_TYPE
4357 && TREE_CODE (ttl) != FUNCTION_TYPE) 5248 && TREE_CODE (ttl) != FUNCTION_TYPE)
4358 { 5249 {
4359 if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl)) 5250 if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
5251 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
4360 { 5252 {
4361 /* Types differing only by the presence of the 'volatile' 5253 /* Types differing only by the presence of the 'volatile'
4362 qualifier are acceptable if the 'volatile' has been added 5254 qualifier are acceptable if the 'volatile' has been added
4363 in by the Objective-C EH machinery. */ 5255 in by the Objective-C EH machinery. */
4364 if (!objc_type_quals_match (ttl, ttr)) 5256 if (!objc_type_quals_match (ttl, ttr))
4365 WARN_FOR_ASSIGNMENT (input_location, 0, 5257 WARN_FOR_ASSIGNMENT (location, 0,
4366 G_("passing argument %d of %qE discards " 5258 G_("passing argument %d of %qE discards "
4367 "qualifiers from pointer target type"), 5259 "qualifiers from pointer target type"),
4368 G_("assignment discards qualifiers " 5260 G_("assignment discards qualifiers "
4369 "from pointer target type"), 5261 "from pointer target type"),
4370 G_("initialization discards qualifiers " 5262 G_("initialization discards qualifiers "
4377 else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) 5269 else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
4378 || target_cmp) 5270 || target_cmp)
4379 ; 5271 ;
4380 /* If there is a mismatch, do warn. */ 5272 /* If there is a mismatch, do warn. */
4381 else if (warn_pointer_sign) 5273 else if (warn_pointer_sign)
4382 WARN_FOR_ASSIGNMENT (input_location, OPT_Wpointer_sign, 5274 WARN_FOR_ASSIGNMENT (location, OPT_Wpointer_sign,
4383 G_("pointer targets in passing argument " 5275 G_("pointer targets in passing argument "
4384 "%d of %qE differ in signedness"), 5276 "%d of %qE differ in signedness"),
4385 G_("pointer targets in assignment " 5277 G_("pointer targets in assignment "
4386 "differ in signedness"), 5278 "differ in signedness"),
4387 G_("pointer targets in initialization " 5279 G_("pointer targets in initialization "
4394 { 5286 {
4395 /* Because const and volatile on functions are restrictions 5287 /* Because const and volatile on functions are restrictions
4396 that say the function will not do certain things, 5288 that say the function will not do certain things,
4397 it is okay to use a const or volatile function 5289 it is okay to use a const or volatile function
4398 where an ordinary one is wanted, but not vice-versa. */ 5290 where an ordinary one is wanted, but not vice-versa. */
4399 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr)) 5291 if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
4400 WARN_FOR_ASSIGNMENT (input_location, 0, 5292 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
5293 WARN_FOR_ASSIGNMENT (location, 0,
4401 G_("passing argument %d of %qE makes " 5294 G_("passing argument %d of %qE makes "
4402 "qualified function pointer " 5295 "qualified function pointer "
4403 "from unqualified"), 5296 "from unqualified"),
4404 G_("assignment makes qualified function " 5297 G_("assignment makes qualified function "
4405 "pointer from unqualified"), 5298 "pointer from unqualified"),
4410 } 5303 }
4411 } 5304 }
4412 else 5305 else
4413 /* Avoid warning about the volatile ObjC EH puts on decls. */ 5306 /* Avoid warning about the volatile ObjC EH puts on decls. */
4414 if (!objc_ok) 5307 if (!objc_ok)
4415 WARN_FOR_ASSIGNMENT (input_location, 0, 5308 WARN_FOR_ASSIGNMENT (location, 0,
4416 G_("passing argument %d of %qE from " 5309 G_("passing argument %d of %qE from "
4417 "incompatible pointer type"), 5310 "incompatible pointer type"),
4418 G_("assignment from incompatible pointer type"), 5311 G_("assignment from incompatible pointer type"),
4419 G_("initialization from incompatible " 5312 G_("initialization from incompatible "
4420 "pointer type"), 5313 "pointer type"),
4424 } 5317 }
4425 else if (codel == POINTER_TYPE && coder == ARRAY_TYPE) 5318 else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
4426 { 5319 {
4427 /* ??? This should not be an error when inlining calls to 5320 /* ??? This should not be an error when inlining calls to
4428 unprototyped functions. */ 5321 unprototyped functions. */
4429 error ("invalid use of non-lvalue array"); 5322 error_at (location, "invalid use of non-lvalue array");
4430 return error_mark_node; 5323 return error_mark_node;
4431 } 5324 }
4432 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE) 5325 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
4433 { 5326 {
4434 /* An explicit constant 0 can convert to a pointer, 5327 /* An explicit constant 0 can convert to a pointer,
4435 or one that results from arithmetic, even including 5328 or one that results from arithmetic, even including
4436 a cast to integer type. */ 5329 a cast to integer type. */
4437 if (!null_pointer_constant_p (rhs)) 5330 if (!null_pointer_constant)
4438 WARN_FOR_ASSIGNMENT (input_location, 0, 5331 WARN_FOR_ASSIGNMENT (location, 0,
4439 G_("passing argument %d of %qE makes " 5332 G_("passing argument %d of %qE makes "
4440 "pointer from integer without a cast"), 5333 "pointer from integer without a cast"),
4441 G_("assignment makes pointer from integer " 5334 G_("assignment makes pointer from integer "
4442 "without a cast"), 5335 "without a cast"),
4443 G_("initialization makes pointer from " 5336 G_("initialization makes pointer from "
4447 5340
4448 return convert (type, rhs); 5341 return convert (type, rhs);
4449 } 5342 }
4450 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE) 5343 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
4451 { 5344 {
4452 WARN_FOR_ASSIGNMENT (input_location, 0, 5345 WARN_FOR_ASSIGNMENT (location, 0,
4453 G_("passing argument %d of %qE makes integer " 5346 G_("passing argument %d of %qE makes integer "
4454 "from pointer without a cast"), 5347 "from pointer without a cast"),
4455 G_("assignment makes integer from pointer " 5348 G_("assignment makes integer from pointer "
4456 "without a cast"), 5349 "without a cast"),
4457 G_("initialization makes integer from pointer " 5350 G_("initialization makes integer from pointer "
4459 G_("return makes integer from pointer " 5352 G_("return makes integer from pointer "
4460 "without a cast")); 5353 "without a cast"));
4461 return convert (type, rhs); 5354 return convert (type, rhs);
4462 } 5355 }
4463 else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE) 5356 else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE)
4464 return convert (type, rhs); 5357 {
5358 tree ret;
5359 bool save = in_late_binary_op;
5360 in_late_binary_op = true;
5361 ret = convert (type, rhs);
5362 in_late_binary_op = save;
5363 return ret;
5364 }
4465 5365
4466 switch (errtype) 5366 switch (errtype)
4467 { 5367 {
4468 case ic_argpass: 5368 case ic_argpass:
4469 error ("incompatible type for argument %d of %qE", parmnum, rname); 5369 error_at (location, "incompatible type for argument %d of %qE", parmnum, rname);
4470 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) 5370 inform ((fundecl && !DECL_IS_BUILTIN (fundecl))
4471 ? DECL_SOURCE_LOCATION (fundecl) : input_location, 5371 ? DECL_SOURCE_LOCATION (fundecl) : input_location,
4472 "expected %qT but argument is of type %qT", type, rhstype); 5372 "expected %qT but argument is of type %qT", type, rhstype);
4473 break; 5373 break;
4474 case ic_assign: 5374 case ic_assign:
4475 error ("incompatible types when assigning to type %qT from type %qT", 5375 error_at (location, "incompatible types when assigning to type %qT from "
4476 type, rhstype); 5376 "type %qT", type, rhstype);
4477 break; 5377 break;
4478 case ic_init: 5378 case ic_init:
4479 error ("incompatible types when initializing type %qT using type %qT", 5379 error_at (location,
4480 type, rhstype); 5380 "incompatible types when initializing type %qT using type %qT",
5381 type, rhstype);
4481 break; 5382 break;
4482 case ic_return: 5383 case ic_return:
4483 error ("incompatible types when returning type %qT but %qT was expected", 5384 error_at (location,
4484 rhstype, type); 5385 "incompatible types when returning type %qT but %qT was "
5386 "expected", rhstype, type);
4485 break; 5387 break;
4486 default: 5388 default:
4487 gcc_unreachable (); 5389 gcc_unreachable ();
4488 } 5390 }
4489 5391
4514 } 5416 }
4515 5417
4516 /* Perform appropriate conversions on the initial value of a variable, 5418 /* Perform appropriate conversions on the initial value of a variable,
4517 store it in the declaration DECL, 5419 store it in the declaration DECL,
4518 and print any error messages that are appropriate. 5420 and print any error messages that are appropriate.
4519 If the init is invalid, store an ERROR_MARK. */ 5421 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
5422 If the init is invalid, store an ERROR_MARK.
5423
5424 INIT_LOC is the location of the initial value. */
4520 5425
4521 void 5426 void
4522 store_init_value (tree decl, tree init) 5427 store_init_value (location_t init_loc, tree decl, tree init, tree origtype)
4523 { 5428 {
4524 tree value, type; 5429 tree value, type;
5430 bool npc = false;
4525 5431
4526 /* If variable's type was invalidly declared, just ignore it. */ 5432 /* If variable's type was invalidly declared, just ignore it. */
4527 5433
4528 type = TREE_TYPE (decl); 5434 type = TREE_TYPE (decl);
4529 if (TREE_CODE (type) == ERROR_MARK) 5435 if (TREE_CODE (type) == ERROR_MARK)
4530 return; 5436 return;
4531 5437
4532 /* Digest the specified initializer into an expression. */ 5438 /* Digest the specified initializer into an expression. */
4533 5439
4534 value = digest_init (type, init, true, TREE_STATIC (decl)); 5440 if (init)
5441 npc = null_pointer_constant_p (init);
5442 value = digest_init (init_loc, type, init, origtype, npc,
5443 true, TREE_STATIC (decl));
4535 5444
4536 /* Store the expression if valid; else report error. */ 5445 /* Store the expression if valid; else report error. */
4537 5446
4538 if (!in_system_header 5447 if (!in_system_header
4539 && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl)) 5448 && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
4542 5451
4543 DECL_INITIAL (decl) = value; 5452 DECL_INITIAL (decl) = value;
4544 5453
4545 /* ANSI wants warnings about out-of-range constant initializers. */ 5454 /* ANSI wants warnings about out-of-range constant initializers. */
4546 STRIP_TYPE_NOPS (value); 5455 STRIP_TYPE_NOPS (value);
4547 if (TREE_STATIC (decl)) 5456 if (TREE_STATIC (decl))
4548 constant_expression_warning (value); 5457 constant_expression_warning (value);
4549 5458
4550 /* Check if we need to set array size from compound literal size. */ 5459 /* Check if we need to set array size from compound literal size. */
4551 if (TREE_CODE (type) == ARRAY_TYPE 5460 if (TREE_CODE (type) == ARRAY_TYPE
4552 && TYPE_DOMAIN (type) == 0 5461 && TYPE_DOMAIN (type) == 0
4637 5546
4638 static void 5547 static void
4639 push_member_name (tree decl) 5548 push_member_name (tree decl)
4640 { 5549 {
4641 const char *const string 5550 const char *const string
4642 = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>"; 5551 = (DECL_NAME (decl)
5552 ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))
5553 : _("<anonymous>"));
4643 PUSH_SPELLING (SPELLING_MEMBER, string, u.s); 5554 PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
4644 } 5555 }
4645 5556
4646 /* Push an array bounds on the stack. Printed as [BOUNDS]. */ 5557 /* Push an array bounds on the stack. Printed as [BOUNDS]. */
4647 5558
4725 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); 5636 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4726 if (*ofwhat) 5637 if (*ofwhat)
4727 pedwarn (location, opt, "(near initialization for %qs)", ofwhat); 5638 pedwarn (location, opt, "(near initialization for %qs)", ofwhat);
4728 } 5639 }
4729 5640
4730 /* Issue a warning for a bad initializer component. 5641 /* Issue a warning for a bad initializer component.
4731 5642
4732 OPT is the OPT_W* value corresponding to the warning option that 5643 OPT is the OPT_W* value corresponding to the warning option that
4733 controls this warning. MSGID identifies the message. The 5644 controls this warning. MSGID identifies the message. The
4734 component name is taken from the spelling stack. */ 5645 component name is taken from the spelling stack. */
4735 5646
4753 { 5664 {
4754 if (pedantic 5665 if (pedantic
4755 && TREE_CODE (type) == ARRAY_TYPE 5666 && TREE_CODE (type) == ARRAY_TYPE
4756 && TREE_CODE (expr.value) == STRING_CST 5667 && TREE_CODE (expr.value) == STRING_CST
4757 && expr.original_code != STRING_CST) 5668 && expr.original_code != STRING_CST)
4758 pedwarn_init (input_location, OPT_pedantic, 5669 pedwarn_init (input_location, OPT_pedantic,
4759 "array initialized from parenthesized string constant"); 5670 "array initialized from parenthesized string constant");
4760 } 5671 }
4761 5672
4762 /* Digest the parser output INIT as an initializer for type TYPE. 5673 /* Digest the parser output INIT as an initializer for type TYPE.
4763 Return a C expression of type TYPE to represent the initial value. 5674 Return a C expression of type TYPE to represent the initial value.
5675
5676 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
5677
5678 NULL_POINTER_CONSTANT is true if INIT is a null pointer constant.
4764 5679
4765 If INIT is a string constant, STRICT_STRING is true if it is 5680 If INIT is a string constant, STRICT_STRING is true if it is
4766 unparenthesized or we should not warn here for it being parenthesized. 5681 unparenthesized or we should not warn here for it being parenthesized.
4767 For other types of INIT, STRICT_STRING is not used. 5682 For other types of INIT, STRICT_STRING is not used.
4768 5683
5684 INIT_LOC is the location of the INIT.
5685
4769 REQUIRE_CONSTANT requests an error if non-constant initializers or 5686 REQUIRE_CONSTANT requests an error if non-constant initializers or
4770 elements are seen. */ 5687 elements are seen. */
4771 5688
4772 static tree 5689 static tree
4773 digest_init (tree type, tree init, bool strict_string, int require_constant) 5690 digest_init (location_t init_loc, tree type, tree init, tree origtype,
5691 bool null_pointer_constant, bool strict_string,
5692 int require_constant)
4774 { 5693 {
4775 enum tree_code code = TREE_CODE (type); 5694 enum tree_code code = TREE_CODE (type);
4776 tree inside_init = init; 5695 tree inside_init = init;
5696 tree semantic_type = NULL_TREE;
5697 bool maybe_const = true;
4777 5698
4778 if (type == error_mark_node 5699 if (type == error_mark_node
4779 || !init 5700 || !init
4780 || init == error_mark_node 5701 || init == error_mark_node
4781 || TREE_TYPE (init) == error_mark_node) 5702 || TREE_TYPE (init) == error_mark_node)
4782 return error_mark_node; 5703 return error_mark_node;
4783 5704
4784 STRIP_TYPE_NOPS (inside_init); 5705 STRIP_TYPE_NOPS (inside_init);
4785 5706
4786 inside_init = fold (inside_init); 5707 if (TREE_CODE (inside_init) == EXCESS_PRECISION_EXPR)
5708 {
5709 semantic_type = TREE_TYPE (inside_init);
5710 inside_init = TREE_OPERAND (inside_init, 0);
5711 }
5712 inside_init = c_fully_fold (inside_init, require_constant, &maybe_const);
5713 inside_init = decl_constant_value_for_optimization (inside_init);
4787 5714
4788 /* Initialization of an array of chars from a string constant 5715 /* Initialization of an array of chars from a string constant
4789 optionally enclosed in braces. */ 5716 optionally enclosed in braces. */
4790 5717
4791 if (code == ARRAY_TYPE && inside_init 5718 if (code == ARRAY_TYPE && inside_init
4806 { 5733 {
4807 struct c_expr expr; 5734 struct c_expr expr;
4808 tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init))); 5735 tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
4809 expr.value = inside_init; 5736 expr.value = inside_init;
4810 expr.original_code = (strict_string ? STRING_CST : ERROR_MARK); 5737 expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
5738 expr.original_type = NULL;
4811 maybe_warn_string_init (type, expr); 5739 maybe_warn_string_init (type, expr);
5740
5741 if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
5742 pedwarn_init (init_loc, OPT_pedantic,
5743 "initialization of a flexible array member");
4812 5744
4813 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), 5745 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4814 TYPE_MAIN_VARIANT (type))) 5746 TYPE_MAIN_VARIANT (type)))
4815 return inside_init; 5747 return inside_init;
4816 5748
4839 } 5771 }
4840 5772
4841 TREE_TYPE (inside_init) = type; 5773 TREE_TYPE (inside_init) = type;
4842 if (TYPE_DOMAIN (type) != 0 5774 if (TYPE_DOMAIN (type) != 0
4843 && TYPE_SIZE (type) != 0 5775 && TYPE_SIZE (type) != 0
4844 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST 5776 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
5777 {
5778 unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
5779
4845 /* Subtract the size of a single (possibly wide) character 5780 /* Subtract the size of a single (possibly wide) character
4846 because it's ok to ignore the terminating null char 5781 because it's ok to ignore the terminating null char
4847 that is counted in the length of the constant. */ 5782 that is counted in the length of the constant. */
4848 && 0 > compare_tree_int (TYPE_SIZE_UNIT (type), 5783 if (0 > compare_tree_int (TYPE_SIZE_UNIT (type),
4849 TREE_STRING_LENGTH (inside_init) 5784 (len
4850 - (TYPE_PRECISION (typ1) 5785 - (TYPE_PRECISION (typ1)
4851 / BITS_PER_UNIT))) 5786 / BITS_PER_UNIT))))
4852 pedwarn_init (input_location, 0, 5787 pedwarn_init (init_loc, 0,
4853 "initializer-string for array of chars is too long"); 5788 ("initializer-string for array of chars "
5789 "is too long"));
5790 else if (warn_cxx_compat
5791 && 0 > compare_tree_int (TYPE_SIZE_UNIT (type), len))
5792 warning_at (init_loc, OPT_Wc___compat,
5793 ("initializer-string for array chars "
5794 "is too long for C++"));
5795 }
4854 5796
4855 return inside_init; 5797 return inside_init;
4856 } 5798 }
4857 else if (INTEGRAL_TYPE_P (typ1)) 5799 else if (INTEGRAL_TYPE_P (typ1))
4858 { 5800 {
4918 { 5860 {
4919 if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE) 5861 if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
4920 { 5862 {
4921 if (TREE_CODE (inside_init) == STRING_CST 5863 if (TREE_CODE (inside_init) == STRING_CST
4922 || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) 5864 || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
4923 inside_init = array_to_pointer_conversion (inside_init); 5865 inside_init = array_to_pointer_conversion
5866 (init_loc, inside_init);
4924 else 5867 else
4925 { 5868 {
4926 error_init ("invalid use of non-lvalue array"); 5869 error_init ("invalid use of non-lvalue array");
4927 return error_mark_node; 5870 return error_mark_node;
4928 } 5871 }
4951 { 5894 {
4952 error_init ("array initialized from non-constant array expression"); 5895 error_init ("array initialized from non-constant array expression");
4953 return error_mark_node; 5896 return error_mark_node;
4954 } 5897 }
4955 5898
4956 if (optimize && TREE_CODE (inside_init) == VAR_DECL)
4957 inside_init = decl_constant_value_for_broken_optimization (inside_init);
4958
4959 /* Compound expressions can only occur here if -pedantic or 5899 /* Compound expressions can only occur here if -pedantic or
4960 -pedantic-errors is specified. In the later case, we always want 5900 -pedantic-errors is specified. In the later case, we always want
4961 an error. In the former case, we simply want a warning. */ 5901 an error. In the former case, we simply want a warning. */
4962 if (require_constant && pedantic 5902 if (require_constant && pedantic
4963 && TREE_CODE (inside_init) == COMPOUND_EXPR) 5903 && TREE_CODE (inside_init) == COMPOUND_EXPR)
4966 = valid_compound_expr_initializer (inside_init, 5906 = valid_compound_expr_initializer (inside_init,
4967 TREE_TYPE (inside_init)); 5907 TREE_TYPE (inside_init));
4968 if (inside_init == error_mark_node) 5908 if (inside_init == error_mark_node)
4969 error_init ("initializer element is not constant"); 5909 error_init ("initializer element is not constant");
4970 else 5910 else
4971 pedwarn_init (input_location, OPT_pedantic, 5911 pedwarn_init (init_loc, OPT_pedantic,
4972 "initializer element is not constant"); 5912 "initializer element is not constant");
4973 if (flag_pedantic_errors) 5913 if (flag_pedantic_errors)
4974 inside_init = error_mark_node; 5914 inside_init = error_mark_node;
4975 } 5915 }
4976 else if (require_constant 5916 else if (require_constant
4978 TREE_TYPE (inside_init))) 5918 TREE_TYPE (inside_init)))
4979 { 5919 {
4980 error_init ("initializer element is not constant"); 5920 error_init ("initializer element is not constant");
4981 inside_init = error_mark_node; 5921 inside_init = error_mark_node;
4982 } 5922 }
5923 else if (require_constant && !maybe_const)
5924 pedwarn_init (init_loc, 0,
5925 "initializer element is not a constant expression");
4983 5926
4984 /* Added to enable additional -Wmissing-format-attribute warnings. */ 5927 /* Added to enable additional -Wmissing-format-attribute warnings. */
4985 if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE) 5928 if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
4986 inside_init = convert_for_assignment (type, inside_init, ic_init, NULL_TREE, 5929 inside_init = convert_for_assignment (init_loc, type, inside_init,
4987 NULL_TREE, 0); 5930 origtype,
5931 ic_init, null_pointer_constant,
5932 NULL_TREE, NULL_TREE, 0);
4988 return inside_init; 5933 return inside_init;
4989 } 5934 }
4990 5935
4991 /* Handle scalar types, including conversions. */ 5936 /* Handle scalar types, including conversions. */
4992 5937
4995 || code == COMPLEX_TYPE || code == VECTOR_TYPE) 5940 || code == COMPLEX_TYPE || code == VECTOR_TYPE)
4996 { 5941 {
4997 if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE 5942 if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
4998 && (TREE_CODE (init) == STRING_CST 5943 && (TREE_CODE (init) == STRING_CST
4999 || TREE_CODE (init) == COMPOUND_LITERAL_EXPR)) 5944 || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
5000 init = array_to_pointer_conversion (init); 5945 inside_init = init = array_to_pointer_conversion (init_loc, init);
5946 if (semantic_type)
5947 inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type,
5948 inside_init);
5001 inside_init 5949 inside_init
5002 = convert_for_assignment (type, init, ic_init, 5950 = convert_for_assignment (init_loc, type, inside_init, origtype,
5951 ic_init, null_pointer_constant,
5003 NULL_TREE, NULL_TREE, 0); 5952 NULL_TREE, NULL_TREE, 0);
5004 5953
5005 /* Check to see if we have already given an error message. */ 5954 /* Check to see if we have already given an error message. */
5006 if (inside_init == error_mark_node) 5955 if (inside_init == error_mark_node)
5007 ; 5956 ;
5015 TREE_TYPE (inside_init))) 5964 TREE_TYPE (inside_init)))
5016 { 5965 {
5017 error_init ("initializer element is not computable at load time"); 5966 error_init ("initializer element is not computable at load time");
5018 inside_init = error_mark_node; 5967 inside_init = error_mark_node;
5019 } 5968 }
5969 else if (require_constant && !maybe_const)
5970 pedwarn_init (init_loc, 0,
5971 "initializer element is not a constant expression");
5020 5972
5021 return inside_init; 5973 return inside_init;
5022 } 5974 }
5023 5975
5024 /* Come here only for records and arrays. */ 5976 /* Come here only for records and arrays. */
5073 /* 1 if so far this constructor's elements are all compile-time constants. */ 6025 /* 1 if so far this constructor's elements are all compile-time constants. */
5074 static int constructor_constant; 6026 static int constructor_constant;
5075 6027
5076 /* 1 if so far this constructor's elements are all valid address constants. */ 6028 /* 1 if so far this constructor's elements are all valid address constants. */
5077 static int constructor_simple; 6029 static int constructor_simple;
6030
6031 /* 1 if this constructor has an element that cannot be part of a
6032 constant expression. */
6033 static int constructor_nonconst;
5078 6034
5079 /* 1 if this constructor is erroneous so far. */ 6035 /* 1 if this constructor is erroneous so far. */
5080 static int constructor_erroneous; 6036 static int constructor_erroneous;
5081 6037
5082 /* Structure for managing pending initializer elements, organized as an 6038 /* Structure for managing pending initializer elements, organized as an
5087 struct init_node *left, *right; 6043 struct init_node *left, *right;
5088 struct init_node *parent; 6044 struct init_node *parent;
5089 int balance; 6045 int balance;
5090 tree purpose; 6046 tree purpose;
5091 tree value; 6047 tree value;
6048 tree origtype;
5092 }; 6049 };
5093 6050
5094 /* Tree of pending elements at this constructor level. 6051 /* Tree of pending elements at this constructor level.
5095 These are elements encountered out of order 6052 These are elements encountered out of order
5096 which belong at places we haven't reached yet in actually 6053 which belong at places we haven't reached yet in actually
5143 constructor at this level. */ 6100 constructor at this level. */
5144 struct c_expr replacement_value; 6101 struct c_expr replacement_value;
5145 struct constructor_range_stack *range_stack; 6102 struct constructor_range_stack *range_stack;
5146 char constant; 6103 char constant;
5147 char simple; 6104 char simple;
6105 char nonconst;
5148 char implicit; 6106 char implicit;
5149 char erroneous; 6107 char erroneous;
5150 char outer; 6108 char outer;
5151 char incremental; 6109 char incremental;
5152 char designated; 6110 char designated;
5224 even within braces. */ 6182 even within braces. */
5225 && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE 6183 && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
5226 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE 6184 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
5227 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE 6185 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
5228 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE)); 6186 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
5229 locus = IDENTIFIER_POINTER (DECL_NAME (decl)); 6187 locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)));
5230 } 6188 }
5231 else 6189 else
5232 { 6190 {
5233 require_constant_value = 0; 6191 require_constant_value = 0;
5234 require_constant_elements = 0; 6192 require_constant_elements = 0;
5235 locus = "(anonymous)"; 6193 locus = _("(anonymous)");
5236 } 6194 }
5237 6195
5238 constructor_stack = 0; 6196 constructor_stack = 0;
5239 constructor_range_stack = 0; 6197 constructor_range_stack = 0;
5240 6198
5293 struct constructor_stack *p = XNEW (struct constructor_stack); 6251 struct constructor_stack *p = XNEW (struct constructor_stack);
5294 6252
5295 if (type == 0) 6253 if (type == 0)
5296 type = TREE_TYPE (constructor_decl); 6254 type = TREE_TYPE (constructor_decl);
5297 6255
5298 if (targetm.vector_opaque_p (type)) 6256 if (TREE_CODE (type) == VECTOR_TYPE
6257 && TYPE_VECTOR_OPAQUE (type))
5299 error ("opaque vector types cannot be initialized"); 6258 error ("opaque vector types cannot be initialized");
5300 6259
5301 p->type = constructor_type; 6260 p->type = constructor_type;
5302 p->fields = constructor_fields; 6261 p->fields = constructor_fields;
5303 p->index = constructor_index; 6262 p->index = constructor_index;
5306 p->unfilled_fields = constructor_unfilled_fields; 6265 p->unfilled_fields = constructor_unfilled_fields;
5307 p->bit_index = constructor_bit_index; 6266 p->bit_index = constructor_bit_index;
5308 p->elements = constructor_elements; 6267 p->elements = constructor_elements;
5309 p->constant = constructor_constant; 6268 p->constant = constructor_constant;
5310 p->simple = constructor_simple; 6269 p->simple = constructor_simple;
6270 p->nonconst = constructor_nonconst;
5311 p->erroneous = constructor_erroneous; 6271 p->erroneous = constructor_erroneous;
5312 p->pending_elts = constructor_pending_elts; 6272 p->pending_elts = constructor_pending_elts;
5313 p->depth = constructor_depth; 6273 p->depth = constructor_depth;
5314 p->replacement_value.value = 0; 6274 p->replacement_value.value = 0;
5315 p->replacement_value.original_code = ERROR_MARK; 6275 p->replacement_value.original_code = ERROR_MARK;
6276 p->replacement_value.original_type = NULL;
5316 p->implicit = 0; 6277 p->implicit = 0;
5317 p->range_stack = 0; 6278 p->range_stack = 0;
5318 p->outer = 0; 6279 p->outer = 0;
5319 p->incremental = constructor_incremental; 6280 p->incremental = constructor_incremental;
5320 p->designated = constructor_designated; 6281 p->designated = constructor_designated;
5321 p->next = 0; 6282 p->next = 0;
5322 constructor_stack = p; 6283 constructor_stack = p;
5323 6284
5324 constructor_constant = 1; 6285 constructor_constant = 1;
5325 constructor_simple = 1; 6286 constructor_simple = 1;
6287 constructor_nonconst = 0;
5326 constructor_depth = SPELLING_DEPTH (); 6288 constructor_depth = SPELLING_DEPTH ();
5327 constructor_elements = 0; 6289 constructor_elements = 0;
5328 constructor_pending_elts = 0; 6290 constructor_pending_elts = 0;
5329 constructor_type = type; 6291 constructor_type = type;
5330 constructor_incremental = 1; 6292 constructor_incremental = 1;
5447 p->unfilled_fields = constructor_unfilled_fields; 6409 p->unfilled_fields = constructor_unfilled_fields;
5448 p->bit_index = constructor_bit_index; 6410 p->bit_index = constructor_bit_index;
5449 p->elements = constructor_elements; 6411 p->elements = constructor_elements;
5450 p->constant = constructor_constant; 6412 p->constant = constructor_constant;
5451 p->simple = constructor_simple; 6413 p->simple = constructor_simple;
6414 p->nonconst = constructor_nonconst;
5452 p->erroneous = constructor_erroneous; 6415 p->erroneous = constructor_erroneous;
5453 p->pending_elts = constructor_pending_elts; 6416 p->pending_elts = constructor_pending_elts;
5454 p->depth = constructor_depth; 6417 p->depth = constructor_depth;
5455 p->replacement_value.value = 0; 6418 p->replacement_value.value = 0;
5456 p->replacement_value.original_code = ERROR_MARK; 6419 p->replacement_value.original_code = ERROR_MARK;
6420 p->replacement_value.original_type = NULL;
5457 p->implicit = implicit; 6421 p->implicit = implicit;
5458 p->outer = 0; 6422 p->outer = 0;
5459 p->incremental = constructor_incremental; 6423 p->incremental = constructor_incremental;
5460 p->designated = constructor_designated; 6424 p->designated = constructor_designated;
5461 p->next = constructor_stack; 6425 p->next = constructor_stack;
5462 p->range_stack = 0; 6426 p->range_stack = 0;
5463 constructor_stack = p; 6427 constructor_stack = p;
5464 6428
5465 constructor_constant = 1; 6429 constructor_constant = 1;
5466 constructor_simple = 1; 6430 constructor_simple = 1;
6431 constructor_nonconst = 0;
5467 constructor_depth = SPELLING_DEPTH (); 6432 constructor_depth = SPELLING_DEPTH ();
5468 constructor_elements = 0; 6433 constructor_elements = 0;
5469 constructor_incremental = 1; 6434 constructor_incremental = 1;
5470 constructor_designated = 0; 6435 constructor_designated = 0;
5471 constructor_pending_elts = 0; 6436 constructor_pending_elts = 0;
5511 6476
5512 if (value && TREE_CODE (value) == CONSTRUCTOR) 6477 if (value && TREE_CODE (value) == CONSTRUCTOR)
5513 { 6478 {
5514 constructor_constant = TREE_CONSTANT (value); 6479 constructor_constant = TREE_CONSTANT (value);
5515 constructor_simple = TREE_STATIC (value); 6480 constructor_simple = TREE_STATIC (value);
6481 constructor_nonconst = CONSTRUCTOR_NON_CONST (value);
5516 constructor_elements = CONSTRUCTOR_ELTS (value); 6482 constructor_elements = CONSTRUCTOR_ELTS (value);
5517 if (!VEC_empty (constructor_elt, constructor_elements) 6483 if (!VEC_empty (constructor_elt, constructor_elements)
5518 && (TREE_CODE (constructor_type) == RECORD_TYPE 6484 && (TREE_CODE (constructor_type) == RECORD_TYPE
5519 || TREE_CODE (constructor_type) == ARRAY_TYPE)) 6485 || TREE_CODE (constructor_type) == ARRAY_TYPE))
5520 set_nonincremental_init (); 6486 set_nonincremental_init ();
5606 { 6572 {
5607 struct constructor_stack *p; 6573 struct constructor_stack *p;
5608 struct c_expr ret; 6574 struct c_expr ret;
5609 ret.value = 0; 6575 ret.value = 0;
5610 ret.original_code = ERROR_MARK; 6576 ret.original_code = ERROR_MARK;
6577 ret.original_type = NULL;
5611 6578
5612 if (implicit == 0) 6579 if (implicit == 0)
5613 { 6580 {
5614 /* When we come to an explicit close brace, 6581 /* When we come to an explicit close brace,
5615 pop any inner levels that didn't have explicit braces. */ 6582 pop any inner levels that didn't have explicit braces. */
5715 constructor_elements); 6682 constructor_elements);
5716 if (constructor_constant) 6683 if (constructor_constant)
5717 TREE_CONSTANT (ret.value) = 1; 6684 TREE_CONSTANT (ret.value) = 1;
5718 if (constructor_constant && constructor_simple) 6685 if (constructor_constant && constructor_simple)
5719 TREE_STATIC (ret.value) = 1; 6686 TREE_STATIC (ret.value) = 1;
5720 } 6687 if (constructor_nonconst)
6688 CONSTRUCTOR_NON_CONST (ret.value) = 1;
6689 }
6690 }
6691
6692 if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR)
6693 {
6694 if (constructor_nonconst)
6695 ret.original_code = C_MAYBE_CONST_EXPR;
6696 else if (ret.original_code == C_MAYBE_CONST_EXPR)
6697 ret.original_code = ERROR_MARK;
5721 } 6698 }
5722 6699
5723 constructor_type = p->type; 6700 constructor_type = p->type;
5724 constructor_fields = p->fields; 6701 constructor_fields = p->fields;
5725 constructor_index = p->index; 6702 constructor_index = p->index;
5728 constructor_unfilled_fields = p->unfilled_fields; 6705 constructor_unfilled_fields = p->unfilled_fields;
5729 constructor_bit_index = p->bit_index; 6706 constructor_bit_index = p->bit_index;
5730 constructor_elements = p->elements; 6707 constructor_elements = p->elements;
5731 constructor_constant = p->constant; 6708 constructor_constant = p->constant;
5732 constructor_simple = p->simple; 6709 constructor_simple = p->simple;
6710 constructor_nonconst = p->nonconst;
5733 constructor_erroneous = p->erroneous; 6711 constructor_erroneous = p->erroneous;
5734 constructor_incremental = p->incremental; 6712 constructor_incremental = p->incremental;
5735 constructor_designated = p->designated; 6713 constructor_designated = p->designated;
5736 constructor_pending_elts = p->pending_elts; 6714 constructor_pending_elts = p->pending_elts;
5737 constructor_depth = p->depth; 6715 constructor_depth = p->depth;
5847 if (!INTEGRAL_TYPE_P (TREE_TYPE (first)) 6825 if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
5848 || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last)))) 6826 || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
5849 { 6827 {
5850 error_init ("array index in initializer not of integer type"); 6828 error_init ("array index in initializer not of integer type");
5851 return; 6829 return;
6830 }
6831
6832 if (TREE_CODE (first) != INTEGER_CST)
6833 {
6834 first = c_fully_fold (first, false, NULL);
6835 if (TREE_CODE (first) == INTEGER_CST)
6836 pedwarn_init (input_location, OPT_pedantic,
6837 "array index in initializer is not "
6838 "an integer constant expression");
6839 }
6840
6841 if (last && TREE_CODE (last) != INTEGER_CST)
6842 {
6843 last = c_fully_fold (last, false, NULL);
6844 if (TREE_CODE (last) == INTEGER_CST)
6845 pedwarn_init (input_location, OPT_pedantic,
6846 "array index in initializer is not "
6847 "an integer constant expression");
5852 } 6848 }
5853 6849
5854 if (TREE_CODE (first) != INTEGER_CST) 6850 if (TREE_CODE (first) != INTEGER_CST)
5855 error_init ("nonconstant array index in initializer"); 6851 error_init ("nonconstant array index in initializer");
5856 else if (last != 0 && TREE_CODE (last) != INTEGER_CST) 6852 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5862 else if (constructor_max_index 6858 else if (constructor_max_index
5863 && tree_int_cst_lt (constructor_max_index, first)) 6859 && tree_int_cst_lt (constructor_max_index, first))
5864 error_init ("array index in initializer exceeds array bounds"); 6860 error_init ("array index in initializer exceeds array bounds");
5865 else 6861 else
5866 { 6862 {
6863 constant_expression_warning (first);
6864 if (last)
6865 constant_expression_warning (last);
5867 constructor_index = convert (bitsizetype, first); 6866 constructor_index = convert (bitsizetype, first);
5868 6867
5869 if (last) 6868 if (last)
5870 { 6869 {
5871 if (tree_int_cst_equal (first, last)) 6870 if (tree_int_cst_equal (first, last))
5932 } 6931 }
5933 } 6932 }
5934 6933
5935 /* Add a new initializer to the tree of pending initializers. PURPOSE 6934 /* Add a new initializer to the tree of pending initializers. PURPOSE
5936 identifies the initializer, either array index or field in a structure. 6935 identifies the initializer, either array index or field in a structure.
5937 VALUE is the value of that index or field. 6936 VALUE is the value of that index or field. If ORIGTYPE is not
6937 NULL_TREE, it is the original type of VALUE.
5938 6938
5939 IMPLICIT is true if value comes from pop_init_level (1), 6939 IMPLICIT is true if value comes from pop_init_level (1),
5940 the new initializer has been merged with the existing one 6940 the new initializer has been merged with the existing one
5941 and thus no warnings should be emitted about overriding an 6941 and thus no warnings should be emitted about overriding an
5942 existing initializer. */ 6942 existing initializer. */
5943 6943
5944 static void 6944 static void
5945 add_pending_init (tree purpose, tree value, bool implicit) 6945 add_pending_init (tree purpose, tree value, tree origtype, bool implicit)
5946 { 6946 {
5947 struct init_node *p, **q, *r; 6947 struct init_node *p, **q, *r;
5948 6948
5949 q = &constructor_pending_elts; 6949 q = &constructor_pending_elts;
5950 p = 0; 6950 p = 0;
5966 warning_init (0, "initialized field with side-effects overwritten"); 6966 warning_init (0, "initialized field with side-effects overwritten");
5967 else if (warn_override_init) 6967 else if (warn_override_init)
5968 warning_init (OPT_Woverride_init, "initialized field overwritten"); 6968 warning_init (OPT_Woverride_init, "initialized field overwritten");
5969 } 6969 }
5970 p->value = value; 6970 p->value = value;
6971 p->origtype = origtype;
5971 return; 6972 return;
5972 } 6973 }
5973 } 6974 }
5974 } 6975 }
5975 else 6976 else
5992 warning_init (0, "initialized field with side-effects overwritten"); 6993 warning_init (0, "initialized field with side-effects overwritten");
5993 else if (warn_override_init) 6994 else if (warn_override_init)
5994 warning_init (OPT_Woverride_init, "initialized field overwritten"); 6995 warning_init (OPT_Woverride_init, "initialized field overwritten");
5995 } 6996 }
5996 p->value = value; 6997 p->value = value;
6998 p->origtype = origtype;
5997 return; 6999 return;
5998 } 7000 }
5999 } 7001 }
6000 } 7002 }
6001 7003
6002 r = GGC_NEW (struct init_node); 7004 r = GGC_NEW (struct init_node);
6003 r->purpose = purpose; 7005 r->purpose = purpose;
6004 r->value = value; 7006 r->value = value;
7007 r->origtype = origtype;
6005 7008
6006 *q = r; 7009 *q = r;
6007 r->parent = p; 7010 r->parent = p;
6008 r->left = 0; 7011 r->left = 0;
6009 r->right = 0; 7012 r->right = 0;
6175 if (TREE_CODE (constructor_type) != RECORD_TYPE 7178 if (TREE_CODE (constructor_type) != RECORD_TYPE
6176 && TREE_CODE (constructor_type) != ARRAY_TYPE) 7179 && TREE_CODE (constructor_type) != ARRAY_TYPE)
6177 return; 7180 return;
6178 7181
6179 FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value) 7182 FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
6180 add_pending_init (index, value, false); 7183 add_pending_init (index, value, NULL_TREE, false);
6181 constructor_elements = 0; 7184 constructor_elements = 0;
6182 if (TREE_CODE (constructor_type) == RECORD_TYPE) 7185 if (TREE_CODE (constructor_type) == RECORD_TYPE)
6183 { 7186 {
6184 constructor_unfilled_fields = TYPE_FIELDS (constructor_type); 7187 constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
6185 /* Skip any nameless bit fields at the beginning. */ 7188 /* Skip any nameless bit fields at the beginning. */
6265 val[0] |= ((HOST_WIDE_INT) -1) 7268 val[0] |= ((HOST_WIDE_INT) -1)
6266 << (bitpos - HOST_BITS_PER_WIDE_INT); 7269 << (bitpos - HOST_BITS_PER_WIDE_INT);
6267 } 7270 }
6268 7271
6269 value = build_int_cst_wide (type, val[1], val[0]); 7272 value = build_int_cst_wide (type, val[1], val[0]);
6270 add_pending_init (purpose, value, false); 7273 add_pending_init (purpose, value, NULL_TREE, false);
6271 } 7274 }
6272 7275
6273 constructor_incremental = 0; 7276 constructor_incremental = 0;
6274 } 7277 }
6275 7278
6330 } 7333 }
6331 7334
6332 /* "Output" the next constructor element. 7335 /* "Output" the next constructor element.
6333 At top level, really output it to assembler code now. 7336 At top level, really output it to assembler code now.
6334 Otherwise, collect it in a list from which we will make a CONSTRUCTOR. 7337 Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
7338 If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
6335 TYPE is the data type that the containing data type wants here. 7339 TYPE is the data type that the containing data type wants here.
6336 FIELD is the field (a FIELD_DECL) or the index that this element fills. 7340 FIELD is the field (a FIELD_DECL) or the index that this element fills.
6337 If VALUE is a string constant, STRICT_STRING is true if it is 7341 If VALUE is a string constant, STRICT_STRING is true if it is
6338 unparenthesized or we should not warn here for it being parenthesized. 7342 unparenthesized or we should not warn here for it being parenthesized.
6339 For other types of VALUE, STRICT_STRING is not used. 7343 For other types of VALUE, STRICT_STRING is not used.
6346 the new initializer has been merged with the existing one 7350 the new initializer has been merged with the existing one
6347 and thus no warnings should be emitted about overriding an 7351 and thus no warnings should be emitted about overriding an
6348 existing initializer. */ 7352 existing initializer. */
6349 7353
6350 static void 7354 static void
6351 output_init_element (tree value, bool strict_string, tree type, tree field, 7355 output_init_element (tree value, tree origtype, bool strict_string, tree type,
6352 int pending, bool implicit) 7356 tree field, int pending, bool implicit)
6353 { 7357 {
7358 tree semantic_type = NULL_TREE;
6354 constructor_elt *celt; 7359 constructor_elt *celt;
7360 bool maybe_const = true;
7361 bool npc;
6355 7362
6356 if (type == error_mark_node || value == error_mark_node) 7363 if (type == error_mark_node || value == error_mark_node)
6357 { 7364 {
6358 constructor_erroneous = 1; 7365 constructor_erroneous = 1;
6359 return; 7366 return;
6364 && !(TREE_CODE (value) == STRING_CST 7371 && !(TREE_CODE (value) == STRING_CST
6365 && TREE_CODE (type) == ARRAY_TYPE 7372 && TREE_CODE (type) == ARRAY_TYPE
6366 && INTEGRAL_TYPE_P (TREE_TYPE (type))) 7373 && INTEGRAL_TYPE_P (TREE_TYPE (type)))
6367 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)), 7374 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
6368 TYPE_MAIN_VARIANT (type))) 7375 TYPE_MAIN_VARIANT (type)))
6369 value = array_to_pointer_conversion (value); 7376 value = array_to_pointer_conversion (input_location, value);
6370 7377
6371 if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR 7378 if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
6372 && require_constant_value && !flag_isoc99 && pending) 7379 && require_constant_value && !flag_isoc99 && pending)
6373 { 7380 {
6374 /* As an extension, allow initializing objects with static storage 7381 /* As an extension, allow initializing objects with static storage
6375 duration with compound literals (which are then treated just as 7382 duration with compound literals (which are then treated just as
6376 the brace enclosed list they contain). */ 7383 the brace enclosed list they contain). */
6377 tree decl = COMPOUND_LITERAL_EXPR_DECL (value); 7384 tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
6378 value = DECL_INITIAL (decl); 7385 value = DECL_INITIAL (decl);
6379 } 7386 }
7387
7388 npc = null_pointer_constant_p (value);
7389 if (TREE_CODE (value) == EXCESS_PRECISION_EXPR)
7390 {
7391 semantic_type = TREE_TYPE (value);
7392 value = TREE_OPERAND (value, 0);
7393 }
7394 value = c_fully_fold (value, require_constant_value, &maybe_const);
6380 7395
6381 if (value == error_mark_node) 7396 if (value == error_mark_node)
6382 constructor_erroneous = 1; 7397 constructor_erroneous = 1;
6383 else if (!TREE_CONSTANT (value)) 7398 else if (!TREE_CONSTANT (value))
6384 constructor_constant = 0; 7399 constructor_constant = 0;
6386 || ((TREE_CODE (constructor_type) == RECORD_TYPE 7401 || ((TREE_CODE (constructor_type) == RECORD_TYPE
6387 || TREE_CODE (constructor_type) == UNION_TYPE) 7402 || TREE_CODE (constructor_type) == UNION_TYPE)
6388 && DECL_C_BIT_FIELD (field) 7403 && DECL_C_BIT_FIELD (field)
6389 && TREE_CODE (value) != INTEGER_CST)) 7404 && TREE_CODE (value) != INTEGER_CST))
6390 constructor_simple = 0; 7405 constructor_simple = 0;
7406 if (!maybe_const)
7407 constructor_nonconst = 1;
6391 7408
6392 if (!initializer_constant_valid_p (value, TREE_TYPE (value))) 7409 if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
6393 { 7410 {
6394 if (require_constant_value) 7411 if (require_constant_value)
6395 { 7412 {
6397 value = error_mark_node; 7414 value = error_mark_node;
6398 } 7415 }
6399 else if (require_constant_elements) 7416 else if (require_constant_elements)
6400 pedwarn (input_location, 0, 7417 pedwarn (input_location, 0,
6401 "initializer element is not computable at load time"); 7418 "initializer element is not computable at load time");
7419 }
7420 else if (!maybe_const
7421 && (require_constant_value || require_constant_elements))
7422 pedwarn_init (input_location, 0,
7423 "initializer element is not a constant expression");
7424
7425 /* Issue -Wc++-compat warnings about initializing a bitfield with
7426 enum type. */
7427 if (warn_cxx_compat
7428 && field != NULL_TREE
7429 && TREE_CODE (field) == FIELD_DECL
7430 && DECL_BIT_FIELD_TYPE (field) != NULL_TREE
7431 && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))
7432 != TYPE_MAIN_VARIANT (type))
7433 && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE)
7434 {
7435 tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value);
7436 if (checktype != error_mark_node
7437 && (TYPE_MAIN_VARIANT (checktype)
7438 != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))))
7439 warning_init (OPT_Wc___compat,
7440 "enum conversion in initialization is invalid in C++");
6402 } 7441 }
6403 7442
6404 /* If this field is empty (and not at the end of structure), 7443 /* If this field is empty (and not at the end of structure),
6405 don't do anything other than checking the initializer. */ 7444 don't do anything other than checking the initializer. */
6406 if (field 7445 if (field
6409 && integer_zerop (TYPE_SIZE (TREE_TYPE (field))) 7448 && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
6410 && (TREE_CODE (constructor_type) == ARRAY_TYPE 7449 && (TREE_CODE (constructor_type) == ARRAY_TYPE
6411 || TREE_CHAIN (field))))) 7450 || TREE_CHAIN (field)))))
6412 return; 7451 return;
6413 7452
6414 value = digest_init (type, value, strict_string, require_constant_value); 7453 if (semantic_type)
7454 value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
7455 value = digest_init (input_location, type, value, origtype, npc,
7456 strict_string, require_constant_value);
6415 if (value == error_mark_node) 7457 if (value == error_mark_node)
6416 { 7458 {
6417 constructor_erroneous = 1; 7459 constructor_erroneous = 1;
6418 return; 7460 return;
6419 } 7461 }
7462 if (require_constant_value || require_constant_elements)
7463 constant_expression_warning (value);
6420 7464
6421 /* If this element doesn't come next in sequence, 7465 /* If this element doesn't come next in sequence,
6422 put it on constructor_pending_elts. */ 7466 put it on constructor_pending_elts. */
6423 if (TREE_CODE (constructor_type) == ARRAY_TYPE 7467 if (TREE_CODE (constructor_type) == ARRAY_TYPE
6424 && (!constructor_incremental 7468 && (!constructor_incremental
6426 { 7470 {
6427 if (constructor_incremental 7471 if (constructor_incremental
6428 && tree_int_cst_lt (field, constructor_unfilled_index)) 7472 && tree_int_cst_lt (field, constructor_unfilled_index))
6429 set_nonincremental_init (); 7473 set_nonincremental_init ();
6430 7474
6431 add_pending_init (field, value, implicit); 7475 add_pending_init (field, value, origtype, implicit);
6432 return; 7476 return;
6433 } 7477 }
6434 else if (TREE_CODE (constructor_type) == RECORD_TYPE 7478 else if (TREE_CODE (constructor_type) == RECORD_TYPE
6435 && (!constructor_incremental 7479 && (!constructor_incremental
6436 || field != constructor_unfilled_fields)) 7480 || field != constructor_unfilled_fields))
6452 if (tree_int_cst_lt (bitpos, unfillpos)) 7496 if (tree_int_cst_lt (bitpos, unfillpos))
6453 set_nonincremental_init (); 7497 set_nonincremental_init ();
6454 } 7498 }
6455 } 7499 }
6456 7500
6457 add_pending_init (field, value, implicit); 7501 add_pending_init (field, value, origtype, implicit);
6458 return; 7502 return;
6459 } 7503 }
6460 else if (TREE_CODE (constructor_type) == UNION_TYPE 7504 else if (TREE_CODE (constructor_type) == UNION_TYPE
6461 && !VEC_empty (constructor_elt, constructor_elements)) 7505 && !VEC_empty (constructor_elt, constructor_elements))
6462 { 7506 {
6482 celt->value = value; 7526 celt->value = value;
6483 7527
6484 /* Advance the variable that indicates sequential elements output. */ 7528 /* Advance the variable that indicates sequential elements output. */
6485 if (TREE_CODE (constructor_type) == ARRAY_TYPE) 7529 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6486 constructor_unfilled_index 7530 constructor_unfilled_index
6487 = size_binop (PLUS_EXPR, constructor_unfilled_index, 7531 = size_binop_loc (input_location, PLUS_EXPR, constructor_unfilled_index,
6488 bitsize_one_node); 7532 bitsize_one_node);
6489 else if (TREE_CODE (constructor_type) == RECORD_TYPE) 7533 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
6490 { 7534 {
6491 constructor_unfilled_fields 7535 constructor_unfilled_fields
6492 = TREE_CHAIN (constructor_unfilled_fields); 7536 = TREE_CHAIN (constructor_unfilled_fields);
6493 7537
6535 { 7579 {
6536 if (TREE_CODE (constructor_type) == ARRAY_TYPE) 7580 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6537 { 7581 {
6538 if (tree_int_cst_equal (elt->purpose, 7582 if (tree_int_cst_equal (elt->purpose,
6539 constructor_unfilled_index)) 7583 constructor_unfilled_index))
6540 output_init_element (elt->value, true, 7584 output_init_element (elt->value, elt->origtype, true,
6541 TREE_TYPE (constructor_type), 7585 TREE_TYPE (constructor_type),
6542 constructor_unfilled_index, 0, false); 7586 constructor_unfilled_index, 0, false);
6543 else if (tree_int_cst_lt (constructor_unfilled_index, 7587 else if (tree_int_cst_lt (constructor_unfilled_index,
6544 elt->purpose)) 7588 elt->purpose))
6545 { 7589 {
6589 /* We can't compare fields here because there might be empty 7633 /* We can't compare fields here because there might be empty
6590 fields in between. */ 7634 fields in between. */
6591 if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos)) 7635 if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos))
6592 { 7636 {
6593 constructor_unfilled_fields = elt->purpose; 7637 constructor_unfilled_fields = elt->purpose;
6594 output_init_element (elt->value, true, TREE_TYPE (elt->purpose), 7638 output_init_element (elt->value, elt->origtype, true,
7639 TREE_TYPE (elt->purpose),
6595 elt->purpose, 0, false); 7640 elt->purpose, 0, false);
6596 } 7641 }
6597 else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos)) 7642 else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos))
6598 { 7643 {
6599 /* Advance to the next smaller node. */ 7644 /* Advance to the next smaller node. */
6703 { 7748 {
6704 if ((TREE_CODE (constructor_type) == RECORD_TYPE 7749 if ((TREE_CODE (constructor_type) == RECORD_TYPE
6705 || TREE_CODE (constructor_type) == UNION_TYPE) 7750 || TREE_CODE (constructor_type) == UNION_TYPE)
6706 && constructor_fields == 0) 7751 && constructor_fields == 0)
6707 process_init_element (pop_init_level (1), true); 7752 process_init_element (pop_init_level (1), true);
6708 else if (TREE_CODE (constructor_type) == ARRAY_TYPE 7753 else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
7754 || TREE_CODE (constructor_type) == VECTOR_TYPE)
6709 && (constructor_max_index == 0 7755 && (constructor_max_index == 0
6710 || tree_int_cst_lt (constructor_max_index, 7756 || tree_int_cst_lt (constructor_max_index,
6711 constructor_index))) 7757 constructor_index)))
6712 process_init_element (pop_init_level (1), true); 7758 process_init_element (pop_init_level (1), true);
6713 else 7759 else
6720 /* If value is a compound literal and we'll be just using its 7766 /* If value is a compound literal and we'll be just using its
6721 content, don't put it into a SAVE_EXPR. */ 7767 content, don't put it into a SAVE_EXPR. */
6722 if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR 7768 if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
6723 || !require_constant_value 7769 || !require_constant_value
6724 || flag_isoc99) 7770 || flag_isoc99)
6725 value.value = save_expr (value.value); 7771 {
7772 tree semantic_type = NULL_TREE;
7773 if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR)
7774 {
7775 semantic_type = TREE_TYPE (value.value);
7776 value.value = TREE_OPERAND (value.value, 0);
7777 }
7778 value.value = c_save_expr (value.value);
7779 if (semantic_type)
7780 value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type,
7781 value.value);
7782 }
6726 } 7783 }
6727 7784
6728 while (1) 7785 while (1)
6729 { 7786 {
6730 if (TREE_CODE (constructor_type) == RECORD_TYPE) 7787 if (TREE_CODE (constructor_type) == RECORD_TYPE)
6764 and we don't have an element of its type, push into it. */ 7821 and we don't have an element of its type, push into it. */
6765 else if (value.value != 0 7822 else if (value.value != 0
6766 && value.value != error_mark_node 7823 && value.value != error_mark_node
6767 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype 7824 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
6768 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE 7825 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6769 || fieldcode == UNION_TYPE)) 7826 || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE))
6770 { 7827 {
6771 push_init_level (1); 7828 push_init_level (1);
6772 continue; 7829 continue;
6773 } 7830 }
6774 7831
6775 if (value.value) 7832 if (value.value)
6776 { 7833 {
6777 push_member_name (constructor_fields); 7834 push_member_name (constructor_fields);
6778 output_init_element (value.value, strict_string, 7835 output_init_element (value.value, value.original_type,
6779 fieldtype, constructor_fields, 1, implicit); 7836 strict_string, fieldtype,
7837 constructor_fields, 1, implicit);
6780 RESTORE_SPELLING_DEPTH (constructor_depth); 7838 RESTORE_SPELLING_DEPTH (constructor_depth);
6781 } 7839 }
6782 else 7840 else
6783 /* Do the bookkeeping for an element that was 7841 /* Do the bookkeeping for an element that was
6784 directly output as a constructor. */ 7842 directly output as a constructor. */
6785 { 7843 {
6786 /* For a record, keep track of end position of last field. */ 7844 /* For a record, keep track of end position of last field. */
6787 if (DECL_SIZE (constructor_fields)) 7845 if (DECL_SIZE (constructor_fields))
6788 constructor_bit_index 7846 constructor_bit_index
6789 = size_binop (PLUS_EXPR, 7847 = size_binop_loc (input_location, PLUS_EXPR,
6790 bit_position (constructor_fields), 7848 bit_position (constructor_fields),
6791 DECL_SIZE (constructor_fields)); 7849 DECL_SIZE (constructor_fields));
6792 7850
6793 /* If the current field was the first one not yet written out, 7851 /* If the current field was the first one not yet written out,
6794 it isn't now, so update. */ 7852 it isn't now, so update. */
6795 if (constructor_unfilled_fields == constructor_fields) 7853 if (constructor_unfilled_fields == constructor_fields)
6796 { 7854 {
6854 and we don't have an element of its type, push into it. */ 7912 and we don't have an element of its type, push into it. */
6855 else if (value.value != 0 7913 else if (value.value != 0
6856 && value.value != error_mark_node 7914 && value.value != error_mark_node
6857 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype 7915 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
6858 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE 7916 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6859 || fieldcode == UNION_TYPE)) 7917 || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE))
6860 { 7918 {
6861 push_init_level (1); 7919 push_init_level (1);
6862 continue; 7920 continue;
6863 } 7921 }
6864 7922
6865 if (value.value) 7923 if (value.value)
6866 { 7924 {
6867 push_member_name (constructor_fields); 7925 push_member_name (constructor_fields);
6868 output_init_element (value.value, strict_string, 7926 output_init_element (value.value, value.original_type,
6869 fieldtype, constructor_fields, 1, implicit); 7927 strict_string, fieldtype,
7928 constructor_fields, 1, implicit);
6870 RESTORE_SPELLING_DEPTH (constructor_depth); 7929 RESTORE_SPELLING_DEPTH (constructor_depth);
6871 } 7930 }
6872 else 7931 else
6873 /* Do the bookkeeping for an element that was 7932 /* Do the bookkeeping for an element that was
6874 directly output as a constructor. */ 7933 directly output as a constructor. */
6894 and we don't have an element of its type, push into it. */ 7953 and we don't have an element of its type, push into it. */
6895 else if (value.value != 0 7954 else if (value.value != 0
6896 && value.value != error_mark_node 7955 && value.value != error_mark_node
6897 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != elttype 7956 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != elttype
6898 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE 7957 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
6899 || eltcode == UNION_TYPE)) 7958 || eltcode == UNION_TYPE || eltcode == VECTOR_TYPE))
6900 { 7959 {
6901 push_init_level (1); 7960 push_init_level (1);
6902 continue; 7961 continue;
6903 } 7962 }
6904 7963
6913 7972
6914 /* Now output the actual element. */ 7973 /* Now output the actual element. */
6915 if (value.value) 7974 if (value.value)
6916 { 7975 {
6917 push_array_bounds (tree_low_cst (constructor_index, 1)); 7976 push_array_bounds (tree_low_cst (constructor_index, 1));
6918 output_init_element (value.value, strict_string, 7977 output_init_element (value.value, value.original_type,
6919 elttype, constructor_index, 1, implicit); 7978 strict_string, elttype,
7979 constructor_index, 1, implicit);
6920 RESTORE_SPELLING_DEPTH (constructor_depth); 7980 RESTORE_SPELLING_DEPTH (constructor_depth);
6921 } 7981 }
6922 7982
6923 constructor_index 7983 constructor_index
6924 = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node); 7984 = size_binop_loc (input_location, PLUS_EXPR,
7985 constructor_index, bitsize_one_node);
6925 7986
6926 if (!value.value) 7987 if (!value.value)
6927 /* If we are doing the bookkeeping for an element that was 7988 /* If we are doing the bookkeeping for an element that was
6928 directly output as a constructor, we must update 7989 directly output as a constructor, we must update
6929 constructor_unfilled_index. */ 7990 constructor_unfilled_index. */
6942 break; 8003 break;
6943 } 8004 }
6944 8005
6945 /* Now output the actual element. */ 8006 /* Now output the actual element. */
6946 if (value.value) 8007 if (value.value)
6947 output_init_element (value.value, strict_string, 8008 {
6948 elttype, constructor_index, 1, implicit); 8009 if (TREE_CODE (value.value) == VECTOR_CST)
8010 elttype = TYPE_MAIN_VARIANT (constructor_type);
8011 output_init_element (value.value, value.original_type,
8012 strict_string, elttype,
8013 constructor_index, 1, implicit);
8014 }
6949 8015
6950 constructor_index 8016 constructor_index
6951 = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node); 8017 = size_binop_loc (input_location,
8018 PLUS_EXPR, constructor_index, bitsize_one_node);
6952 8019
6953 if (!value.value) 8020 if (!value.value)
6954 /* If we are doing the bookkeeping for an element that was 8021 /* If we are doing the bookkeeping for an element that was
6955 directly output as a constructor, we must update 8022 directly output as a constructor, we must update
6956 constructor_unfilled_index. */ 8023 constructor_unfilled_index. */
6967 break; 8034 break;
6968 } 8035 }
6969 else 8036 else
6970 { 8037 {
6971 if (value.value) 8038 if (value.value)
6972 output_init_element (value.value, strict_string, 8039 output_init_element (value.value, value.original_type,
6973 constructor_type, NULL_TREE, 1, implicit); 8040 strict_string, constructor_type,
8041 NULL_TREE, 1, implicit);
6974 constructor_fields = 0; 8042 constructor_fields = 0;
6975 } 8043 }
6976 8044
6977 /* Handle range initializers either at this level or anywhere higher 8045 /* Handle range initializers either at this level or anywhere higher
6978 in the designator stack. */ 8046 in the designator stack. */
6994 { 8062 {
6995 gcc_assert (constructor_stack->implicit); 8063 gcc_assert (constructor_stack->implicit);
6996 process_init_element (pop_init_level (1), true); 8064 process_init_element (pop_init_level (1), true);
6997 } 8065 }
6998 8066
6999 p->index = size_binop (PLUS_EXPR, p->index, bitsize_one_node); 8067 p->index = size_binop_loc (input_location,
8068 PLUS_EXPR, p->index, bitsize_one_node);
7000 if (tree_int_cst_equal (p->index, p->range_end) && !p->prev) 8069 if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
7001 finish = 1; 8070 finish = 1;
7002 8071
7003 while (1) 8072 while (1)
7004 { 8073 {
7044 some INPUTS, and some CLOBBERS. The latter three may be NULL. 8113 some INPUTS, and some CLOBBERS. The latter three may be NULL.
7045 SIMPLE indicates whether there was anything at all after the 8114 SIMPLE indicates whether there was anything at all after the
7046 string in the asm expression -- asm("blah") and asm("blah" : ) 8115 string in the asm expression -- asm("blah") and asm("blah" : )
7047 are subtly different. We use a ASM_EXPR node to represent this. */ 8116 are subtly different. We use a ASM_EXPR node to represent this. */
7048 tree 8117 tree
7049 build_asm_expr (tree string, tree outputs, tree inputs, tree clobbers, 8118 build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
7050 bool simple) 8119 tree clobbers, tree labels, bool simple)
7051 { 8120 {
7052 tree tail; 8121 tree tail;
7053 tree args; 8122 tree args;
7054 int i; 8123 int i;
7055 const char *constraint; 8124 const char *constraint;
7059 8128
7060 ninputs = list_length (inputs); 8129 ninputs = list_length (inputs);
7061 noutputs = list_length (outputs); 8130 noutputs = list_length (outputs);
7062 oconstraints = (const char **) alloca (noutputs * sizeof (const char *)); 8131 oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
7063 8132
7064 string = resolve_asm_operand_names (string, outputs, inputs); 8133 string = resolve_asm_operand_names (string, outputs, inputs, labels);
7065 8134
7066 /* Remove output conversions that change the type but not the mode. */ 8135 /* Remove output conversions that change the type but not the mode. */
7067 for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail)) 8136 for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
7068 { 8137 {
7069 tree output = TREE_VALUE (tail); 8138 tree output = TREE_VALUE (tail);
7129 input = error_mark_node; 8198 input = error_mark_node;
7130 8199
7131 TREE_VALUE (tail) = input; 8200 TREE_VALUE (tail) = input;
7132 } 8201 }
7133 8202
7134 args = build_stmt (ASM_EXPR, string, outputs, inputs, clobbers); 8203 /* ASMs with labels cannot have outputs. This should have been
8204 enforced by the parser. */
8205 gcc_assert (outputs == NULL || labels == NULL);
8206
8207 args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers, labels);
7135 8208
7136 /* asm statements without outputs, including simple ones, are treated 8209 /* asm statements without outputs, including simple ones, are treated
7137 as volatile. */ 8210 as volatile. */
7138 ASM_INPUT_P (args) = simple; 8211 ASM_INPUT_P (args) = simple;
7139 ASM_VOLATILE_P (args) = (noutputs == 0); 8212 ASM_VOLATILE_P (args) = (noutputs == 0);
7140 8213
7141 return args; 8214 return args;
7142 } 8215 }
7143 8216
7144 /* Generate a goto statement to LABEL. */ 8217 /* Generate a goto statement to LABEL. LOC is the location of the
8218 GOTO. */
7145 8219
7146 tree 8220 tree
7147 c_finish_goto_label (tree label) 8221 c_finish_goto_label (location_t loc, tree label)
7148 { 8222 {
7149 tree decl = lookup_label (label); 8223 tree decl = lookup_label_for_goto (loc, label);
7150 if (!decl) 8224 if (!decl)
7151 return NULL_TREE; 8225 return NULL_TREE;
7152
7153 if (C_DECL_UNJUMPABLE_STMT_EXPR (decl))
7154 {
7155 error ("jump into statement expression");
7156 return NULL_TREE;
7157 }
7158
7159 if (C_DECL_UNJUMPABLE_VM (decl))
7160 {
7161 error ("jump into scope of identifier with variably modified type");
7162 return NULL_TREE;
7163 }
7164
7165 if (!C_DECL_UNDEFINABLE_STMT_EXPR (decl))
7166 {
7167 /* No jump from outside this statement expression context, so
7168 record that there is a jump from within this context. */
7169 struct c_label_list *nlist;
7170 nlist = XOBNEW (&parser_obstack, struct c_label_list);
7171 nlist->next = label_context_stack_se->labels_used;
7172 nlist->label = decl;
7173 label_context_stack_se->labels_used = nlist;
7174 }
7175
7176 if (!C_DECL_UNDEFINABLE_VM (decl))
7177 {
7178 /* No jump from outside this context context of identifiers with
7179 variably modified type, so record that there is a jump from
7180 within this context. */
7181 struct c_label_list *nlist;
7182 nlist = XOBNEW (&parser_obstack, struct c_label_list);
7183 nlist->next = label_context_stack_vm->labels_used;
7184 nlist->label = decl;
7185 label_context_stack_vm->labels_used = nlist;
7186 }
7187
7188 TREE_USED (decl) = 1; 8226 TREE_USED (decl) = 1;
7189 return add_stmt (build1 (GOTO_EXPR, void_type_node, decl)); 8227 {
7190 } 8228 tree t = build1 (GOTO_EXPR, void_type_node, decl);
7191 8229 SET_EXPR_LOCATION (t, loc);
7192 /* Generate a computed goto statement to EXPR. */ 8230 return add_stmt (t);
8231 }
8232 }
8233
8234 /* Generate a computed goto statement to EXPR. LOC is the location of
8235 the GOTO. */
7193 8236
7194 tree 8237 tree
7195 c_finish_goto_ptr (tree expr) 8238 c_finish_goto_ptr (location_t loc, tree expr)
7196 { 8239 {
7197 pedwarn (input_location, OPT_pedantic, "ISO C forbids %<goto *expr;%>"); 8240 tree t;
8241 pedwarn (loc, OPT_pedantic, "ISO C forbids %<goto *expr;%>");
8242 expr = c_fully_fold (expr, false, NULL);
7198 expr = convert (ptr_type_node, expr); 8243 expr = convert (ptr_type_node, expr);
7199 return add_stmt (build1 (GOTO_EXPR, void_type_node, expr)); 8244 t = build1 (GOTO_EXPR, void_type_node, expr);
8245 SET_EXPR_LOCATION (t, loc);
8246 return add_stmt (t);
7200 } 8247 }
7201 8248
7202 /* Generate a C `return' statement. RETVAL is the expression for what 8249 /* Generate a C `return' statement. RETVAL is the expression for what
7203 to return, or a null pointer for `return;' with no value. */ 8250 to return, or a null pointer for `return;' with no value. LOC is
8251 the location of the return statement. If ORIGTYPE is not NULL_TREE, it
8252 is the original type of RETVAL. */
7204 8253
7205 tree 8254 tree
7206 c_finish_return (tree retval) 8255 c_finish_return (location_t loc, tree retval, tree origtype)
7207 { 8256 {
7208 tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt; 8257 tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
7209 bool no_warning = false; 8258 bool no_warning = false;
8259 bool npc = false;
7210 8260
7211 if (TREE_THIS_VOLATILE (current_function_decl)) 8261 if (TREE_THIS_VOLATILE (current_function_decl))
7212 warning (0, "function declared %<noreturn%> has a %<return%> statement"); 8262 warning_at (loc, 0,
8263 "function declared %<noreturn%> has a %<return%> statement");
8264
8265 if (retval)
8266 {
8267 tree semantic_type = NULL_TREE;
8268 npc = null_pointer_constant_p (retval);
8269 if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR)
8270 {
8271 semantic_type = TREE_TYPE (retval);
8272 retval = TREE_OPERAND (retval, 0);
8273 }
8274 retval = c_fully_fold (retval, false, NULL);
8275 if (semantic_type)
8276 retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
8277 }
7213 8278
7214 if (!retval) 8279 if (!retval)
7215 { 8280 {
7216 current_function_returns_null = 1; 8281 current_function_returns_null = 1;
7217 if ((warn_return_type || flag_isoc99) 8282 if ((warn_return_type || flag_isoc99)
7218 && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE) 8283 && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
7219 { 8284 {
7220 pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wreturn_type, 8285 pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wreturn_type,
7221 "%<return%> with no value, in " 8286 "%<return%> with no value, in "
7222 "function returning non-void"); 8287 "function returning non-void");
7223 no_warning = true; 8288 no_warning = true;
7224 } 8289 }
7225 } 8290 }
7226 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE) 8291 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
7227 { 8292 {
7228 current_function_returns_null = 1; 8293 current_function_returns_null = 1;
7229 if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) 8294 if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
7230 pedwarn (input_location, 0, 8295 pedwarn (loc, 0,
7231 "%<return%> with a value, in function returning void"); 8296 "%<return%> with a value, in function returning void");
7232 else 8297 else
7233 pedwarn (input_location, OPT_pedantic, "ISO C forbids " 8298 pedwarn (loc, OPT_pedantic, "ISO C forbids "
7234 "%<return%> with expression, in function returning void"); 8299 "%<return%> with expression, in function returning void");
7235 } 8300 }
7236 else 8301 else
7237 { 8302 {
7238 tree t = convert_for_assignment (valtype, retval, ic_return, 8303 tree t = convert_for_assignment (loc, valtype, retval, origtype,
7239 NULL_TREE, NULL_TREE, 0); 8304 ic_return,
8305 npc, NULL_TREE, NULL_TREE, 0);
7240 tree res = DECL_RESULT (current_function_decl); 8306 tree res = DECL_RESULT (current_function_decl);
7241 tree inner; 8307 tree inner;
7242 8308
7243 current_function_returns_value = 1; 8309 current_function_returns_value = 1;
7244 if (t == error_mark_node) 8310 if (t == error_mark_node)
7287 8353
7288 if (DECL_P (inner) 8354 if (DECL_P (inner)
7289 && !DECL_EXTERNAL (inner) 8355 && !DECL_EXTERNAL (inner)
7290 && !TREE_STATIC (inner) 8356 && !TREE_STATIC (inner)
7291 && DECL_CONTEXT (inner) == current_function_decl) 8357 && DECL_CONTEXT (inner) == current_function_decl)
7292 warning (0, "function returns address of local variable"); 8358 warning_at (loc,
8359 0, "function returns address of local variable");
7293 break; 8360 break;
7294 8361
7295 default: 8362 default:
7296 break; 8363 break;
7297 } 8364 }
7298 8365
7299 break; 8366 break;
7300 } 8367 }
7301 8368
7302 retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t); 8369 retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
8370 SET_EXPR_LOCATION (retval, loc);
7303 8371
7304 if (warn_sequence_point) 8372 if (warn_sequence_point)
7305 verify_sequence_points (retval); 8373 verify_sequence_points (retval);
7306 } 8374 }
7307 8375
7308 ret_stmt = build_stmt (RETURN_EXPR, retval); 8376 ret_stmt = build_stmt (loc, RETURN_EXPR, retval);
7309 TREE_NO_WARNING (ret_stmt) |= no_warning; 8377 TREE_NO_WARNING (ret_stmt) |= no_warning;
7310 return add_stmt (ret_stmt); 8378 return add_stmt (ret_stmt);
7311 } 8379 }
7312 8380
7313 struct c_switch { 8381 struct c_switch {
7323 determine whether or not a new case label duplicates an old case 8391 determine whether or not a new case label duplicates an old case
7324 label. We need a tree, rather than simply a hash table, because 8392 label. We need a tree, rather than simply a hash table, because
7325 of the GNU case range extension. */ 8393 of the GNU case range extension. */
7326 splay_tree cases; 8394 splay_tree cases;
7327 8395
7328 /* Number of nested statement expressions within this switch 8396 /* The bindings at the point of the switch. This is used for
7329 statement; if nonzero, case and default labels may not 8397 warnings crossing decls when branching to a case label. */
7330 appear. */ 8398 struct c_spot_bindings *bindings;
7331 unsigned int blocked_stmt_expr;
7332
7333 /* Scope of outermost declarations of identifiers with variably
7334 modified type within this switch statement; if nonzero, case and
7335 default labels may not appear. */
7336 unsigned int blocked_vm;
7337 8399
7338 /* The next node on the stack. */ 8400 /* The next node on the stack. */
7339 struct c_switch *next; 8401 struct c_switch *next;
7340 }; 8402 };
7341 8403
7346 collect at that point. */ 8408 collect at that point. */
7347 8409
7348 struct c_switch *c_switch_stack; 8410 struct c_switch *c_switch_stack;
7349 8411
7350 /* Start a C switch statement, testing expression EXP. Return the new 8412 /* Start a C switch statement, testing expression EXP. Return the new
7351 SWITCH_EXPR. */ 8413 SWITCH_EXPR. SWITCH_LOC is the location of the `switch'.
8414 SWITCH_COND_LOC is the location of the switch's condition. */
7352 8415
7353 tree 8416 tree
7354 c_start_case (tree exp) 8417 c_start_case (location_t switch_loc,
8418 location_t switch_cond_loc,
8419 tree exp)
7355 { 8420 {
7356 tree orig_type = error_mark_node; 8421 tree orig_type = error_mark_node;
7357 struct c_switch *cs; 8422 struct c_switch *cs;
7358 8423
7359 if (exp != error_mark_node) 8424 if (exp != error_mark_node)
7362 8427
7363 if (!INTEGRAL_TYPE_P (orig_type)) 8428 if (!INTEGRAL_TYPE_P (orig_type))
7364 { 8429 {
7365 if (orig_type != error_mark_node) 8430 if (orig_type != error_mark_node)
7366 { 8431 {
7367 error ("switch quantity not an integer"); 8432 error_at (switch_cond_loc, "switch quantity not an integer");
7368 orig_type = error_mark_node; 8433 orig_type = error_mark_node;
7369 } 8434 }
7370 exp = integer_zero_node; 8435 exp = integer_zero_node;
7371 } 8436 }
7372 else 8437 else
7374 tree type = TYPE_MAIN_VARIANT (orig_type); 8439 tree type = TYPE_MAIN_VARIANT (orig_type);
7375 8440
7376 if (!in_system_header 8441 if (!in_system_header
7377 && (type == long_integer_type_node 8442 && (type == long_integer_type_node
7378 || type == long_unsigned_type_node)) 8443 || type == long_unsigned_type_node))
7379 warning (OPT_Wtraditional, "%<long%> switch expression not " 8444 warning_at (switch_cond_loc,
7380 "converted to %<int%> in ISO C"); 8445 OPT_Wtraditional, "%<long%> switch expression not "
7381 8446 "converted to %<int%> in ISO C");
8447
8448 exp = c_fully_fold (exp, false, NULL);
7382 exp = default_conversion (exp); 8449 exp = default_conversion (exp);
7383 8450
7384 if (warn_sequence_point) 8451 if (warn_sequence_point)
7385 verify_sequence_points (exp); 8452 verify_sequence_points (exp);
7386 } 8453 }
7387 } 8454 }
7388 8455
7389 /* Add this new SWITCH_EXPR to the stack. */ 8456 /* Add this new SWITCH_EXPR to the stack. */
7390 cs = XNEW (struct c_switch); 8457 cs = XNEW (struct c_switch);
7391 cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp, NULL_TREE, NULL_TREE); 8458 cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp, NULL_TREE, NULL_TREE);
8459 SET_EXPR_LOCATION (cs->switch_expr, switch_loc);
7392 cs->orig_type = orig_type; 8460 cs->orig_type = orig_type;
7393 cs->cases = splay_tree_new (case_compare, NULL, NULL); 8461 cs->cases = splay_tree_new (case_compare, NULL, NULL);
7394 cs->blocked_stmt_expr = 0; 8462 cs->bindings = c_get_switch_bindings ();
7395 cs->blocked_vm = 0;
7396 cs->next = c_switch_stack; 8463 cs->next = c_switch_stack;
7397 c_switch_stack = cs; 8464 c_switch_stack = cs;
7398 8465
7399 return add_stmt (cs->switch_expr); 8466 return add_stmt (cs->switch_expr);
7400 } 8467 }
7401 8468
7402 /* Process a case label. */ 8469 /* Process a case label at location LOC. */
7403 8470
7404 tree 8471 tree
7405 do_case (tree low_value, tree high_value) 8472 do_case (location_t loc, tree low_value, tree high_value)
7406 { 8473 {
7407 tree label = NULL_TREE; 8474 tree label = NULL_TREE;
7408 8475
7409 if (c_switch_stack && !c_switch_stack->blocked_stmt_expr 8476 if (low_value && TREE_CODE (low_value) != INTEGER_CST)
7410 && !c_switch_stack->blocked_vm) 8477 {
7411 { 8478 low_value = c_fully_fold (low_value, false, NULL);
7412 label = c_add_case_label (c_switch_stack->cases, 8479 if (TREE_CODE (low_value) == INTEGER_CST)
7413 SWITCH_COND (c_switch_stack->switch_expr), 8480 pedwarn (input_location, OPT_pedantic,
7414 c_switch_stack->orig_type, 8481 "case label is not an integer constant expression");
7415 low_value, high_value); 8482 }
7416 if (label == error_mark_node) 8483
7417 label = NULL_TREE; 8484 if (high_value && TREE_CODE (high_value) != INTEGER_CST)
7418 } 8485 {
7419 else if (c_switch_stack && c_switch_stack->blocked_stmt_expr) 8486 high_value = c_fully_fold (high_value, false, NULL);
8487 if (TREE_CODE (high_value) == INTEGER_CST)
8488 pedwarn (input_location, OPT_pedantic,
8489 "case label is not an integer constant expression");
8490 }
8491
8492 if (c_switch_stack == NULL)
7420 { 8493 {
7421 if (low_value) 8494 if (low_value)
7422 error ("case label in statement expression not containing " 8495 error_at (loc, "case label not within a switch statement");
7423 "enclosing switch statement");
7424 else 8496 else
7425 error ("%<default%> label in statement expression not containing " 8497 error_at (loc, "%<default%> label not within a switch statement");
7426 "enclosing switch statement"); 8498 return NULL_TREE;
7427 } 8499 }
7428 else if (c_switch_stack && c_switch_stack->blocked_vm) 8500
7429 { 8501 if (c_check_switch_jump_warnings (c_switch_stack->bindings,
7430 if (low_value) 8502 EXPR_LOCATION (c_switch_stack->switch_expr),
7431 error ("case label in scope of identifier with variably modified " 8503 loc))
7432 "type not containing enclosing switch statement"); 8504 return NULL_TREE;
7433 else 8505
7434 error ("%<default%> label in scope of identifier with variably " 8506 label = c_add_case_label (loc, c_switch_stack->cases,
7435 "modified type not containing enclosing switch statement"); 8507 SWITCH_COND (c_switch_stack->switch_expr),
7436 } 8508 c_switch_stack->orig_type,
7437 else if (low_value) 8509 low_value, high_value);
7438 error ("case label not within a switch statement"); 8510 if (label == error_mark_node)
7439 else 8511 label = NULL_TREE;
7440 error ("%<default%> label not within a switch statement");
7441
7442 return label; 8512 return label;
7443 } 8513 }
7444 8514
7445 /* Finish the switch statement. */ 8515 /* Finish the switch statement. */
7446 8516
7450 struct c_switch *cs = c_switch_stack; 8520 struct c_switch *cs = c_switch_stack;
7451 location_t switch_location; 8521 location_t switch_location;
7452 8522
7453 SWITCH_BODY (cs->switch_expr) = body; 8523 SWITCH_BODY (cs->switch_expr) = body;
7454 8524
7455 /* We must not be within a statement expression nested in the switch
7456 at this point; we might, however, be within the scope of an
7457 identifier with variably modified type nested in the switch. */
7458 gcc_assert (!cs->blocked_stmt_expr);
7459
7460 /* Emit warnings as needed. */ 8525 /* Emit warnings as needed. */
7461 if (EXPR_HAS_LOCATION (cs->switch_expr)) 8526 switch_location = EXPR_LOCATION (cs->switch_expr);
7462 switch_location = EXPR_LOCATION (cs->switch_expr);
7463 else
7464 switch_location = input_location;
7465 c_do_switch_warnings (cs->cases, switch_location, 8527 c_do_switch_warnings (cs->cases, switch_location,
7466 TREE_TYPE (cs->switch_expr), 8528 TREE_TYPE (cs->switch_expr),
7467 SWITCH_COND (cs->switch_expr)); 8529 SWITCH_COND (cs->switch_expr));
7468 8530
7469 /* Pop the stack. */ 8531 /* Pop the stack. */
7470 c_switch_stack = cs->next; 8532 c_switch_stack = cs->next;
7471 splay_tree_delete (cs->cases); 8533 splay_tree_delete (cs->cases);
8534 c_release_switch_bindings (cs->bindings);
7472 XDELETE (cs); 8535 XDELETE (cs);
7473 } 8536 }
7474 8537
7475 /* Emit an if statement. IF_LOCUS is the location of the 'if'. COND, 8538 /* Emit an if statement. IF_LOCUS is the location of the 'if'. COND,
7476 THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK 8539 THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
7511 gcc_unreachable (); 8574 gcc_unreachable ();
7512 } 8575 }
7513 found: 8576 found:
7514 8577
7515 if (COND_EXPR_ELSE (inner_if)) 8578 if (COND_EXPR_ELSE (inner_if))
7516 warning (OPT_Wparentheses, 8579 warning_at (if_locus, OPT_Wparentheses,
7517 "%Hsuggest explicit braces to avoid ambiguous %<else%>", 8580 "suggest explicit braces to avoid ambiguous %<else%>");
7518 &if_locus);
7519 } 8581 }
7520 8582
7521 stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block); 8583 stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
7522 SET_EXPR_LOCATION (stmt, if_locus); 8584 SET_EXPR_LOCATION (stmt, if_locus);
7523 add_stmt (stmt); 8585 add_stmt (stmt);
7571 SET_EXPR_LOCATION (t, start_locus); 8633 SET_EXPR_LOCATION (t, start_locus);
7572 add_stmt (t); 8634 add_stmt (t);
7573 } 8635 }
7574 8636
7575 t = build_and_jump (&blab); 8637 t = build_and_jump (&blab);
7576 exit = fold_build3 (COND_EXPR, void_type_node, cond, exit, t);
7577 if (cond_is_first) 8638 if (cond_is_first)
7578 SET_EXPR_LOCATION (exit, start_locus); 8639 exit = fold_build3_loc (start_locus,
8640 COND_EXPR, void_type_node, cond, exit, t);
7579 else 8641 else
7580 SET_EXPR_LOCATION (exit, input_location); 8642 exit = fold_build3_loc (input_location,
8643 COND_EXPR, void_type_node, cond, exit, t);
7581 } 8644 }
7582 8645
7583 add_stmt (top); 8646 add_stmt (top);
7584 } 8647 }
7585 8648
7596 if (blab) 8659 if (blab)
7597 add_stmt (build1 (LABEL_EXPR, void_type_node, blab)); 8660 add_stmt (build1 (LABEL_EXPR, void_type_node, blab));
7598 } 8661 }
7599 8662
7600 tree 8663 tree
7601 c_finish_bc_stmt (tree *label_p, bool is_break) 8664 c_finish_bc_stmt (location_t loc, tree *label_p, bool is_break)
7602 { 8665 {
7603 bool skip; 8666 bool skip;
7604 tree label = *label_p; 8667 tree label = *label_p;
7605 8668
7606 /* In switch statements break is sometimes stylistically used after 8669 /* In switch statements break is sometimes stylistically used after
7613 skip = !block_may_fallthru (cur_stmt_list); 8676 skip = !block_may_fallthru (cur_stmt_list);
7614 8677
7615 if (!label) 8678 if (!label)
7616 { 8679 {
7617 if (!skip) 8680 if (!skip)
7618 *label_p = label = create_artificial_label (); 8681 *label_p = label = create_artificial_label (loc);
7619 } 8682 }
7620 else if (TREE_CODE (label) == LABEL_DECL) 8683 else if (TREE_CODE (label) == LABEL_DECL)
7621 ; 8684 ;
7622 else switch (TREE_INT_CST_LOW (label)) 8685 else switch (TREE_INT_CST_LOW (label))
7623 { 8686 {
7624 case 0: 8687 case 0:
7625 if (is_break) 8688 if (is_break)
7626 error ("break statement not within loop or switch"); 8689 error_at (loc, "break statement not within loop or switch");
7627 else 8690 else
7628 error ("continue statement not within a loop"); 8691 error_at (loc, "continue statement not within a loop");
7629 return NULL_TREE; 8692 return NULL_TREE;
7630 8693
7631 case 1: 8694 case 1:
7632 gcc_assert (is_break); 8695 gcc_assert (is_break);
7633 error ("break statement used with OpenMP for loop"); 8696 error_at (loc, "break statement used with OpenMP for loop");
7634 return NULL_TREE; 8697 return NULL_TREE;
7635 8698
7636 default: 8699 default:
7637 gcc_unreachable (); 8700 gcc_unreachable ();
7638 } 8701 }
7647 } 8710 }
7648 8711
7649 /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr. */ 8712 /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr. */
7650 8713
7651 static void 8714 static void
7652 emit_side_effect_warnings (tree expr) 8715 emit_side_effect_warnings (location_t loc, tree expr)
7653 { 8716 {
7654 if (expr == error_mark_node) 8717 if (expr == error_mark_node)
7655 ; 8718 ;
7656 else if (!TREE_SIDE_EFFECTS (expr)) 8719 else if (!TREE_SIDE_EFFECTS (expr))
7657 { 8720 {
7658 if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr)) 8721 if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr))
7659 warning (OPT_Wunused_value, "%Hstatement with no effect", 8722 warning_at (loc, OPT_Wunused_value, "statement with no effect");
7660 EXPR_HAS_LOCATION (expr) ? EXPR_LOCUS (expr) : &input_location);
7661 } 8723 }
7662 else 8724 else
7663 warn_if_unused_value (expr, input_location); 8725 warn_if_unused_value (expr, loc);
7664 } 8726 }
7665 8727
7666 /* Process an expression as if it were a complete statement. Emit 8728 /* Process an expression as if it were a complete statement. Emit
7667 diagnostics, but do not call ADD_STMT. */ 8729 diagnostics, but do not call ADD_STMT. LOC is the location of the
8730 statement. */
7668 8731
7669 tree 8732 tree
7670 c_process_expr_stmt (tree expr) 8733 c_process_expr_stmt (location_t loc, tree expr)
7671 { 8734 {
7672 if (!expr) 8735 if (!expr)
7673 return NULL_TREE; 8736 return NULL_TREE;
8737
8738 expr = c_fully_fold (expr, false, NULL);
7674 8739
7675 if (warn_sequence_point) 8740 if (warn_sequence_point)
7676 verify_sequence_points (expr); 8741 verify_sequence_points (expr);
7677 8742
7678 if (TREE_TYPE (expr) != error_mark_node 8743 if (TREE_TYPE (expr) != error_mark_node
7679 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr)) 8744 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
7680 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE) 8745 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
7681 error ("expression statement has incomplete type"); 8746 error_at (loc, "expression statement has incomplete type");
7682 8747
7683 /* If we're not processing a statement expression, warn about unused values. 8748 /* If we're not processing a statement expression, warn about unused values.
7684 Warnings for statement expressions will be emitted later, once we figure 8749 Warnings for statement expressions will be emitted later, once we figure
7685 out which is the result. */ 8750 out which is the result. */
7686 if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list) 8751 if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
7687 && warn_unused_value) 8752 && warn_unused_value)
7688 emit_side_effect_warnings (expr); 8753 emit_side_effect_warnings (loc, expr);
7689 8754
7690 /* If the expression is not of a type to which we cannot assign a line 8755 /* If the expression is not of a type to which we cannot assign a line
7691 number, wrap the thing in a no-op NOP_EXPR. */ 8756 number, wrap the thing in a no-op NOP_EXPR. */
7692 if (DECL_P (expr) || CONSTANT_CLASS_P (expr)) 8757 if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
7693 expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr); 8758 {
7694 8759 expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
7695 if (CAN_HAVE_LOCATION_P (expr)) 8760 SET_EXPR_LOCATION (expr, loc);
7696 SET_EXPR_LOCATION (expr, input_location); 8761 }
7697 8762
7698 return expr; 8763 return expr;
7699 } 8764 }
7700 8765
7701 /* Emit an expression as a statement. */ 8766 /* Emit an expression as a statement. LOC is the location of the
8767 expression. */
7702 8768
7703 tree 8769 tree
7704 c_finish_expr_stmt (tree expr) 8770 c_finish_expr_stmt (location_t loc, tree expr)
7705 { 8771 {
7706 if (expr) 8772 if (expr)
7707 return add_stmt (c_process_expr_stmt (expr)); 8773 return add_stmt (c_process_expr_stmt (loc, expr));
7708 else 8774 else
7709 return NULL; 8775 return NULL;
7710 } 8776 }
7711 8777
7712 /* Do the opposite and emit a statement as an expression. To begin, 8778 /* Do the opposite and emit a statement as an expression. To begin,
7714 8780
7715 tree 8781 tree
7716 c_begin_stmt_expr (void) 8782 c_begin_stmt_expr (void)
7717 { 8783 {
7718 tree ret; 8784 tree ret;
7719 struct c_label_context_se *nstack;
7720 struct c_label_list *glist;
7721 8785
7722 /* We must force a BLOCK for this level so that, if it is not expanded 8786 /* We must force a BLOCK for this level so that, if it is not expanded
7723 later, there is a way to turn off the entire subtree of blocks that 8787 later, there is a way to turn off the entire subtree of blocks that
7724 are contained in it. */ 8788 are contained in it. */
7725 keep_next_level (); 8789 keep_next_level ();
7726 ret = c_begin_compound_stmt (true); 8790 ret = c_begin_compound_stmt (true);
7727 if (c_switch_stack) 8791
7728 { 8792 c_bindings_start_stmt_expr (c_switch_stack == NULL
7729 c_switch_stack->blocked_stmt_expr++; 8793 ? NULL
7730 gcc_assert (c_switch_stack->blocked_stmt_expr != 0); 8794 : c_switch_stack->bindings);
7731 }
7732 for (glist = label_context_stack_se->labels_used;
7733 glist != NULL;
7734 glist = glist->next)
7735 {
7736 C_DECL_UNDEFINABLE_STMT_EXPR (glist->label) = 1;
7737 }
7738 nstack = XOBNEW (&parser_obstack, struct c_label_context_se);
7739 nstack->labels_def = NULL;
7740 nstack->labels_used = NULL;
7741 nstack->next = label_context_stack_se;
7742 label_context_stack_se = nstack;
7743 8795
7744 /* Mark the current statement list as belonging to a statement list. */ 8796 /* Mark the current statement list as belonging to a statement list. */
7745 STATEMENT_LIST_STMT_EXPR (ret) = 1; 8797 STATEMENT_LIST_STMT_EXPR (ret) = 1;
7746 8798
7747 return ret; 8799 return ret;
7748 } 8800 }
7749 8801
8802 /* LOC is the location of the compound statement to which this body
8803 belongs. */
8804
7750 tree 8805 tree
7751 c_finish_stmt_expr (tree body) 8806 c_finish_stmt_expr (location_t loc, tree body)
7752 { 8807 {
7753 tree last, type, tmp, val; 8808 tree last, type, tmp, val;
7754 tree *last_p; 8809 tree *last_p;
7755 struct c_label_list *dlist, *glist, *glist_prev = NULL; 8810
7756 8811 body = c_end_compound_stmt (loc, body, true);
7757 body = c_end_compound_stmt (body, true); 8812
7758 if (c_switch_stack) 8813 c_bindings_end_stmt_expr (c_switch_stack == NULL
7759 { 8814 ? NULL
7760 gcc_assert (c_switch_stack->blocked_stmt_expr != 0); 8815 : c_switch_stack->bindings);
7761 c_switch_stack->blocked_stmt_expr--;
7762 }
7763 /* It is no longer possible to jump to labels defined within this
7764 statement expression. */
7765 for (dlist = label_context_stack_se->labels_def;
7766 dlist != NULL;
7767 dlist = dlist->next)
7768 {
7769 C_DECL_UNJUMPABLE_STMT_EXPR (dlist->label) = 1;
7770 }
7771 /* It is again possible to define labels with a goto just outside
7772 this statement expression. */
7773 for (glist = label_context_stack_se->next->labels_used;
7774 glist != NULL;
7775 glist = glist->next)
7776 {
7777 C_DECL_UNDEFINABLE_STMT_EXPR (glist->label) = 0;
7778 glist_prev = glist;
7779 }
7780 if (glist_prev != NULL)
7781 glist_prev->next = label_context_stack_se->labels_used;
7782 else
7783 label_context_stack_se->next->labels_used
7784 = label_context_stack_se->labels_used;
7785 label_context_stack_se = label_context_stack_se->next;
7786 8816
7787 /* Locate the last statement in BODY. See c_end_compound_stmt 8817 /* Locate the last statement in BODY. See c_end_compound_stmt
7788 about always returning a BIND_EXPR. */ 8818 about always returning a BIND_EXPR. */
7789 last_p = &BIND_EXPR_BODY (body); 8819 last_p = &BIND_EXPR_BODY (body);
7790 last = BIND_EXPR_BODY (body); 8820 last = BIND_EXPR_BODY (body);
7801 /* If we're supposed to generate side effects warnings, process 8831 /* If we're supposed to generate side effects warnings, process
7802 all of the statements except the last. */ 8832 all of the statements except the last. */
7803 if (warn_unused_value) 8833 if (warn_unused_value)
7804 { 8834 {
7805 for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i)) 8835 for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i))
7806 emit_side_effect_warnings (tsi_stmt (i)); 8836 {
8837 location_t tloc;
8838 tree t = tsi_stmt (i);
8839
8840 tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc;
8841 emit_side_effect_warnings (tloc, t);
8842 }
7807 } 8843 }
7808 else 8844 else
7809 i = tsi_last (last); 8845 i = tsi_last (last);
7810 last_p = tsi_stmt_ptr (i); 8846 last_p = tsi_stmt_ptr (i);
7811 last = *last_p; 8847 last = *last_p;
7819 last_p = &TREE_OPERAND (last, 0); 8855 last_p = &TREE_OPERAND (last, 0);
7820 last = *last_p; 8856 last = *last_p;
7821 goto continue_searching; 8857 goto continue_searching;
7822 } 8858 }
7823 8859
8860 if (last == error_mark_node)
8861 return last;
8862
7824 /* In the case that the BIND_EXPR is not necessary, return the 8863 /* In the case that the BIND_EXPR is not necessary, return the
7825 expression out from inside it. */ 8864 expression out from inside it. */
7826 if (last == error_mark_node 8865 if (last == BIND_EXPR_BODY (body)
7827 || (last == BIND_EXPR_BODY (body) 8866 && BIND_EXPR_VARS (body) == NULL)
7828 && BIND_EXPR_VARS (body) == NULL)) 8867 {
7829 { 8868 /* Even if this looks constant, do not allow it in a constant
8869 expression. */
8870 last = c_wrap_maybe_const (last, true);
7830 /* Do not warn if the return value of a statement expression is 8871 /* Do not warn if the return value of a statement expression is
7831 unused. */ 8872 unused. */
7832 if (CAN_HAVE_LOCATION_P (last)) 8873 TREE_NO_WARNING (last) = 1;
7833 TREE_NO_WARNING (last) = 1;
7834 return last; 8874 return last;
7835 } 8875 }
7836 8876
7837 /* Extract the type of said expression. */ 8877 /* Extract the type of said expression. */
7838 type = TREE_TYPE (last); 8878 type = TREE_TYPE (last);
7853 if (TREE_CODE (val) == NOP_EXPR 8893 if (TREE_CODE (val) == NOP_EXPR
7854 && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))) 8894 && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
7855 val = TREE_OPERAND (val, 0); 8895 val = TREE_OPERAND (val, 0);
7856 8896
7857 *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val); 8897 *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
7858 SET_EXPR_LOCUS (*last_p, EXPR_LOCUS (last)); 8898 SET_EXPR_LOCATION (*last_p, EXPR_LOCATION (last));
7859 8899
7860 return build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE); 8900 {
7861 } 8901 tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
7862 8902 SET_EXPR_LOCATION (t, loc);
7863 /* Begin the scope of an identifier of variably modified type, scope 8903 return t;
7864 number SCOPE. Jumping from outside this scope to inside it is not 8904 }
7865 permitted. */
7866
7867 void
7868 c_begin_vm_scope (unsigned int scope)
7869 {
7870 struct c_label_context_vm *nstack;
7871 struct c_label_list *glist;
7872
7873 gcc_assert (scope > 0);
7874
7875 /* At file_scope, we don't have to do any processing. */
7876 if (label_context_stack_vm == NULL)
7877 return;
7878
7879 if (c_switch_stack && !c_switch_stack->blocked_vm)
7880 c_switch_stack->blocked_vm = scope;
7881 for (glist = label_context_stack_vm->labels_used;
7882 glist != NULL;
7883 glist = glist->next)
7884 {
7885 C_DECL_UNDEFINABLE_VM (glist->label) = 1;
7886 }
7887 nstack = XOBNEW (&parser_obstack, struct c_label_context_vm);
7888 nstack->labels_def = NULL;
7889 nstack->labels_used = NULL;
7890 nstack->scope = scope;
7891 nstack->next = label_context_stack_vm;
7892 label_context_stack_vm = nstack;
7893 }
7894
7895 /* End a scope which may contain identifiers of variably modified
7896 type, scope number SCOPE. */
7897
7898 void
7899 c_end_vm_scope (unsigned int scope)
7900 {
7901 if (label_context_stack_vm == NULL)
7902 return;
7903 if (c_switch_stack && c_switch_stack->blocked_vm == scope)
7904 c_switch_stack->blocked_vm = 0;
7905 /* We may have a number of nested scopes of identifiers with
7906 variably modified type, all at this depth. Pop each in turn. */
7907 while (label_context_stack_vm->scope == scope)
7908 {
7909 struct c_label_list *dlist, *glist, *glist_prev = NULL;
7910
7911 /* It is no longer possible to jump to labels defined within this
7912 scope. */
7913 for (dlist = label_context_stack_vm->labels_def;
7914 dlist != NULL;
7915 dlist = dlist->next)
7916 {
7917 C_DECL_UNJUMPABLE_VM (dlist->label) = 1;
7918 }
7919 /* It is again possible to define labels with a goto just outside
7920 this scope. */
7921 for (glist = label_context_stack_vm->next->labels_used;
7922 glist != NULL;
7923 glist = glist->next)
7924 {
7925 C_DECL_UNDEFINABLE_VM (glist->label) = 0;
7926 glist_prev = glist;
7927 }
7928 if (glist_prev != NULL)
7929 glist_prev->next = label_context_stack_vm->labels_used;
7930 else
7931 label_context_stack_vm->next->labels_used
7932 = label_context_stack_vm->labels_used;
7933 label_context_stack_vm = label_context_stack_vm->next;
7934 }
7935 } 8905 }
7936 8906
7937 /* Begin and end compound statements. This is as simple as pushing 8907 /* Begin and end compound statements. This is as simple as pushing
7938 and popping new statement lists from the tree. */ 8908 and popping new statement lists from the tree. */
7939 8909
7944 if (do_scope) 8914 if (do_scope)
7945 push_scope (); 8915 push_scope ();
7946 return stmt; 8916 return stmt;
7947 } 8917 }
7948 8918
8919 /* End a compound statement. STMT is the statement. LOC is the
8920 location of the compound statement-- this is usually the location
8921 of the opening brace. */
8922
7949 tree 8923 tree
7950 c_end_compound_stmt (tree stmt, bool do_scope) 8924 c_end_compound_stmt (location_t loc, tree stmt, bool do_scope)
7951 { 8925 {
7952 tree block = NULL; 8926 tree block = NULL;
7953 8927
7954 if (do_scope) 8928 if (do_scope)
7955 { 8929 {
7957 objc_clear_super_receiver (); 8931 objc_clear_super_receiver ();
7958 block = pop_scope (); 8932 block = pop_scope ();
7959 } 8933 }
7960 8934
7961 stmt = pop_stmt_list (stmt); 8935 stmt = pop_stmt_list (stmt);
7962 stmt = c_build_bind_expr (block, stmt); 8936 stmt = c_build_bind_expr (loc, block, stmt);
7963 8937
7964 /* If this compound statement is nested immediately inside a statement 8938 /* If this compound statement is nested immediately inside a statement
7965 expression, then force a BIND_EXPR to be created. Otherwise we'll 8939 expression, then force a BIND_EXPR to be created. Otherwise we'll
7966 do the wrong thing for ({ { 1; } }) or ({ 1; { } }). In particular, 8940 do the wrong thing for ({ { 1; } }) or ({ 1; { } }). In particular,
7967 STATEMENT_LISTs merge, and thus we can lose track of what statement 8941 STATEMENT_LISTs merge, and thus we can lose track of what statement
7970 && STATEMENT_LIST_STMT_EXPR (cur_stmt_list) 8944 && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
7971 && TREE_CODE (stmt) != BIND_EXPR) 8945 && TREE_CODE (stmt) != BIND_EXPR)
7972 { 8946 {
7973 stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL); 8947 stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
7974 TREE_SIDE_EFFECTS (stmt) = 1; 8948 TREE_SIDE_EFFECTS (stmt) = 1;
8949 SET_EXPR_LOCATION (stmt, loc);
7975 } 8950 }
7976 8951
7977 return stmt; 8952 return stmt;
7978 } 8953 }
7979 8954
7980 /* Queue a cleanup. CLEANUP is an expression/statement to be executed 8955 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
7981 when the current scope is exited. EH_ONLY is true when this is not 8956 when the current scope is exited. EH_ONLY is true when this is not
7982 meant to apply to normal control flow transfer. */ 8957 meant to apply to normal control flow transfer. */
7983 8958
7984 void 8959 void
7985 push_cleanup (tree ARG_UNUSED (decl), tree cleanup, bool eh_only) 8960 push_cleanup (tree decl, tree cleanup, bool eh_only)
7986 { 8961 {
7987 enum tree_code code; 8962 enum tree_code code;
7988 tree stmt, list; 8963 tree stmt, list;
7989 bool stmt_expr; 8964 bool stmt_expr;
7990 8965
7991 code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR; 8966 code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
7992 stmt = build_stmt (code, NULL, cleanup); 8967 stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup);
7993 add_stmt (stmt); 8968 add_stmt (stmt);
7994 stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list); 8969 stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
7995 list = push_stmt_list (); 8970 list = push_stmt_list ();
7996 TREE_OPERAND (stmt, 0) = list; 8971 TREE_OPERAND (stmt, 0) = list;
7997 STATEMENT_LIST_STMT_EXPR (list) = stmt_expr; 8972 STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
8015 8990
8016 tree 8991 tree
8017 build_binary_op (location_t location, enum tree_code code, 8992 build_binary_op (location_t location, enum tree_code code,
8018 tree orig_op0, tree orig_op1, int convert_p) 8993 tree orig_op0, tree orig_op1, int convert_p)
8019 { 8994 {
8020 tree type0, type1; 8995 tree type0, type1, orig_type0, orig_type1;
8996 tree eptype;
8021 enum tree_code code0, code1; 8997 enum tree_code code0, code1;
8022 tree op0, op1; 8998 tree op0, op1;
8023 tree ret = error_mark_node; 8999 tree ret = error_mark_node;
8024 const char *invalid_op_diag; 9000 const char *invalid_op_diag;
9001 bool op0_int_operands, op1_int_operands;
9002 bool int_const, int_const_or_overflow, int_operands;
8025 9003
8026 /* Expression code to give to the expression when it is built. 9004 /* Expression code to give to the expression when it is built.
8027 Normally this is CODE, which is what the caller asked for, 9005 Normally this is CODE, which is what the caller asked for,
8028 but in some special cases we change it. */ 9006 but in some special cases we change it. */
8029 enum tree_code resultcode = code; 9007 enum tree_code resultcode = code;
8030 9008
8031 /* Data type in which the computation is to be performed. 9009 /* Data type in which the computation is to be performed.
8032 In the simplest cases this is the common type of the arguments. */ 9010 In the simplest cases this is the common type of the arguments. */
8033 tree result_type = NULL; 9011 tree result_type = NULL;
9012
9013 /* When the computation is in excess precision, the type of the
9014 final EXCESS_PRECISION_EXPR. */
9015 tree real_result_type = NULL;
8034 9016
8035 /* Nonzero means operands have already been type-converted 9017 /* Nonzero means operands have already been type-converted
8036 in whatever way is necessary. 9018 in whatever way is necessary.
8037 Zero means they need to be converted to RESULT_TYPE. */ 9019 Zero means they need to be converted to RESULT_TYPE. */
8038 int converted = 0; 9020 int converted = 0;
8066 int common = 0; 9048 int common = 0;
8067 9049
8068 /* True means types are compatible as far as ObjC is concerned. */ 9050 /* True means types are compatible as far as ObjC is concerned. */
8069 bool objc_ok; 9051 bool objc_ok;
8070 9052
9053 /* True means this is an arithmetic operation that may need excess
9054 precision. */
9055 bool may_need_excess_precision;
9056
8071 if (location == UNKNOWN_LOCATION) 9057 if (location == UNKNOWN_LOCATION)
8072 location = input_location; 9058 location = input_location;
8073 9059
9060 op0 = orig_op0;
9061 op1 = orig_op1;
9062
9063 op0_int_operands = EXPR_INT_CONST_OPERANDS (orig_op0);
9064 if (op0_int_operands)
9065 op0 = remove_c_maybe_const_expr (op0);
9066 op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
9067 if (op1_int_operands)
9068 op1 = remove_c_maybe_const_expr (op1);
9069 int_operands = (op0_int_operands && op1_int_operands);
9070 if (int_operands)
9071 {
9072 int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST
9073 && TREE_CODE (orig_op1) == INTEGER_CST);
9074 int_const = (int_const_or_overflow
9075 && !TREE_OVERFLOW (orig_op0)
9076 && !TREE_OVERFLOW (orig_op1));
9077 }
9078 else
9079 int_const = int_const_or_overflow = false;
9080
8074 if (convert_p) 9081 if (convert_p)
8075 { 9082 {
8076 op0 = default_conversion (orig_op0); 9083 op0 = default_conversion (op0);
8077 op1 = default_conversion (orig_op1); 9084 op1 = default_conversion (op1);
8078 } 9085 }
8079 else 9086
8080 { 9087 orig_type0 = type0 = TREE_TYPE (op0);
8081 op0 = orig_op0; 9088 orig_type1 = type1 = TREE_TYPE (op1);
8082 op1 = orig_op1;
8083 }
8084
8085 type0 = TREE_TYPE (op0);
8086 type1 = TREE_TYPE (op1);
8087 9089
8088 /* The expression codes of the data types of the arguments tell us 9090 /* The expression codes of the data types of the arguments tell us
8089 whether the arguments are integers, floating, pointers, etc. */ 9091 whether the arguments are integers, floating, pointers, etc. */
8090 code0 = TREE_CODE (type0); 9092 code0 = TREE_CODE (type0);
8091 code1 = TREE_CODE (type1); 9093 code1 = TREE_CODE (type1);
8105 { 9107 {
8106 error_at (location, invalid_op_diag); 9108 error_at (location, invalid_op_diag);
8107 return error_mark_node; 9109 return error_mark_node;
8108 } 9110 }
8109 9111
9112 switch (code)
9113 {
9114 case PLUS_EXPR:
9115 case MINUS_EXPR:
9116 case MULT_EXPR:
9117 case TRUNC_DIV_EXPR:
9118 case CEIL_DIV_EXPR:
9119 case FLOOR_DIV_EXPR:
9120 case ROUND_DIV_EXPR:
9121 case EXACT_DIV_EXPR:
9122 may_need_excess_precision = true;
9123 break;
9124 default:
9125 may_need_excess_precision = false;
9126 break;
9127 }
9128 if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
9129 {
9130 op0 = TREE_OPERAND (op0, 0);
9131 type0 = TREE_TYPE (op0);
9132 }
9133 else if (may_need_excess_precision
9134 && (eptype = excess_precision_type (type0)) != NULL_TREE)
9135 {
9136 type0 = eptype;
9137 op0 = convert (eptype, op0);
9138 }
9139 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
9140 {
9141 op1 = TREE_OPERAND (op1, 0);
9142 type1 = TREE_TYPE (op1);
9143 }
9144 else if (may_need_excess_precision
9145 && (eptype = excess_precision_type (type1)) != NULL_TREE)
9146 {
9147 type1 = eptype;
9148 op1 = convert (eptype, op1);
9149 }
9150
8110 objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE); 9151 objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
8111 9152
8112 switch (code) 9153 switch (code)
8113 { 9154 {
8114 case PLUS_EXPR: 9155 case PLUS_EXPR:
8115 /* Handle the pointer + int case. */ 9156 /* Handle the pointer + int case. */
8116 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) 9157 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
8117 { 9158 {
8118 ret = pointer_int_sum (PLUS_EXPR, op0, op1); 9159 ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
8119 goto return_build_binary_op; 9160 goto return_build_binary_op;
8120 } 9161 }
8121 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE) 9162 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
8122 { 9163 {
8123 ret = pointer_int_sum (PLUS_EXPR, op1, op0); 9164 ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
8124 goto return_build_binary_op; 9165 goto return_build_binary_op;
8125 } 9166 }
8126 else 9167 else
8127 common = 1; 9168 common = 1;
8128 break; 9169 break;
8129 9170
8130 case MINUS_EXPR: 9171 case MINUS_EXPR:
8131 /* Subtraction of two similar pointers. 9172 /* Subtraction of two similar pointers.
8132 We must subtract them as integers, then divide by object size. */ 9173 We must subtract them as integers, then divide by object size. */
8133 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE 9174 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
8134 && comp_target_types (type0, type1)) 9175 && comp_target_types (location, type0, type1))
8135 { 9176 {
8136 ret = pointer_diff (op0, op1); 9177 ret = pointer_diff (location, op0, op1);
8137 goto return_build_binary_op; 9178 goto return_build_binary_op;
8138 } 9179 }
8139 /* Handle pointer minus int. Just like pointer plus int. */ 9180 /* Handle pointer minus int. Just like pointer plus int. */
8140 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) 9181 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
8141 { 9182 {
8142 ret = pointer_int_sum (MINUS_EXPR, op0, op1); 9183 ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
8143 goto return_build_binary_op; 9184 goto return_build_binary_op;
8144 } 9185 }
8145 else 9186 else
8146 common = 1; 9187 common = 1;
8147 break; 9188 break;
8202 9243
8203 case TRUNC_MOD_EXPR: 9244 case TRUNC_MOD_EXPR:
8204 case FLOOR_MOD_EXPR: 9245 case FLOOR_MOD_EXPR:
8205 warn_for_div_by_zero (location, op1); 9246 warn_for_div_by_zero (location, op1);
8206 9247
8207 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) 9248 if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
9249 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
9250 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
9251 common = 1;
9252 else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
8208 { 9253 {
8209 /* Although it would be tempting to shorten always here, that loses 9254 /* Although it would be tempting to shorten always here, that loses
8210 on some targets, since the modulo instruction is undefined if the 9255 on some targets, since the modulo instruction is undefined if the
8211 quotient can't be represented in the computation mode. We shorten 9256 quotient can't be represented in the computation mode. We shorten
8212 only if unsigned or if dividing by something we know != -1. */ 9257 only if unsigned or if dividing by something we know != -1. */
8235 result_type = integer_type_node; 9280 result_type = integer_type_node;
8236 op0 = c_common_truthvalue_conversion (location, op0); 9281 op0 = c_common_truthvalue_conversion (location, op0);
8237 op1 = c_common_truthvalue_conversion (location, op1); 9282 op1 = c_common_truthvalue_conversion (location, op1);
8238 converted = 1; 9283 converted = 1;
8239 } 9284 }
9285 if (code == TRUTH_ANDIF_EXPR)
9286 {
9287 int_const_or_overflow = (int_operands
9288 && TREE_CODE (orig_op0) == INTEGER_CST
9289 && (op0 == truthvalue_false_node
9290 || TREE_CODE (orig_op1) == INTEGER_CST));
9291 int_const = (int_const_or_overflow
9292 && !TREE_OVERFLOW (orig_op0)
9293 && (op0 == truthvalue_false_node
9294 || !TREE_OVERFLOW (orig_op1)));
9295 }
9296 else if (code == TRUTH_ORIF_EXPR)
9297 {
9298 int_const_or_overflow = (int_operands
9299 && TREE_CODE (orig_op0) == INTEGER_CST
9300 && (op0 == truthvalue_true_node
9301 || TREE_CODE (orig_op1) == INTEGER_CST));
9302 int_const = (int_const_or_overflow
9303 && !TREE_OVERFLOW (orig_op0)
9304 && (op0 == truthvalue_true_node
9305 || !TREE_OVERFLOW (orig_op1)));
9306 }
8240 break; 9307 break;
8241 9308
8242 /* Shift operations: result has same type as first operand; 9309 /* Shift operations: result has same type as first operand;
8243 always convert second operand to int. 9310 always convert second operand to int.
8244 Also set SHORT_SHIFT if shifting rightward. */ 9311 Also set SHORT_SHIFT if shifting rightward. */
8245 9312
8246 case RSHIFT_EXPR: 9313 case RSHIFT_EXPR:
8247 if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE) 9314 if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE)
8248 && code1 == INTEGER_TYPE) 9315 && code1 == INTEGER_TYPE)
8249 { 9316 {
8250 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0) 9317 if (TREE_CODE (op1) == INTEGER_CST)
8251 { 9318 {
8252 if (tree_int_cst_sgn (op1) < 0) 9319 if (tree_int_cst_sgn (op1) < 0)
8253 warning (0, "right shift count is negative"); 9320 {
9321 int_const = false;
9322 if (c_inhibit_evaluation_warnings == 0)
9323 warning (0, "right shift count is negative");
9324 }
8254 else 9325 else
8255 { 9326 {
8256 if (!integer_zerop (op1)) 9327 if (!integer_zerop (op1))
8257 short_shift = 1; 9328 short_shift = 1;
8258 9329
8259 if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0) 9330 if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
8260 warning (0, "right shift count >= width of type"); 9331 {
9332 int_const = false;
9333 if (c_inhibit_evaluation_warnings == 0)
9334 warning (0, "right shift count >= width of type");
9335 }
8261 } 9336 }
8262 } 9337 }
8263 9338
8264 /* Use the type of the value to be shifted. */ 9339 /* Use the type of the value to be shifted. */
8265 result_type = type0; 9340 result_type = type0;
8274 9349
8275 case LSHIFT_EXPR: 9350 case LSHIFT_EXPR:
8276 if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE) 9351 if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE)
8277 && code1 == INTEGER_TYPE) 9352 && code1 == INTEGER_TYPE)
8278 { 9353 {
8279 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0) 9354 if (TREE_CODE (op1) == INTEGER_CST)
8280 { 9355 {
8281 if (tree_int_cst_sgn (op1) < 0) 9356 if (tree_int_cst_sgn (op1) < 0)
8282 warning (0, "left shift count is negative"); 9357 {
9358 int_const = false;
9359 if (c_inhibit_evaluation_warnings == 0)
9360 warning (0, "left shift count is negative");
9361 }
8283 9362
8284 else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0) 9363 else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
8285 warning (0, "left shift count >= width of type"); 9364 {
9365 int_const = false;
9366 if (c_inhibit_evaluation_warnings == 0)
9367 warning (0, "left shift count >= width of type");
9368 }
8286 } 9369 }
8287 9370
8288 /* Use the type of the value to be shifted. */ 9371 /* Use the type of the value to be shifted. */
8289 result_type = type0; 9372 result_type = type0;
8290 /* Convert the shift-count to an integer, regardless of size 9373 /* Convert the shift-count to an integer, regardless of size
8312 short_compare = 1; 9395 short_compare = 1;
8313 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) 9396 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
8314 { 9397 {
8315 tree tt0 = TREE_TYPE (type0); 9398 tree tt0 = TREE_TYPE (type0);
8316 tree tt1 = TREE_TYPE (type1); 9399 tree tt1 = TREE_TYPE (type1);
9400 addr_space_t as0 = TYPE_ADDR_SPACE (tt0);
9401 addr_space_t as1 = TYPE_ADDR_SPACE (tt1);
9402 addr_space_t as_common = ADDR_SPACE_GENERIC;
9403
8317 /* Anything compares with void *. void * compares with anything. 9404 /* Anything compares with void *. void * compares with anything.
8318 Otherwise, the targets must be compatible 9405 Otherwise, the targets must be compatible
8319 and both must be object or both incomplete. */ 9406 and both must be object or both incomplete. */
8320 if (comp_target_types (type0, type1)) 9407 if (comp_target_types (location, type0, type1))
8321 result_type = common_pointer_type (type0, type1); 9408 result_type = common_pointer_type (type0, type1);
9409 else if (null_pointer_constant_p (orig_op0))
9410 result_type = type1;
9411 else if (null_pointer_constant_p (orig_op1))
9412 result_type = type0;
9413 else if (!addr_space_superset (as0, as1, &as_common))
9414 {
9415 error_at (location, "comparison of pointers to "
9416 "disjoint address spaces");
9417 return error_mark_node;
9418 }
8322 else if (VOID_TYPE_P (tt0)) 9419 else if (VOID_TYPE_P (tt0))
8323 { 9420 {
8324 /* op0 != orig_op0 detects the case of something 9421 if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
8325 whose value is 0 but which isn't a valid null ptr const. */
8326 if (pedantic && !null_pointer_constant_p (orig_op0)
8327 && TREE_CODE (tt1) == FUNCTION_TYPE)
8328 pedwarn (location, OPT_pedantic, "ISO C forbids " 9422 pedwarn (location, OPT_pedantic, "ISO C forbids "
8329 "comparison of %<void *%> with function pointer"); 9423 "comparison of %<void *%> with function pointer");
8330 } 9424 }
8331 else if (VOID_TYPE_P (tt1)) 9425 else if (VOID_TYPE_P (tt1))
8332 { 9426 {
8333 if (pedantic && !null_pointer_constant_p (orig_op1) 9427 if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
8334 && TREE_CODE (tt0) == FUNCTION_TYPE)
8335 pedwarn (location, OPT_pedantic, "ISO C forbids " 9428 pedwarn (location, OPT_pedantic, "ISO C forbids "
8336 "comparison of %<void *%> with function pointer"); 9429 "comparison of %<void *%> with function pointer");
8337 } 9430 }
8338 else 9431 else
8339 /* Avoid warning about the volatile ObjC EH puts on decls. */ 9432 /* Avoid warning about the volatile ObjC EH puts on decls. */
8340 if (!objc_ok) 9433 if (!objc_ok)
8341 pedwarn (location, 0, 9434 pedwarn (location, 0,
8342 "comparison of distinct pointer types lacks a cast"); 9435 "comparison of distinct pointer types lacks a cast");
8343 9436
8344 if (result_type == NULL_TREE) 9437 if (result_type == NULL_TREE)
8345 result_type = ptr_type_node; 9438 {
9439 int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
9440 result_type = build_pointer_type
9441 (build_qualified_type (void_type_node, qual));
9442 }
8346 } 9443 }
8347 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1)) 9444 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
8348 { 9445 {
8349 if (TREE_CODE (op0) == ADDR_EXPR 9446 if (TREE_CODE (op0) == ADDR_EXPR
8350 && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0))) 9447 && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0)))
8384 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE 9481 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
8385 || code1 == FIXED_POINT_TYPE)) 9482 || code1 == FIXED_POINT_TYPE))
8386 short_compare = 1; 9483 short_compare = 1;
8387 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) 9484 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
8388 { 9485 {
8389 if (comp_target_types (type0, type1)) 9486 addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0));
9487 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
9488 addr_space_t as_common;
9489
9490 if (comp_target_types (location, type0, type1))
8390 { 9491 {
8391 result_type = common_pointer_type (type0, type1); 9492 result_type = common_pointer_type (type0, type1);
8392 if (!COMPLETE_TYPE_P (TREE_TYPE (type0)) 9493 if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
8393 != !COMPLETE_TYPE_P (TREE_TYPE (type1))) 9494 != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
8394 pedwarn (location, 0, 9495 pedwarn (location, 0,
8395 "comparison of complete and incomplete pointers"); 9496 "comparison of complete and incomplete pointers");
8396 else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE) 9497 else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
8397 pedwarn (location, OPT_pedantic, "ISO C forbids " 9498 pedwarn (location, OPT_pedantic, "ISO C forbids "
8398 "ordered comparisons of pointers to functions"); 9499 "ordered comparisons of pointers to functions");
8399 } 9500 }
9501 else if (!addr_space_superset (as0, as1, &as_common))
9502 {
9503 error_at (location, "comparison of pointers to "
9504 "disjoint address spaces");
9505 return error_mark_node;
9506 }
8400 else 9507 else
8401 { 9508 {
8402 result_type = ptr_type_node; 9509 int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
9510 result_type = build_pointer_type
9511 (build_qualified_type (void_type_node, qual));
8403 pedwarn (location, 0, 9512 pedwarn (location, 0,
8404 "comparison of distinct pointer types lacks a cast"); 9513 "comparison of distinct pointer types lacks a cast");
8405 } 9514 }
8406 } 9515 }
8407 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1)) 9516 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
8408 { 9517 {
8409 result_type = type0; 9518 result_type = type0;
8410 if (pedantic) 9519 if (pedantic)
8411 pedwarn (location, OPT_pedantic, 9520 pedwarn (location, OPT_pedantic,
8412 "ordered comparison of pointer with integer zero"); 9521 "ordered comparison of pointer with integer zero");
8413 else if (extra_warnings) 9522 else if (extra_warnings)
8414 warning_at (location, OPT_Wextra, 9523 warning_at (location, OPT_Wextra,
8415 "ordered comparison of pointer with integer zero"); 9524 "ordered comparison of pointer with integer zero");
8416 } 9525 }
8417 else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0)) 9526 else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
8418 { 9527 {
8419 result_type = type1; 9528 result_type = type1;
8420 pedwarn (location, OPT_pedantic, 9529 pedwarn (location, OPT_pedantic,
8421 "ordered comparison of pointer with integer zero"); 9530 "ordered comparison of pointer with integer zero");
8422 } 9531 }
8423 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) 9532 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
8424 { 9533 {
8425 result_type = type0; 9534 result_type = type0;
8452 || code0 == FIXED_POINT_TYPE || code0 == VECTOR_TYPE) 9561 || code0 == FIXED_POINT_TYPE || code0 == VECTOR_TYPE)
8453 && 9562 &&
8454 (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE 9563 (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
8455 || code1 == FIXED_POINT_TYPE || code1 == VECTOR_TYPE)) 9564 || code1 == FIXED_POINT_TYPE || code1 == VECTOR_TYPE))
8456 { 9565 {
8457 int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE); 9566 bool first_complex = (code0 == COMPLEX_TYPE);
9567 bool second_complex = (code1 == COMPLEX_TYPE);
9568 int none_complex = (!first_complex && !second_complex);
8458 9569
8459 if (shorten || common || short_compare) 9570 if (shorten || common || short_compare)
8460 { 9571 {
8461 result_type = c_common_type (type0, type1); 9572 result_type = c_common_type (type0, type1);
8462 if (result_type == error_mark_node) 9573 if (result_type == error_mark_node)
8463 return error_mark_node; 9574 return error_mark_node;
9575 }
9576
9577 if (first_complex != second_complex
9578 && (code == PLUS_EXPR
9579 || code == MINUS_EXPR
9580 || code == MULT_EXPR
9581 || (code == TRUNC_DIV_EXPR && first_complex))
9582 && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
9583 && flag_signed_zeros)
9584 {
9585 /* An operation on mixed real/complex operands must be
9586 handled specially, but the language-independent code can
9587 more easily optimize the plain complex arithmetic if
9588 -fno-signed-zeros. */
9589 tree real_type = TREE_TYPE (result_type);
9590 tree real, imag;
9591 if (type0 != orig_type0 || type1 != orig_type1)
9592 {
9593 gcc_assert (may_need_excess_precision && common);
9594 real_result_type = c_common_type (orig_type0, orig_type1);
9595 }
9596 if (first_complex)
9597 {
9598 if (TREE_TYPE (op0) != result_type)
9599 op0 = convert_and_check (result_type, op0);
9600 if (TREE_TYPE (op1) != real_type)
9601 op1 = convert_and_check (real_type, op1);
9602 }
9603 else
9604 {
9605 if (TREE_TYPE (op0) != real_type)
9606 op0 = convert_and_check (real_type, op0);
9607 if (TREE_TYPE (op1) != result_type)
9608 op1 = convert_and_check (result_type, op1);
9609 }
9610 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
9611 return error_mark_node;
9612 if (first_complex)
9613 {
9614 op0 = c_save_expr (op0);
9615 real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR,
9616 op0, 1);
9617 imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR,
9618 op0, 1);
9619 switch (code)
9620 {
9621 case MULT_EXPR:
9622 case TRUNC_DIV_EXPR:
9623 imag = build2 (resultcode, real_type, imag, op1);
9624 /* Fall through. */
9625 case PLUS_EXPR:
9626 case MINUS_EXPR:
9627 real = build2 (resultcode, real_type, real, op1);
9628 break;
9629 default:
9630 gcc_unreachable();
9631 }
9632 }
9633 else
9634 {
9635 op1 = c_save_expr (op1);
9636 real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR,
9637 op1, 1);
9638 imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR,
9639 op1, 1);
9640 switch (code)
9641 {
9642 case MULT_EXPR:
9643 imag = build2 (resultcode, real_type, op0, imag);
9644 /* Fall through. */
9645 case PLUS_EXPR:
9646 real = build2 (resultcode, real_type, op0, real);
9647 break;
9648 case MINUS_EXPR:
9649 real = build2 (resultcode, real_type, op0, real);
9650 imag = build1 (NEGATE_EXPR, real_type, imag);
9651 break;
9652 default:
9653 gcc_unreachable();
9654 }
9655 }
9656 ret = build2 (COMPLEX_EXPR, result_type, real, imag);
9657 goto return_build_binary_op;
8464 } 9658 }
8465 9659
8466 /* For certain operations (which identify themselves by shorten != 0) 9660 /* For certain operations (which identify themselves by shorten != 0)
8467 if both args were extended from the same smaller type, 9661 if both args were extended from the same smaller type,
8468 do the arithmetic in that type and then extend. 9662 do the arithmetic in that type and then extend.
8475 but calculated in (unsigned short) it would be (unsigned short)-1. */ 9669 but calculated in (unsigned short) it would be (unsigned short)-1. */
8476 9670
8477 if (shorten && none_complex) 9671 if (shorten && none_complex)
8478 { 9672 {
8479 final_type = result_type; 9673 final_type = result_type;
8480 result_type = shorten_binary_op (result_type, op0, op1, 9674 result_type = shorten_binary_op (result_type, op0, op1,
8481 shorten == -1); 9675 shorten == -1);
8482 } 9676 }
8483 9677
8484 /* Shifts can be shortened if shifting right. */ 9678 /* Shifts can be shortened if shifting right. */
8485 9679
8534 9728
8535 op0 = xop0, op1 = xop1; 9729 op0 = xop0, op1 = xop1;
8536 converted = 1; 9730 converted = 1;
8537 resultcode = xresultcode; 9731 resultcode = xresultcode;
8538 9732
8539 if (warn_sign_compare && !skip_evaluation) 9733 if (c_inhibit_evaluation_warnings == 0)
8540 { 9734 {
8541 warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1, 9735 bool op0_maybe_const = true;
8542 result_type, resultcode); 9736 bool op1_maybe_const = true;
9737 tree orig_op0_folded, orig_op1_folded;
9738
9739 if (in_late_binary_op)
9740 {
9741 orig_op0_folded = orig_op0;
9742 orig_op1_folded = orig_op1;
9743 }
9744 else
9745 {
9746 /* Fold for the sake of possible warnings, as in
9747 build_conditional_expr. This requires the
9748 "original" values to be folded, not just op0 and
9749 op1. */
9750 c_inhibit_evaluation_warnings++;
9751 op0 = c_fully_fold (op0, require_constant_value,
9752 &op0_maybe_const);
9753 op1 = c_fully_fold (op1, require_constant_value,
9754 &op1_maybe_const);
9755 c_inhibit_evaluation_warnings--;
9756 orig_op0_folded = c_fully_fold (orig_op0,
9757 require_constant_value,
9758 NULL);
9759 orig_op1_folded = c_fully_fold (orig_op1,
9760 require_constant_value,
9761 NULL);
9762 }
9763
9764 if (warn_sign_compare)
9765 warn_for_sign_compare (location, orig_op0_folded,
9766 orig_op1_folded, op0, op1,
9767 result_type, resultcode);
9768 if (!in_late_binary_op)
9769 {
9770 if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
9771 op0 = c_wrap_maybe_const (op0, !op0_maybe_const);
9772 if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
9773 op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
9774 }
8543 } 9775 }
8544 } 9776 }
8545 } 9777 }
8546 9778
8547 /* At this point, RESULT_TYPE must be nonzero to avoid an error message. 9779 /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
8568 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK) 9800 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
8569 return error_mark_node; 9801 return error_mark_node;
8570 } 9802 }
8571 9803
8572 if (build_type == NULL_TREE) 9804 if (build_type == NULL_TREE)
8573 build_type = result_type; 9805 {
9806 build_type = result_type;
9807 if (type0 != orig_type0 || type1 != orig_type1)
9808 {
9809 gcc_assert (may_need_excess_precision && common);
9810 real_result_type = c_common_type (orig_type0, orig_type1);
9811 }
9812 }
8574 9813
8575 /* Treat expressions in initializers specially as they can't trap. */ 9814 /* Treat expressions in initializers specially as they can't trap. */
8576 ret = require_constant_value ? fold_build2_initializer (resultcode, 9815 if (int_const_or_overflow)
8577 build_type, 9816 ret = (require_constant_value
8578 op0, op1) 9817 ? fold_build2_initializer_loc (location, resultcode, build_type,
8579 : fold_build2 (resultcode, build_type, 9818 op0, op1)
8580 op0, op1); 9819 : fold_build2_loc (location, resultcode, build_type, op0, op1));
9820 else
9821 ret = build2 (resultcode, build_type, op0, op1);
8581 if (final_type != 0) 9822 if (final_type != 0)
8582 ret = convert (final_type, ret); 9823 ret = convert (final_type, ret);
8583 9824
8584 return_build_binary_op: 9825 return_build_binary_op:
8585 gcc_assert (ret != error_mark_node); 9826 gcc_assert (ret != error_mark_node);
9827 if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const)
9828 ret = (int_operands
9829 ? note_integer_operands (ret)
9830 : build1 (NOP_EXPR, TREE_TYPE (ret), ret));
9831 else if (TREE_CODE (ret) != INTEGER_CST && int_operands
9832 && !in_late_binary_op)
9833 ret = note_integer_operands (ret);
9834 if (real_result_type)
9835 ret = build1 (EXCESS_PRECISION_EXPR, real_result_type, ret);
8586 protected_set_expr_location (ret, location); 9836 protected_set_expr_location (ret, location);
8587 return ret; 9837 return ret;
8588 } 9838 }
8589 9839
8590 9840
8592 purpose. LOCATION is the source location for the expression. */ 9842 purpose. LOCATION is the source location for the expression. */
8593 9843
8594 tree 9844 tree
8595 c_objc_common_truthvalue_conversion (location_t location, tree expr) 9845 c_objc_common_truthvalue_conversion (location_t location, tree expr)
8596 { 9846 {
9847 bool int_const, int_operands;
9848
8597 switch (TREE_CODE (TREE_TYPE (expr))) 9849 switch (TREE_CODE (TREE_TYPE (expr)))
8598 { 9850 {
8599 case ARRAY_TYPE: 9851 case ARRAY_TYPE:
8600 error_at (location, "used array that cannot be converted to pointer where scalar is required"); 9852 error_at (location, "used array that cannot be converted to pointer where scalar is required");
8601 return error_mark_node; 9853 return error_mark_node;
8613 9865
8614 default: 9866 default:
8615 break; 9867 break;
8616 } 9868 }
8617 9869
9870 int_const = (TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr));
9871 int_operands = EXPR_INT_CONST_OPERANDS (expr);
9872 if (int_operands)
9873 expr = remove_c_maybe_const_expr (expr);
9874
8618 /* ??? Should we also give an error for void and vectors rather than 9875 /* ??? Should we also give an error for void and vectors rather than
8619 leaving those to give errors later? */ 9876 leaving those to give errors later? */
8620 return c_common_truthvalue_conversion (location, expr); 9877 expr = c_common_truthvalue_conversion (location, expr);
9878
9879 if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
9880 {
9881 if (TREE_OVERFLOW (expr))
9882 return expr;
9883 else
9884 return note_integer_operands (expr);
9885 }
9886 if (TREE_CODE (expr) == INTEGER_CST && !int_const)
9887 return build1 (NOP_EXPR, TREE_TYPE (expr), expr);
9888 return expr;
8621 } 9889 }
8622 9890
8623 9891
8624 /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as 9892 /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
8625 required. */ 9893 required. */
8651 block = c_begin_compound_stmt (true); 9919 block = c_begin_compound_stmt (true);
8652 9920
8653 return block; 9921 return block;
8654 } 9922 }
8655 9923
8656 /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound statement. */ 9924 /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
9925 statement. LOC is the location of the OMP_PARALLEL. */
8657 9926
8658 tree 9927 tree
8659 c_finish_omp_parallel (tree clauses, tree block) 9928 c_finish_omp_parallel (location_t loc, tree clauses, tree block)
8660 { 9929 {
8661 tree stmt; 9930 tree stmt;
8662 9931
8663 block = c_end_compound_stmt (block, true); 9932 block = c_end_compound_stmt (loc, block, true);
8664 9933
8665 stmt = make_node (OMP_PARALLEL); 9934 stmt = make_node (OMP_PARALLEL);
8666 TREE_TYPE (stmt) = void_type_node; 9935 TREE_TYPE (stmt) = void_type_node;
8667 OMP_PARALLEL_CLAUSES (stmt) = clauses; 9936 OMP_PARALLEL_CLAUSES (stmt) = clauses;
8668 OMP_PARALLEL_BODY (stmt) = block; 9937 OMP_PARALLEL_BODY (stmt) = block;
9938 SET_EXPR_LOCATION (stmt, loc);
8669 9939
8670 return add_stmt (stmt); 9940 return add_stmt (stmt);
8671 } 9941 }
8672 9942
8673 /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */ 9943 /* Like c_begin_compound_stmt, except force the retention of the BLOCK. */
8681 block = c_begin_compound_stmt (true); 9951 block = c_begin_compound_stmt (true);
8682 9952
8683 return block; 9953 return block;
8684 } 9954 }
8685 9955
8686 /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound statement. */ 9956 /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
9957 statement. LOC is the location of the #pragma. */
8687 9958
8688 tree 9959 tree
8689 c_finish_omp_task (tree clauses, tree block) 9960 c_finish_omp_task (location_t loc, tree clauses, tree block)
8690 { 9961 {
8691 tree stmt; 9962 tree stmt;
8692 9963
8693 block = c_end_compound_stmt (block, true); 9964 block = c_end_compound_stmt (loc, block, true);
8694 9965
8695 stmt = make_node (OMP_TASK); 9966 stmt = make_node (OMP_TASK);
8696 TREE_TYPE (stmt) = void_type_node; 9967 TREE_TYPE (stmt) = void_type_node;
8697 OMP_TASK_CLAUSES (stmt) = clauses; 9968 OMP_TASK_CLAUSES (stmt) = clauses;
8698 OMP_TASK_BODY (stmt) = block; 9969 OMP_TASK_BODY (stmt) = block;
9970 SET_EXPR_LOCATION (stmt, loc);
8699 9971
8700 return add_stmt (stmt); 9972 return add_stmt (stmt);
8701 } 9973 }
8702 9974
8703 /* For all elements of CLAUSES, validate them vs OpenMP constraints. 9975 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
8739 need_implicitly_determined = true; 10011 need_implicitly_determined = true;
8740 t = OMP_CLAUSE_DECL (c); 10012 t = OMP_CLAUSE_DECL (c);
8741 if (AGGREGATE_TYPE_P (TREE_TYPE (t)) 10013 if (AGGREGATE_TYPE_P (TREE_TYPE (t))
8742 || POINTER_TYPE_P (TREE_TYPE (t))) 10014 || POINTER_TYPE_P (TREE_TYPE (t)))
8743 { 10015 {
8744 error ("%qE has invalid type for %<reduction%>", t); 10016 error_at (OMP_CLAUSE_LOCATION (c),
10017 "%qE has invalid type for %<reduction%>", t);
8745 remove = true; 10018 remove = true;
8746 } 10019 }
8747 else if (FLOAT_TYPE_P (TREE_TYPE (t))) 10020 else if (FLOAT_TYPE_P (TREE_TYPE (t)))
8748 { 10021 {
8749 enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c); 10022 enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
8773 default: 10046 default:
8774 gcc_unreachable (); 10047 gcc_unreachable ();
8775 } 10048 }
8776 if (r_name) 10049 if (r_name)
8777 { 10050 {
8778 error ("%qE has invalid type for %<reduction(%s)%>", 10051 error_at (OMP_CLAUSE_LOCATION (c),
8779 t, r_name); 10052 "%qE has invalid type for %<reduction(%s)%>",
10053 t, r_name);
8780 remove = true; 10054 remove = true;
8781 } 10055 }
8782 } 10056 }
8783 goto check_dup_generic; 10057 goto check_dup_generic;
8784 10058
8789 case OMP_CLAUSE_COPYIN: 10063 case OMP_CLAUSE_COPYIN:
8790 name = "copyin"; 10064 name = "copyin";
8791 t = OMP_CLAUSE_DECL (c); 10065 t = OMP_CLAUSE_DECL (c);
8792 if (TREE_CODE (t) != VAR_DECL || !DECL_THREAD_LOCAL_P (t)) 10066 if (TREE_CODE (t) != VAR_DECL || !DECL_THREAD_LOCAL_P (t))
8793 { 10067 {
8794 error ("%qE must be %<threadprivate%> for %<copyin%>", t); 10068 error_at (OMP_CLAUSE_LOCATION (c),
10069 "%qE must be %<threadprivate%> for %<copyin%>", t);
8795 remove = true; 10070 remove = true;
8796 } 10071 }
8797 goto check_dup_generic; 10072 goto check_dup_generic;
8798 10073
8799 check_dup_generic: 10074 check_dup_generic:
8800 t = OMP_CLAUSE_DECL (c); 10075 t = OMP_CLAUSE_DECL (c);
8801 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) 10076 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
8802 { 10077 {
8803 error ("%qE is not a variable in clause %qs", t, name); 10078 error_at (OMP_CLAUSE_LOCATION (c),
10079 "%qE is not a variable in clause %qs", t, name);
8804 remove = true; 10080 remove = true;
8805 } 10081 }
8806 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 10082 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8807 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) 10083 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
8808 || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) 10084 || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8809 { 10085 {
8810 error ("%qE appears more than once in data clauses", t); 10086 error_at (OMP_CLAUSE_LOCATION (c),
10087 "%qE appears more than once in data clauses", t);
8811 remove = true; 10088 remove = true;
8812 } 10089 }
8813 else 10090 else
8814 bitmap_set_bit (&generic_head, DECL_UID (t)); 10091 bitmap_set_bit (&generic_head, DECL_UID (t));
8815 break; 10092 break;
8819 t = OMP_CLAUSE_DECL (c); 10096 t = OMP_CLAUSE_DECL (c);
8820 need_complete = true; 10097 need_complete = true;
8821 need_implicitly_determined = true; 10098 need_implicitly_determined = true;
8822 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) 10099 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
8823 { 10100 {
8824 error ("%qE is not a variable in clause %<firstprivate%>", t); 10101 error_at (OMP_CLAUSE_LOCATION (c),
10102 "%qE is not a variable in clause %<firstprivate%>", t);
8825 remove = true; 10103 remove = true;
8826 } 10104 }
8827 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 10105 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8828 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) 10106 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
8829 { 10107 {
8830 error ("%qE appears more than once in data clauses", t); 10108 error_at (OMP_CLAUSE_LOCATION (c),
10109 "%qE appears more than once in data clauses", t);
8831 remove = true; 10110 remove = true;
8832 } 10111 }
8833 else 10112 else
8834 bitmap_set_bit (&firstprivate_head, DECL_UID (t)); 10113 bitmap_set_bit (&firstprivate_head, DECL_UID (t));
8835 break; 10114 break;
8839 t = OMP_CLAUSE_DECL (c); 10118 t = OMP_CLAUSE_DECL (c);
8840 need_complete = true; 10119 need_complete = true;
8841 need_implicitly_determined = true; 10120 need_implicitly_determined = true;
8842 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) 10121 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
8843 { 10122 {
8844 error ("%qE is not a variable in clause %<lastprivate%>", t); 10123 error_at (OMP_CLAUSE_LOCATION (c),
10124 "%qE is not a variable in clause %<lastprivate%>", t);
8845 remove = true; 10125 remove = true;
8846 } 10126 }
8847 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) 10127 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
8848 || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) 10128 || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
8849 { 10129 {
8850 error ("%qE appears more than once in data clauses", t); 10130 error_at (OMP_CLAUSE_LOCATION (c),
10131 "%qE appears more than once in data clauses", t);
8851 remove = true; 10132 remove = true;
8852 } 10133 }
8853 else 10134 else
8854 bitmap_set_bit (&lastprivate_head, DECL_UID (t)); 10135 bitmap_set_bit (&lastprivate_head, DECL_UID (t));
8855 break; 10136 break;
8899 default: 10180 default:
8900 gcc_unreachable (); 10181 gcc_unreachable ();
8901 } 10182 }
8902 if (share_name) 10183 if (share_name)
8903 { 10184 {
8904 error ("%qE is predetermined %qs for %qs", 10185 error_at (OMP_CLAUSE_LOCATION (c),
8905 t, share_name, name); 10186 "%qE is predetermined %qs for %qs",
10187 t, share_name, name);
8906 remove = true; 10188 remove = true;
8907 } 10189 }
8908 } 10190 }
8909 } 10191 }
8910 10192
8954 || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain))) 10236 || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
8955 SET_TYPE_STRUCTURAL_EQUALITY (t); 10237 SET_TYPE_STRUCTURAL_EQUALITY (t);
8956 else if (TYPE_CANONICAL (element_type) != element_type 10238 else if (TYPE_CANONICAL (element_type) != element_type
8957 || (domain && TYPE_CANONICAL (domain) != domain)) 10239 || (domain && TYPE_CANONICAL (domain) != domain))
8958 { 10240 {
8959 tree unqualified_canon 10241 tree unqualified_canon
8960 = build_array_type (TYPE_CANONICAL (element_type), 10242 = build_array_type (TYPE_CANONICAL (element_type),
8961 domain? TYPE_CANONICAL (domain) 10243 domain? TYPE_CANONICAL (domain)
8962 : NULL_TREE); 10244 : NULL_TREE);
8963 TYPE_CANONICAL (t) 10245 TYPE_CANONICAL (t)
8964 = c_build_qualified_type (unqualified_canon, type_quals); 10246 = c_build_qualified_type (unqualified_canon, type_quals);
8965 } 10247 }
8966 else 10248 else
8967 TYPE_CANONICAL (t) = t; 10249 TYPE_CANONICAL (t) = t;
8968 } 10250 }
8980 type_quals &= ~TYPE_QUAL_RESTRICT; 10262 type_quals &= ~TYPE_QUAL_RESTRICT;
8981 } 10263 }
8982 10264
8983 return build_qualified_type (type, type_quals); 10265 return build_qualified_type (type, type_quals);
8984 } 10266 }
10267
10268 /* Build a VA_ARG_EXPR for the C parser. */
10269
10270 tree
10271 c_build_va_arg (location_t loc, tree expr, tree type)
10272 {
10273 if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
10274 warning_at (loc, OPT_Wc___compat,
10275 "C++ requires promoted type, not enum type, in %<va_arg%>");
10276 return build_va_arg (loc, expr, type);
10277 }