comparison gcc/c-typeck.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 1b10fe6932e1
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
1 /* Build expressions with type checking for C compiler. 1 /* Build expressions with type checking for C compiler.
2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it under 8 GCC is free software; you can redistribute it and/or modify it under
33 #include "langhooks.h" 33 #include "langhooks.h"
34 #include "c-tree.h" 34 #include "c-tree.h"
35 #include "c-lang.h" 35 #include "c-lang.h"
36 #include "flags.h" 36 #include "flags.h"
37 #include "output.h" 37 #include "output.h"
38 #include "expr.h"
39 #include "toplev.h"
40 #include "intl.h" 38 #include "intl.h"
41 #include "target.h" 39 #include "target.h"
42 #include "tree-iterator.h" 40 #include "tree-iterator.h"
43 #include "tree-flow.h" 41 #include "bitmap.h"
42 #include "gimple.h"
43 #include "c-family/c-objc.h"
44 44
45 /* Possible cases of implicit bad conversions. Used to select 45 /* Possible cases of implicit bad conversions. Used to select
46 diagnostic messages in convert_for_assignment. */ 46 diagnostic messages in convert_for_assignment. */
47 enum impl_conv { 47 enum impl_conv {
48 ic_argpass, 48 ic_argpass,
49 ic_assign, 49 ic_assign,
50 ic_init, 50 ic_init,
51 ic_return 51 ic_return
52 }; 52 };
53 53
54 /* Whether we are building a boolean conversion inside
55 convert_for_assignment, or some other late binary operation. If
56 build_binary_op is called (from code shared with C++) in this case,
57 then the operands have already been folded and the result will not
58 be folded again, so C_MAYBE_CONST_EXPR should not be generated. */
59 bool in_late_binary_op;
60
61 /* The level of nesting inside "__alignof__". */ 54 /* The level of nesting inside "__alignof__". */
62 int in_alignof; 55 int in_alignof;
63 56
64 /* The level of nesting inside "sizeof". */ 57 /* The level of nesting inside "sizeof". */
65 int in_sizeof; 58 int in_sizeof;
74 static int require_constant_value; 67 static int require_constant_value;
75 static int require_constant_elements; 68 static int require_constant_elements;
76 69
77 static bool null_pointer_constant_p (const_tree); 70 static bool null_pointer_constant_p (const_tree);
78 static tree qualify_type (tree, tree); 71 static tree qualify_type (tree, tree);
79 static int tagged_types_tu_compatible_p (const_tree, const_tree, bool *); 72 static int tagged_types_tu_compatible_p (const_tree, const_tree, bool *,
73 bool *);
80 static int comp_target_types (location_t, tree, tree); 74 static int comp_target_types (location_t, tree, tree);
81 static int function_types_compatible_p (const_tree, const_tree, bool *); 75 static int function_types_compatible_p (const_tree, const_tree, bool *,
82 static int type_lists_compatible_p (const_tree, const_tree, bool *); 76 bool *);
77 static int type_lists_compatible_p (const_tree, const_tree, bool *, bool *);
83 static tree lookup_field (tree, tree); 78 static tree lookup_field (tree, tree);
84 static int convert_arguments (tree, VEC(tree,gc) *, VEC(tree,gc) *, tree, 79 static int convert_arguments (tree, VEC(tree,gc) *, VEC(tree,gc) *, tree,
85 tree); 80 tree);
86 static tree pointer_diff (location_t, tree, tree); 81 static tree pointer_diff (location_t, tree, tree);
87 static tree convert_for_assignment (location_t, tree, tree, tree, 82 static tree convert_for_assignment (location_t, tree, tree, tree,
100 static void push_range_stack (tree, struct obstack *); 95 static void push_range_stack (tree, struct obstack *);
101 static void add_pending_init (tree, tree, tree, bool, struct obstack *); 96 static void add_pending_init (tree, tree, tree, bool, struct obstack *);
102 static void set_nonincremental_init (struct obstack *); 97 static void set_nonincremental_init (struct obstack *);
103 static void set_nonincremental_init_from_string (tree, struct obstack *); 98 static void set_nonincremental_init_from_string (tree, struct obstack *);
104 static tree find_init_member (tree, struct obstack *); 99 static tree find_init_member (tree, struct obstack *);
105 static void readonly_error (tree, enum lvalue_use);
106 static void readonly_warning (tree, enum lvalue_use); 100 static void readonly_warning (tree, enum lvalue_use);
107 static int lvalue_or_else (const_tree, enum lvalue_use); 101 static int lvalue_or_else (location_t, const_tree, enum lvalue_use);
108 static void record_maybe_used_decl (tree); 102 static void record_maybe_used_decl (tree);
109 static int comptypes_internal (const_tree, const_tree, bool *); 103 static int comptypes_internal (const_tree, const_tree, bool *, bool *);
110 104
111 /* Return true if EXP is a null pointer constant, false otherwise. */ 105 /* Return true if EXP is a null pointer constant, false otherwise. */
112 106
113 static bool 107 static bool
114 null_pointer_constant_p (const_tree expr) 108 null_pointer_constant_p (const_tree expr)
551 tree mv2 = TREE_VALUE (p2); 545 tree mv2 = TREE_VALUE (p2);
552 if (mv2 && mv2 != error_mark_node 546 if (mv2 && mv2 != error_mark_node
553 && TREE_CODE (mv2) != ARRAY_TYPE) 547 && TREE_CODE (mv2) != ARRAY_TYPE)
554 mv2 = TYPE_MAIN_VARIANT (mv2); 548 mv2 = TYPE_MAIN_VARIANT (mv2);
555 for (memb = TYPE_FIELDS (TREE_VALUE (p1)); 549 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
556 memb; memb = TREE_CHAIN (memb)) 550 memb; memb = DECL_CHAIN (memb))
557 { 551 {
558 tree mv3 = TREE_TYPE (memb); 552 tree mv3 = TREE_TYPE (memb);
559 if (mv3 && mv3 != error_mark_node 553 if (mv3 && mv3 != error_mark_node
560 && TREE_CODE (mv3) != ARRAY_TYPE) 554 && TREE_CODE (mv3) != ARRAY_TYPE)
561 mv3 = TYPE_MAIN_VARIANT (mv3); 555 mv3 = TYPE_MAIN_VARIANT (mv3);
576 tree mv1 = TREE_VALUE (p1); 570 tree mv1 = TREE_VALUE (p1);
577 if (mv1 && mv1 != error_mark_node 571 if (mv1 && mv1 != error_mark_node
578 && TREE_CODE (mv1) != ARRAY_TYPE) 572 && TREE_CODE (mv1) != ARRAY_TYPE)
579 mv1 = TYPE_MAIN_VARIANT (mv1); 573 mv1 = TYPE_MAIN_VARIANT (mv1);
580 for (memb = TYPE_FIELDS (TREE_VALUE (p2)); 574 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
581 memb; memb = TREE_CHAIN (memb)) 575 memb; memb = DECL_CHAIN (memb))
582 { 576 {
583 tree mv3 = TREE_TYPE (memb); 577 tree mv3 = TREE_TYPE (memb);
584 if (mv3 && mv3 != error_mark_node 578 if (mv3 && mv3 != error_mark_node
585 && TREE_CODE (mv3) != ARRAY_TYPE) 579 && TREE_CODE (mv3) != ARRAY_TYPE)
586 mv3 = TYPE_MAIN_VARIANT (mv3); 580 mv3 = TYPE_MAIN_VARIANT (mv3);
970 comptypes (tree type1, tree type2) 964 comptypes (tree type1, tree type2)
971 { 965 {
972 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base; 966 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
973 int val; 967 int val;
974 968
975 val = comptypes_internal (type1, type2, NULL); 969 val = comptypes_internal (type1, type2, NULL, NULL);
976 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1); 970 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
977 971
978 return val; 972 return val;
979 } 973 }
980 974
985 comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p) 979 comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
986 { 980 {
987 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base; 981 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
988 int val; 982 int val;
989 983
990 val = comptypes_internal (type1, type2, enum_and_int_p); 984 val = comptypes_internal (type1, type2, enum_and_int_p, NULL);
985 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
986
987 return val;
988 }
989
990 /* Like comptypes, but if it returns nonzero for different types, it
991 sets *DIFFERENT_TYPES_P to true. */
992
993 int
994 comptypes_check_different_types (tree type1, tree type2,
995 bool *different_types_p)
996 {
997 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
998 int val;
999
1000 val = comptypes_internal (type1, type2, NULL, different_types_p);
991 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1); 1001 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
992 1002
993 return val; 1003 return val;
994 } 1004 }
995 1005
996 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment 1006 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
997 or various other operations. Return 2 if they are compatible 1007 or various other operations. Return 2 if they are compatible
998 but a warning may be needed if you use them together. If 1008 but a warning may be needed if you use them together. If
999 ENUM_AND_INT_P is not NULL, and one type is an enum and the other a 1009 ENUM_AND_INT_P is not NULL, and one type is an enum and the other a
1000 compatible integer type, then this sets *ENUM_AND_INT_P to true; 1010 compatible integer type, then this sets *ENUM_AND_INT_P to true;
1001 *ENUM_AND_INT_P is never set to false. This differs from 1011 *ENUM_AND_INT_P is never set to false. If DIFFERENT_TYPES_P is not
1002 comptypes, in that we don't free the seen types. */ 1012 NULL, and the types are compatible but different enough not to be
1013 permitted in C1X typedef redeclarations, then this sets
1014 *DIFFERENT_TYPES_P to true; *DIFFERENT_TYPES_P is never set to
1015 false, but may or may not be set if the types are incompatible.
1016 This differs from comptypes, in that we don't free the seen
1017 types. */
1003 1018
1004 static int 1019 static int
1005 comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p) 1020 comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p,
1021 bool *different_types_p)
1006 { 1022 {
1007 const_tree t1 = type1; 1023 const_tree t1 = type1;
1008 const_tree t2 = type2; 1024 const_tree t2 = type2;
1009 int attrval, val; 1025 int attrval, val;
1010 1026
1012 1028
1013 if (t1 == t2 || !t1 || !t2 1029 if (t1 == t2 || !t1 || !t2
1014 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK) 1030 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
1015 return 1; 1031 return 1;
1016 1032
1017 /* If either type is the internal version of sizetype, return the
1018 language version. */
1019 if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1)
1020 && TYPE_ORIG_SIZE_TYPE (t1))
1021 t1 = TYPE_ORIG_SIZE_TYPE (t1);
1022
1023 if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2)
1024 && TYPE_ORIG_SIZE_TYPE (t2))
1025 t2 = TYPE_ORIG_SIZE_TYPE (t2);
1026
1027
1028 /* Enumerated types are compatible with integer types, but this is 1033 /* Enumerated types are compatible with integer types, but this is
1029 not transitive: two enumerated types in the same translation unit 1034 not transitive: two enumerated types in the same translation unit
1030 are compatible with each other only if they are the same type. */ 1035 are compatible with each other only if they are the same type. */
1031 1036
1032 if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE) 1037 if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE)
1033 { 1038 {
1034 t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1)); 1039 t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1));
1035 if (enum_and_int_p != NULL && TREE_CODE (t2) != VOID_TYPE) 1040 if (TREE_CODE (t2) != VOID_TYPE)
1036 *enum_and_int_p = true; 1041 {
1042 if (enum_and_int_p != NULL)
1043 *enum_and_int_p = true;
1044 if (different_types_p != NULL)
1045 *different_types_p = true;
1046 }
1037 } 1047 }
1038 else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE) 1048 else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE)
1039 { 1049 {
1040 t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2)); 1050 t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2));
1041 if (enum_and_int_p != NULL && TREE_CODE (t1) != VOID_TYPE) 1051 if (TREE_CODE (t1) != VOID_TYPE)
1042 *enum_and_int_p = true; 1052 {
1053 if (enum_and_int_p != NULL)
1054 *enum_and_int_p = true;
1055 if (different_types_p != NULL)
1056 *different_types_p = true;
1057 }
1043 } 1058 }
1044 1059
1045 if (t1 == t2) 1060 if (t1 == t2)
1046 return 1; 1061 return 1;
1047 1062
1077 if (TYPE_MODE (t1) != TYPE_MODE (t2) 1092 if (TYPE_MODE (t1) != TYPE_MODE (t2)
1078 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) 1093 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
1079 break; 1094 break;
1080 val = (TREE_TYPE (t1) == TREE_TYPE (t2) 1095 val = (TREE_TYPE (t1) == TREE_TYPE (t2)
1081 ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), 1096 ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1082 enum_and_int_p)); 1097 enum_and_int_p, different_types_p));
1083 break; 1098 break;
1084 1099
1085 case FUNCTION_TYPE: 1100 case FUNCTION_TYPE:
1086 val = function_types_compatible_p (t1, t2, enum_and_int_p); 1101 val = function_types_compatible_p (t1, t2, enum_and_int_p,
1102 different_types_p);
1087 break; 1103 break;
1088 1104
1089 case ARRAY_TYPE: 1105 case ARRAY_TYPE:
1090 { 1106 {
1091 tree d1 = TYPE_DOMAIN (t1); 1107 tree d1 = TYPE_DOMAIN (t1);
1095 val = 1; 1111 val = 1;
1096 1112
1097 /* Target types must match incl. qualifiers. */ 1113 /* Target types must match incl. qualifiers. */
1098 if (TREE_TYPE (t1) != TREE_TYPE (t2) 1114 if (TREE_TYPE (t1) != TREE_TYPE (t2)
1099 && 0 == (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), 1115 && 0 == (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1100 enum_and_int_p))) 1116 enum_and_int_p,
1117 different_types_p)))
1101 return 0; 1118 return 0;
1102 1119
1120 if (different_types_p != NULL
1121 && (d1 == 0) != (d2 == 0))
1122 *different_types_p = true;
1103 /* Sizes must match unless one is missing or variable. */ 1123 /* Sizes must match unless one is missing or variable. */
1104 if (d1 == 0 || d2 == 0 || d1 == d2) 1124 if (d1 == 0 || d2 == 0 || d1 == d2)
1105 break; 1125 break;
1106 1126
1107 d1_zero = !TYPE_MAX_VALUE (d1); 1127 d1_zero = !TYPE_MAX_VALUE (d1);
1114 && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST 1134 && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
1115 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)); 1135 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
1116 d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1)); 1136 d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1));
1117 d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2)); 1137 d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2));
1118 1138
1139 if (different_types_p != NULL
1140 && d1_variable != d2_variable)
1141 *different_types_p = true;
1119 if (d1_variable || d2_variable) 1142 if (d1_variable || d2_variable)
1120 break; 1143 break;
1121 if (d1_zero && d2_zero) 1144 if (d1_zero && d2_zero)
1122 break; 1145 break;
1123 if (d1_zero || d2_zero 1146 if (d1_zero || d2_zero
1139 if (! attribute_list_contained (a1, a2) 1162 if (! attribute_list_contained (a1, a2)
1140 && ! attribute_list_contained (a2, a1)) 1163 && ! attribute_list_contained (a2, a1))
1141 break; 1164 break;
1142 1165
1143 if (attrval != 2) 1166 if (attrval != 2)
1144 return tagged_types_tu_compatible_p (t1, t2, enum_and_int_p); 1167 return tagged_types_tu_compatible_p (t1, t2, enum_and_int_p,
1145 val = tagged_types_tu_compatible_p (t1, t2, enum_and_int_p); 1168 different_types_p);
1169 val = tagged_types_tu_compatible_p (t1, t2, enum_and_int_p,
1170 different_types_p);
1146 } 1171 }
1147 break; 1172 break;
1148 1173
1149 case VECTOR_TYPE: 1174 case VECTOR_TYPE:
1150 val = (TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2) 1175 val = (TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
1151 && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), 1176 && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
1152 enum_and_int_p)); 1177 enum_and_int_p, different_types_p));
1153 break; 1178 break;
1154 1179
1155 default: 1180 default:
1156 break; 1181 break;
1157 } 1182 }
1279 1304
1280 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are 1305 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are
1281 compatible. If the two types are not the same (which has been 1306 compatible. If the two types are not the same (which has been
1282 checked earlier), this can only happen when multiple translation 1307 checked earlier), this can only happen when multiple translation
1283 units are being compiled. See C99 6.2.7 paragraph 1 for the exact 1308 units are being compiled. See C99 6.2.7 paragraph 1 for the exact
1284 rules. ENUM_AND_INT_P is as in comptypes_internal. */ 1309 rules. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
1310 comptypes_internal. */
1285 1311
1286 static int 1312 static int
1287 tagged_types_tu_compatible_p (const_tree t1, const_tree t2, 1313 tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
1288 bool *enum_and_int_p) 1314 bool *enum_and_int_p, bool *different_types_p)
1289 { 1315 {
1290 tree s1, s2; 1316 tree s1, s2;
1291 bool needs_warning = false; 1317 bool needs_warning = false;
1292 1318
1293 /* We have to verify that the tags of the types are the same. This 1319 /* We have to verify that the tags of the types are the same. This
1387 return 0; 1413 return 0;
1388 } 1414 }
1389 1415
1390 /* Speed up the common case where the fields are in the same order. */ 1416 /* Speed up the common case where the fields are in the same order. */
1391 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); s1 && s2; 1417 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); s1 && s2;
1392 s1 = TREE_CHAIN (s1), s2 = TREE_CHAIN (s2)) 1418 s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
1393 { 1419 {
1394 int result; 1420 int result;
1395 1421
1396 if (DECL_NAME (s1) != DECL_NAME (s2)) 1422 if (DECL_NAME (s1) != DECL_NAME (s2))
1397 break; 1423 break;
1398 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), 1424 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
1399 enum_and_int_p); 1425 enum_and_int_p, different_types_p);
1400 1426
1401 if (result != 1 && !DECL_NAME (s1)) 1427 if (result != 1 && !DECL_NAME (s1))
1402 break; 1428 break;
1403 if (result == 0) 1429 if (result == 0)
1404 { 1430 {
1420 { 1446 {
1421 tu->val = needs_warning ? 2 : 1; 1447 tu->val = needs_warning ? 2 : 1;
1422 return tu->val; 1448 return tu->val;
1423 } 1449 }
1424 1450
1425 for (s1 = TYPE_FIELDS (t1); s1; s1 = TREE_CHAIN (s1)) 1451 for (s1 = TYPE_FIELDS (t1); s1; s1 = DECL_CHAIN (s1))
1426 { 1452 {
1427 bool ok = false; 1453 bool ok = false;
1428 1454
1429 for (s2 = TYPE_FIELDS (t2); s2; s2 = TREE_CHAIN (s2)) 1455 for (s2 = TYPE_FIELDS (t2); s2; s2 = DECL_CHAIN (s2))
1430 if (DECL_NAME (s1) == DECL_NAME (s2)) 1456 if (DECL_NAME (s1) == DECL_NAME (s2))
1431 { 1457 {
1432 int result; 1458 int result;
1433 1459
1434 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), 1460 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
1435 enum_and_int_p); 1461 enum_and_int_p,
1462 different_types_p);
1436 1463
1437 if (result != 1 && !DECL_NAME (s1)) 1464 if (result != 1 && !DECL_NAME (s1))
1438 continue; 1465 continue;
1439 if (result == 0) 1466 if (result == 0)
1440 { 1467 {
1466 { 1493 {
1467 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); 1494 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
1468 1495
1469 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); 1496 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
1470 s1 && s2; 1497 s1 && s2;
1471 s1 = TREE_CHAIN (s1), s2 = TREE_CHAIN (s2)) 1498 s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
1472 { 1499 {
1473 int result; 1500 int result;
1474 if (TREE_CODE (s1) != TREE_CODE (s2) 1501 if (TREE_CODE (s1) != TREE_CODE (s2)
1475 || DECL_NAME (s1) != DECL_NAME (s2)) 1502 || DECL_NAME (s1) != DECL_NAME (s2))
1476 break; 1503 break;
1477 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), 1504 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
1478 enum_and_int_p); 1505 enum_and_int_p, different_types_p);
1479 if (result == 0) 1506 if (result == 0)
1480 break; 1507 break;
1481 if (result == 2) 1508 if (result == 2)
1482 needs_warning = true; 1509 needs_warning = true;
1483 1510
1502 If either type specifies no argument types, 1529 If either type specifies no argument types,
1503 the other must specify a fixed number of self-promoting arg types. 1530 the other must specify a fixed number of self-promoting arg types.
1504 Otherwise, if one type specifies only the number of arguments, 1531 Otherwise, if one type specifies only the number of arguments,
1505 the other must specify that number of self-promoting arg types. 1532 the other must specify that number of self-promoting arg types.
1506 Otherwise, the argument types must match. 1533 Otherwise, the argument types must match.
1507 ENUM_AND_INT_P is as in comptypes_internal. */ 1534 ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in comptypes_internal. */
1508 1535
1509 static int 1536 static int
1510 function_types_compatible_p (const_tree f1, const_tree f2, 1537 function_types_compatible_p (const_tree f1, const_tree f2,
1511 bool *enum_and_int_p) 1538 bool *enum_and_int_p, bool *different_types_p)
1512 { 1539 {
1513 tree args1, args2; 1540 tree args1, args2;
1514 /* 1 if no need for warning yet, 2 if warning cause has been seen. */ 1541 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1515 int val = 1; 1542 int val = 1;
1516 int val1; 1543 int val1;
1527 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1), 1554 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
1528 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE); 1555 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
1529 if (TYPE_VOLATILE (ret2)) 1556 if (TYPE_VOLATILE (ret2))
1530 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2), 1557 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
1531 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE); 1558 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
1532 val = comptypes_internal (ret1, ret2, enum_and_int_p); 1559 val = comptypes_internal (ret1, ret2, enum_and_int_p, different_types_p);
1533 if (val == 0) 1560 if (val == 0)
1534 return 0; 1561 return 0;
1535 1562
1536 args1 = TYPE_ARG_TYPES (f1); 1563 args1 = TYPE_ARG_TYPES (f1);
1537 args2 = TYPE_ARG_TYPES (f2); 1564 args2 = TYPE_ARG_TYPES (f2);
1565
1566 if (different_types_p != NULL
1567 && (args1 == 0) != (args2 == 0))
1568 *different_types_p = true;
1538 1569
1539 /* An unspecified parmlist matches any specified parmlist 1570 /* An unspecified parmlist matches any specified parmlist
1540 whose argument types don't need default promotions. */ 1571 whose argument types don't need default promotions. */
1541 1572
1542 if (args1 == 0) 1573 if (args1 == 0)
1546 /* If one of these types comes from a non-prototype fn definition, 1577 /* If one of these types comes from a non-prototype fn definition,
1547 compare that with the other type's arglist. 1578 compare that with the other type's arglist.
1548 If they don't match, ask for a warning (but no error). */ 1579 If they don't match, ask for a warning (but no error). */
1549 if (TYPE_ACTUAL_ARG_TYPES (f1) 1580 if (TYPE_ACTUAL_ARG_TYPES (f1)
1550 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), 1581 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1),
1551 enum_and_int_p)) 1582 enum_and_int_p, different_types_p))
1552 val = 2; 1583 val = 2;
1553 return val; 1584 return val;
1554 } 1585 }
1555 if (args2 == 0) 1586 if (args2 == 0)
1556 { 1587 {
1557 if (!self_promoting_args_p (args1)) 1588 if (!self_promoting_args_p (args1))
1558 return 0; 1589 return 0;
1559 if (TYPE_ACTUAL_ARG_TYPES (f2) 1590 if (TYPE_ACTUAL_ARG_TYPES (f2)
1560 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), 1591 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2),
1561 enum_and_int_p)) 1592 enum_and_int_p, different_types_p))
1562 val = 2; 1593 val = 2;
1563 return val; 1594 return val;
1564 } 1595 }
1565 1596
1566 /* Both types have argument lists: compare them and propagate results. */ 1597 /* Both types have argument lists: compare them and propagate results. */
1567 val1 = type_lists_compatible_p (args1, args2, enum_and_int_p); 1598 val1 = type_lists_compatible_p (args1, args2, enum_and_int_p,
1599 different_types_p);
1568 return val1 != 1 ? val1 : val; 1600 return val1 != 1 ? val1 : val;
1569 } 1601 }
1570 1602
1571 /* Check two lists of types for compatibility, returning 0 for 1603 /* Check two lists of types for compatibility, returning 0 for
1572 incompatible, 1 for compatible, or 2 for compatible with 1604 incompatible, 1 for compatible, or 2 for compatible with
1573 warning. ENUM_AND_INT_P is as in comptypes_internal. */ 1605 warning. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
1606 comptypes_internal. */
1574 1607
1575 static int 1608 static int
1576 type_lists_compatible_p (const_tree args1, const_tree args2, 1609 type_lists_compatible_p (const_tree args1, const_tree args2,
1577 bool *enum_and_int_p) 1610 bool *enum_and_int_p, bool *different_types_p)
1578 { 1611 {
1579 /* 1 if no need for warning yet, 2 if warning cause has been seen. */ 1612 /* 1 if no need for warning yet, 2 if warning cause has been seen. */
1580 int val = 1; 1613 int val = 1;
1581 int newval = 0; 1614 int newval = 0;
1582 1615
1597 mv2 = TYPE_MAIN_VARIANT (mv2); 1630 mv2 = TYPE_MAIN_VARIANT (mv2);
1598 /* A null pointer instead of a type 1631 /* A null pointer instead of a type
1599 means there is supposed to be an argument 1632 means there is supposed to be an argument
1600 but nothing is specified about what type it has. 1633 but nothing is specified about what type it has.
1601 So match anything that self-promotes. */ 1634 So match anything that self-promotes. */
1635 if (different_types_p != NULL
1636 && (a1 == 0) != (a2 == 0))
1637 *different_types_p = true;
1602 if (a1 == 0) 1638 if (a1 == 0)
1603 { 1639 {
1604 if (c_type_promotes_to (a2) != a2) 1640 if (c_type_promotes_to (a2) != a2)
1605 return 0; 1641 return 0;
1606 } 1642 }
1611 } 1647 }
1612 /* If one of the lists has an error marker, ignore this arg. */ 1648 /* If one of the lists has an error marker, ignore this arg. */
1613 else if (TREE_CODE (a1) == ERROR_MARK 1649 else if (TREE_CODE (a1) == ERROR_MARK
1614 || TREE_CODE (a2) == ERROR_MARK) 1650 || TREE_CODE (a2) == ERROR_MARK)
1615 ; 1651 ;
1616 else if (!(newval = comptypes_internal (mv1, mv2, enum_and_int_p))) 1652 else if (!(newval = comptypes_internal (mv1, mv2, enum_and_int_p,
1617 { 1653 different_types_p)))
1654 {
1655 if (different_types_p != NULL)
1656 *different_types_p = true;
1618 /* Allow wait (union {union wait *u; int *i} *) 1657 /* Allow wait (union {union wait *u; int *i} *)
1619 and wait (union wait *) to be compatible. */ 1658 and wait (union wait *) to be compatible. */
1620 if (TREE_CODE (a1) == UNION_TYPE 1659 if (TREE_CODE (a1) == UNION_TYPE
1621 && (TYPE_NAME (a1) == 0 1660 && (TYPE_NAME (a1) == 0
1622 || TYPE_TRANSPARENT_AGGR (a1)) 1661 || TYPE_TRANSPARENT_AGGR (a1))
1624 && tree_int_cst_equal (TYPE_SIZE (a1), 1663 && tree_int_cst_equal (TYPE_SIZE (a1),
1625 TYPE_SIZE (a2))) 1664 TYPE_SIZE (a2)))
1626 { 1665 {
1627 tree memb; 1666 tree memb;
1628 for (memb = TYPE_FIELDS (a1); 1667 for (memb = TYPE_FIELDS (a1);
1629 memb; memb = TREE_CHAIN (memb)) 1668 memb; memb = DECL_CHAIN (memb))
1630 { 1669 {
1631 tree mv3 = TREE_TYPE (memb); 1670 tree mv3 = TREE_TYPE (memb);
1632 if (mv3 && mv3 != error_mark_node 1671 if (mv3 && mv3 != error_mark_node
1633 && TREE_CODE (mv3) != ARRAY_TYPE) 1672 && TREE_CODE (mv3) != ARRAY_TYPE)
1634 mv3 = TYPE_MAIN_VARIANT (mv3); 1673 mv3 = TYPE_MAIN_VARIANT (mv3);
1635 if (comptypes_internal (mv3, mv2, enum_and_int_p)) 1674 if (comptypes_internal (mv3, mv2, enum_and_int_p,
1675 different_types_p))
1636 break; 1676 break;
1637 } 1677 }
1638 if (memb == 0) 1678 if (memb == 0)
1639 return 0; 1679 return 0;
1640 } 1680 }
1645 && tree_int_cst_equal (TYPE_SIZE (a2), 1685 && tree_int_cst_equal (TYPE_SIZE (a2),
1646 TYPE_SIZE (a1))) 1686 TYPE_SIZE (a1)))
1647 { 1687 {
1648 tree memb; 1688 tree memb;
1649 for (memb = TYPE_FIELDS (a2); 1689 for (memb = TYPE_FIELDS (a2);
1650 memb; memb = TREE_CHAIN (memb)) 1690 memb; memb = DECL_CHAIN (memb))
1651 { 1691 {
1652 tree mv3 = TREE_TYPE (memb); 1692 tree mv3 = TREE_TYPE (memb);
1653 if (mv3 && mv3 != error_mark_node 1693 if (mv3 && mv3 != error_mark_node
1654 && TREE_CODE (mv3) != ARRAY_TYPE) 1694 && TREE_CODE (mv3) != ARRAY_TYPE)
1655 mv3 = TYPE_MAIN_VARIANT (mv3); 1695 mv3 = TYPE_MAIN_VARIANT (mv3);
1656 if (comptypes_internal (mv3, mv1, enum_and_int_p)) 1696 if (comptypes_internal (mv3, mv1, enum_and_int_p,
1697 different_types_p))
1657 break; 1698 break;
1658 } 1699 }
1659 if (memb == 0) 1700 if (memb == 0)
1660 return 0; 1701 return 0;
1661 } 1702 }
1780 CASE_CONVERT: 1821 CASE_CONVERT:
1781 case ADDR_EXPR: 1822 case ADDR_EXPR:
1782 mark_exp_read (TREE_OPERAND (exp, 0)); 1823 mark_exp_read (TREE_OPERAND (exp, 0));
1783 break; 1824 break;
1784 case COMPOUND_EXPR: 1825 case COMPOUND_EXPR:
1826 case C_MAYBE_CONST_EXPR:
1785 mark_exp_read (TREE_OPERAND (exp, 1)); 1827 mark_exp_read (TREE_OPERAND (exp, 1));
1786 break; 1828 break;
1787 default: 1829 default:
1788 break; 1830 break;
1789 } 1831 }
1992 { 2034 {
1993 tree anon = lookup_field (TREE_TYPE (field), component); 2035 tree anon = lookup_field (TREE_TYPE (field), component);
1994 2036
1995 if (anon) 2037 if (anon)
1996 return tree_cons (NULL_TREE, field, anon); 2038 return tree_cons (NULL_TREE, field, anon);
2039
2040 /* The Plan 9 compiler permits referring
2041 directly to an anonymous struct/union field
2042 using a typedef name. */
2043 if (flag_plan9_extensions
2044 && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
2045 && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
2046 == TYPE_DECL)
2047 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
2048 == component))
2049 break;
1997 } 2050 }
1998 } 2051 }
1999 2052
2000 /* Entire record is only anon unions. */ 2053 /* Entire record is only anon unions. */
2001 if (bot > top) 2054 if (bot > top)
2018 else if (DECL_NAME (field) != component) 2071 else if (DECL_NAME (field) != component)
2019 return NULL_TREE; 2072 return NULL_TREE;
2020 } 2073 }
2021 else 2074 else
2022 { 2075 {
2023 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) 2076 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2024 { 2077 {
2025 if (DECL_NAME (field) == NULL_TREE 2078 if (DECL_NAME (field) == NULL_TREE
2026 && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE 2079 && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
2027 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)) 2080 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE))
2028 { 2081 {
2029 tree anon = lookup_field (TREE_TYPE (field), component); 2082 tree anon = lookup_field (TREE_TYPE (field), component);
2030 2083
2031 if (anon) 2084 if (anon)
2032 return tree_cons (NULL_TREE, field, anon); 2085 return tree_cons (NULL_TREE, field, anon);
2086
2087 /* The Plan 9 compiler permits referring directly to an
2088 anonymous struct/union field using a typedef
2089 name. */
2090 if (flag_plan9_extensions
2091 && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
2092 && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
2093 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
2094 == component))
2095 break;
2033 } 2096 }
2034 2097
2035 if (DECL_NAME (field) == component) 2098 if (DECL_NAME (field) == component)
2036 break; 2099 break;
2037 } 2100 }
2056 tree ref; 2119 tree ref;
2057 bool datum_lvalue = lvalue_p (datum); 2120 bool datum_lvalue = lvalue_p (datum);
2058 2121
2059 if (!objc_is_public (datum, component)) 2122 if (!objc_is_public (datum, component))
2060 return error_mark_node; 2123 return error_mark_node;
2124
2125 /* Detect Objective-C property syntax object.property. */
2126 if (c_dialect_objc ()
2127 && (ref = objc_maybe_build_component_ref (datum, component)))
2128 return ref;
2061 2129
2062 /* See if there is a field or component with name COMPONENT. */ 2130 /* See if there is a field or component with name COMPONENT. */
2063 2131
2064 if (code == RECORD_TYPE || code == UNION_TYPE) 2132 if (code == RECORD_TYPE || code == UNION_TYPE)
2065 { 2133 {
2196 protected_set_expr_location (ref, loc); 2264 protected_set_expr_location (ref, loc);
2197 return ref; 2265 return ref;
2198 } 2266 }
2199 } 2267 }
2200 else if (TREE_CODE (pointer) != ERROR_MARK) 2268 else if (TREE_CODE (pointer) != ERROR_MARK)
2201 switch (errstring) 2269 invalid_indirection_error (loc, type, errstring);
2202 { 2270
2203 case RO_ARRAY_INDEXING:
2204 error_at (loc,
2205 "invalid type argument of array indexing (have %qT)",
2206 type);
2207 break;
2208 case RO_UNARY_STAR:
2209 error_at (loc,
2210 "invalid type argument of unary %<*%> (have %qT)",
2211 type);
2212 break;
2213 case RO_ARROW:
2214 error_at (loc,
2215 "invalid type argument of %<->%> (have %qT)",
2216 type);
2217 break;
2218 default:
2219 gcc_unreachable ();
2220 }
2221 return error_mark_node; 2271 return error_mark_node;
2222 } 2272 }
2223 2273
2224 /* This handles expressions of the form "a[i]", which denotes 2274 /* This handles expressions of the form "a[i]", which denotes
2225 an array reference. 2275 an array reference.
2228 If A is a variable or a member, we generate a primitive ARRAY_REF. 2278 If A is a variable or a member, we generate a primitive ARRAY_REF.
2229 This avoids forcing the array out of registers, and can work on 2279 This avoids forcing the array out of registers, and can work on
2230 arrays that are not lvalues (for example, members of structures returned 2280 arrays that are not lvalues (for example, members of structures returned
2231 by functions). 2281 by functions).
2232 2282
2283 For vector types, allow vector[i] but not i[vector], and create
2284 *(((type*)&vectortype) + i) for the expression.
2285
2233 LOC is the location to use for the returned expression. */ 2286 LOC is the location to use for the returned expression. */
2234 2287
2235 tree 2288 tree
2236 build_array_ref (location_t loc, tree array, tree index) 2289 build_array_ref (location_t loc, tree array, tree index)
2237 { 2290 {
2240 if (TREE_TYPE (array) == error_mark_node 2293 if (TREE_TYPE (array) == error_mark_node
2241 || TREE_TYPE (index) == error_mark_node) 2294 || TREE_TYPE (index) == error_mark_node)
2242 return error_mark_node; 2295 return error_mark_node;
2243 2296
2244 if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE 2297 if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
2245 && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE) 2298 && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
2299 /* Allow vector[index] but not index[vector]. */
2300 && TREE_CODE (TREE_TYPE (array)) != VECTOR_TYPE)
2246 { 2301 {
2247 tree temp; 2302 tree temp;
2248 if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE 2303 if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
2249 && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE) 2304 && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
2250 { 2305 {
2251 error_at (loc, "subscripted value is neither array nor pointer"); 2306 error_at (loc,
2307 "subscripted value is neither array nor pointer nor vector");
2308
2252 return error_mark_node; 2309 return error_mark_node;
2253 } 2310 }
2254 temp = array; 2311 temp = array;
2255 array = index; 2312 array = index;
2256 index = temp; 2313 index = temp;
2276 2333
2277 /* Apply default promotions *after* noticing character types. */ 2334 /* Apply default promotions *after* noticing character types. */
2278 index = default_conversion (index); 2335 index = default_conversion (index);
2279 2336
2280 gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE); 2337 gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE);
2338
2339 /* For vector[index], convert the vector to a
2340 pointer of the underlying type. */
2341 if (TREE_CODE (TREE_TYPE (array)) == VECTOR_TYPE)
2342 {
2343 tree type = TREE_TYPE (array);
2344 tree type1;
2345
2346 if (TREE_CODE (index) == INTEGER_CST)
2347 if (!host_integerp (index, 1)
2348 || ((unsigned HOST_WIDE_INT) tree_low_cst (index, 1)
2349 >= TYPE_VECTOR_SUBPARTS (TREE_TYPE (array))))
2350 warning_at (loc, OPT_Warray_bounds, "index value is out of bound");
2351
2352 c_common_mark_addressable_vec (array);
2353 type = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
2354 type = build_pointer_type (type);
2355 type1 = build_pointer_type (TREE_TYPE (array));
2356 array = build1 (ADDR_EXPR, type1, array);
2357 array = convert (type, array);
2358 }
2281 2359
2282 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE) 2360 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
2283 { 2361 {
2284 tree rval, type; 2362 tree rval, type;
2285 2363
2715 if (AGGREGATE_TYPE_P (return_type)) 2793 if (AGGREGATE_TYPE_P (return_type))
2716 rhs = build_compound_literal (loc, return_type, 2794 rhs = build_compound_literal (loc, return_type,
2717 build_constructor (return_type, 0), 2795 build_constructor (return_type, 0),
2718 false); 2796 false);
2719 else 2797 else
2720 rhs = fold_convert_loc (loc, return_type, integer_zero_node); 2798 rhs = build_zero_cst (return_type);
2721 2799
2722 return require_complete_type (build2 (COMPOUND_EXPR, return_type, 2800 return require_complete_type (build2 (COMPOUND_EXPR, return_type,
2723 trap, rhs)); 2801 trap, rhs));
2724 } 2802 }
2725 } 2803 }
2845 bool npc; 2923 bool npc;
2846 tree parmval; 2924 tree parmval;
2847 2925
2848 if (type == void_type_node) 2926 if (type == void_type_node)
2849 { 2927 {
2850 error_at (input_location, 2928 if (selector)
2851 "too many arguments to function %qE", function); 2929 error_at (input_location,
2930 "too many arguments to method %qE", selector);
2931 else
2932 error_at (input_location,
2933 "too many arguments to function %qE", function);
2934
2852 if (fundecl && !DECL_BUILT_IN (fundecl)) 2935 if (fundecl && !DECL_BUILT_IN (fundecl))
2853 inform (DECL_SOURCE_LOCATION (fundecl), "declared here"); 2936 inform (DECL_SOURCE_LOCATION (fundecl), "declared here");
2854 return parmnum; 2937 return parmnum;
2855 } 2938 }
2856 2939
3043 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype))) 3126 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
3044 { 3127 {
3045 if (type_generic) 3128 if (type_generic)
3046 parmval = val; 3129 parmval = val;
3047 else 3130 else
3048 /* Convert `float' to `double'. */ 3131 {
3049 parmval = convert (double_type_node, val); 3132 /* Convert `float' to `double'. */
3133 if (warn_double_promotion && !c_inhibit_evaluation_warnings)
3134 warning (OPT_Wdouble_promotion,
3135 "implicit conversion from %qT to %qT when passing "
3136 "argument to function",
3137 valtype, double_type_node);
3138 parmval = convert (double_type_node, val);
3139 }
3050 } 3140 }
3051 else if (excess_precision && !type_generic) 3141 else if (excess_precision && !type_generic)
3052 /* A "double" argument with excess precision being passed 3142 /* A "double" argument with excess precision being passed
3053 without a prototype or in variable arguments. */ 3143 without a prototype or in variable arguments. */
3054 parmval = convert (valtype, val); 3144 parmval = convert (valtype, val);
3443 if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret)) 3533 if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
3444 location = EXPR_LOCATION (ret); 3534 location = EXPR_LOCATION (ret);
3445 goto return_build_unary_op; 3535 goto return_build_unary_op;
3446 3536
3447 case REALPART_EXPR: 3537 case REALPART_EXPR:
3448 if (TREE_CODE (arg) == COMPLEX_CST)
3449 ret = TREE_REALPART (arg);
3450 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
3451 ret = fold_build1_loc (location,
3452 REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
3453 else
3454 ret = arg;
3455 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
3456 eptype = TREE_TYPE (eptype);
3457 goto return_build_unary_op;
3458
3459 case IMAGPART_EXPR: 3538 case IMAGPART_EXPR:
3460 if (TREE_CODE (arg) == COMPLEX_CST) 3539 ret = build_real_imag_expr (location, code, arg);
3461 ret = TREE_IMAGPART (arg); 3540 if (ret == error_mark_node)
3462 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE) 3541 return error_mark_node;
3463 ret = fold_build1_loc (location,
3464 IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
3465 else
3466 ret = omit_one_operand_loc (location, TREE_TYPE (arg),
3467 integer_zero_node, arg);
3468 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE) 3542 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
3469 eptype = TREE_TYPE (eptype); 3543 eptype = TREE_TYPE (eptype);
3470 goto return_build_unary_op; 3544 goto return_build_unary_op;
3471 3545
3472 case PREINCREMENT_EXPR: 3546 case PREINCREMENT_EXPR:
3485 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg)); 3559 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
3486 C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1; 3560 C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
3487 goto return_build_unary_op; 3561 goto return_build_unary_op;
3488 } 3562 }
3489 3563
3490 /* Complain about anything that is not a true lvalue. */ 3564 /* Complain about anything that is not a true lvalue. In
3491 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR 3565 Objective-C, skip this check for property_refs. */
3492 || code == POSTINCREMENT_EXPR) 3566 if (!objc_is_property_ref (arg)
3493 ? lv_increment 3567 && !lvalue_or_else (location,
3494 : lv_decrement))) 3568 arg, ((code == PREINCREMENT_EXPR
3569 || code == POSTINCREMENT_EXPR)
3570 ? lv_increment
3571 : lv_decrement)))
3495 return error_mark_node; 3572 return error_mark_node;
3496 3573
3497 if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE) 3574 if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
3498 { 3575 {
3499 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) 3576 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
3597 { 3674 {
3598 inc = integer_one_node; 3675 inc = integer_one_node;
3599 inc = convert (argtype, inc); 3676 inc = convert (argtype, inc);
3600 } 3677 }
3601 3678
3679 /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
3680 need to ask Objective-C to build the increment or decrement
3681 expression for it. */
3682 if (objc_is_property_ref (arg))
3683 return objc_build_incr_expr_for_property_ref (location, code,
3684 arg, inc);
3685
3602 /* Report a read-only lvalue. */ 3686 /* Report a read-only lvalue. */
3603 if (TYPE_READONLY (argtype)) 3687 if (TYPE_READONLY (argtype))
3604 { 3688 {
3605 readonly_error (arg, 3689 readonly_error (arg,
3606 ((code == PREINCREMENT_EXPR 3690 ((code == PREINCREMENT_EXPR
3662 } 3746 }
3663 3747
3664 /* Anything not already handled and not a true memory reference 3748 /* Anything not already handled and not a true memory reference
3665 or a non-lvalue array is an error. */ 3749 or a non-lvalue array is an error. */
3666 else if (typecode != FUNCTION_TYPE && !flag 3750 else if (typecode != FUNCTION_TYPE && !flag
3667 && !lvalue_or_else (arg, lv_addressof)) 3751 && !lvalue_or_else (location, arg, lv_addressof))
3668 return error_mark_node; 3752 return error_mark_node;
3669 3753
3670 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify 3754 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
3671 folding later. */ 3755 folding later. */
3672 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR) 3756 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
3683 3767
3684 /* Ordinary case; arg is a COMPONENT_REF or a decl. */ 3768 /* Ordinary case; arg is a COMPONENT_REF or a decl. */
3685 argtype = TREE_TYPE (arg); 3769 argtype = TREE_TYPE (arg);
3686 3770
3687 /* If the lvalue is const or volatile, merge that into the type 3771 /* If the lvalue is const or volatile, merge that into the type
3688 to which the address will point. Note that you can't get a 3772 to which the address will point. This should only be needed
3689 restricted pointer by taking the address of something, so we 3773 for function types. */
3690 only have to deal with `const' and `volatile' here. */
3691 if ((DECL_P (arg) || REFERENCE_CLASS_P (arg)) 3774 if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
3692 && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))) 3775 && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg)))
3693 argtype = c_build_type_variant (argtype, 3776 {
3694 TREE_READONLY (arg), 3777 int orig_quals = TYPE_QUALS (strip_array_types (argtype));
3695 TREE_THIS_VOLATILE (arg)); 3778 int quals = orig_quals;
3779
3780 if (TREE_READONLY (arg))
3781 quals |= TYPE_QUAL_CONST;
3782 if (TREE_THIS_VOLATILE (arg))
3783 quals |= TYPE_QUAL_VOLATILE;
3784
3785 gcc_assert (quals == orig_quals
3786 || TREE_CODE (argtype) == FUNCTION_TYPE);
3787
3788 argtype = c_build_qualified_type (argtype, quals);
3789 }
3696 3790
3697 if (!c_mark_addressable (arg)) 3791 if (!c_mark_addressable (arg))
3698 return error_mark_node; 3792 return error_mark_node;
3699 3793
3700 gcc_assert (TREE_CODE (arg) != COMPONENT_REF 3794 gcc_assert (TREE_CODE (arg) != COMPONENT_REF
3784 default: 3878 default:
3785 return 0; 3879 return 0;
3786 } 3880 }
3787 } 3881 }
3788 3882
3789 /* Give an error for storing in something that is 'const'. */
3790
3791 static void
3792 readonly_error (tree arg, enum lvalue_use use)
3793 {
3794 gcc_assert (use == lv_assign || use == lv_increment || use == lv_decrement
3795 || use == lv_asm);
3796 /* Using this macro rather than (for example) arrays of messages
3797 ensures that all the format strings are checked at compile
3798 time. */
3799 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
3800 : (use == lv_increment ? (I) \
3801 : (use == lv_decrement ? (D) : (AS))))
3802 if (TREE_CODE (arg) == COMPONENT_REF)
3803 {
3804 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3805 readonly_error (TREE_OPERAND (arg, 0), use);
3806 else
3807 error (READONLY_MSG (G_("assignment of read-only member %qD"),
3808 G_("increment of read-only member %qD"),
3809 G_("decrement of read-only member %qD"),
3810 G_("read-only member %qD used as %<asm%> output")),
3811 TREE_OPERAND (arg, 1));
3812 }
3813 else if (TREE_CODE (arg) == VAR_DECL)
3814 error (READONLY_MSG (G_("assignment of read-only variable %qD"),
3815 G_("increment of read-only variable %qD"),
3816 G_("decrement of read-only variable %qD"),
3817 G_("read-only variable %qD used as %<asm%> output")),
3818 arg);
3819 else
3820 error (READONLY_MSG (G_("assignment of read-only location %qE"),
3821 G_("increment of read-only location %qE"),
3822 G_("decrement of read-only location %qE"),
3823 G_("read-only location %qE used as %<asm%> output")),
3824 arg);
3825 }
3826
3827 /* Give a warning for storing in something that is read-only in GCC 3883 /* Give a warning for storing in something that is read-only in GCC
3828 terms but not const in ISO C terms. */ 3884 terms but not const in ISO C terms. */
3829 3885
3830 static void 3886 static void
3831 readonly_warning (tree arg, enum lvalue_use use) 3887 readonly_warning (tree arg, enum lvalue_use use)
3848 } 3904 }
3849 3905
3850 3906
3851 /* Return nonzero if REF is an lvalue valid for this language; 3907 /* Return nonzero if REF is an lvalue valid for this language;
3852 otherwise, print an error message and return zero. USE says 3908 otherwise, print an error message and return zero. USE says
3853 how the lvalue is being used and so selects the error message. */ 3909 how the lvalue is being used and so selects the error message.
3910 LOCATION is the location at which any error should be reported. */
3854 3911
3855 static int 3912 static int
3856 lvalue_or_else (const_tree ref, enum lvalue_use use) 3913 lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
3857 { 3914 {
3858 int win = lvalue_p (ref); 3915 int win = lvalue_p (ref);
3859 3916
3860 if (!win) 3917 if (!win)
3861 lvalue_error (use); 3918 lvalue_error (loc, use);
3862 3919
3863 return win; 3920 return win;
3864 } 3921 }
3865 3922
3866 /* Mark EXP saying that we need to be able to take the 3923 /* Mark EXP saying that we need to be able to take the
3977 tree semantic_result_type = NULL; 4034 tree semantic_result_type = NULL;
3978 tree orig_op1 = op1, orig_op2 = op2; 4035 tree orig_op1 = op1, orig_op2 = op2;
3979 bool int_const, op1_int_operands, op2_int_operands, int_operands; 4036 bool int_const, op1_int_operands, op2_int_operands, int_operands;
3980 bool ifexp_int_operands; 4037 bool ifexp_int_operands;
3981 tree ret; 4038 tree ret;
3982 bool objc_ok;
3983 4039
3984 op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1); 4040 op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
3985 if (op1_int_operands) 4041 if (op1_int_operands)
3986 op1 = remove_c_maybe_const_expr (op1); 4042 op1 = remove_c_maybe_const_expr (op1);
3987 op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2); 4043 op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
4014 { 4070 {
4015 error_at (colon_loc, "non-lvalue array in conditional expression"); 4071 error_at (colon_loc, "non-lvalue array in conditional expression");
4016 return error_mark_node; 4072 return error_mark_node;
4017 } 4073 }
4018 4074
4019 objc_ok = objc_compare_types (type1, type2, -3, NULL_TREE);
4020
4021 if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR 4075 if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
4022 || TREE_CODE (op2) == EXCESS_PRECISION_EXPR) 4076 || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
4023 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE 4077 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
4024 || code1 == COMPLEX_TYPE) 4078 || code1 == COMPLEX_TYPE)
4025 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE 4079 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
4067 || code1 == COMPLEX_TYPE) 4121 || code1 == COMPLEX_TYPE)
4068 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE 4122 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
4069 || code2 == COMPLEX_TYPE)) 4123 || code2 == COMPLEX_TYPE))
4070 { 4124 {
4071 result_type = c_common_type (type1, type2); 4125 result_type = c_common_type (type1, type2);
4126 do_warn_double_promotion (result_type, type1, type2,
4127 "implicit conversion from %qT to %qT to "
4128 "match other result of conditional",
4129 colon_loc);
4072 4130
4073 /* If -Wsign-compare, warn here if type1 and type2 have 4131 /* If -Wsign-compare, warn here if type1 and type2 have
4074 different signedness. We'll promote the signed to unsigned 4132 different signedness. We'll promote the signed to unsigned
4075 and later code won't know it used to be different. 4133 and later code won't know it used to be different.
4076 Do this check on the original types, so that explicit casts 4134 Do this check on the original types, so that explicit casts
4177 "ISO C forbids conditional expr between " 4235 "ISO C forbids conditional expr between "
4178 "%<void *%> and function pointer"); 4236 "%<void *%> and function pointer");
4179 result_type = build_pointer_type (qualify_type (TREE_TYPE (type2), 4237 result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
4180 TREE_TYPE (type1))); 4238 TREE_TYPE (type1)));
4181 } 4239 }
4240 /* Objective-C pointer comparisons are a bit more lenient. */
4241 else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
4242 result_type = objc_common_type (type1, type2);
4182 else 4243 else
4183 { 4244 {
4184 int qual = ENCODE_QUAL_ADDR_SPACE (as_common); 4245 int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
4185 4246
4186 if (!objc_ok) 4247 pedwarn (colon_loc, 0,
4187 pedwarn (colon_loc, 0, 4248 "pointer type mismatch in conditional expression");
4188 "pointer type mismatch in conditional expression");
4189 result_type = build_pointer_type 4249 result_type = build_pointer_type
4190 (build_qualified_type (void_type_node, qual)); 4250 (build_qualified_type (void_type_node, qual));
4191 } 4251 }
4192 } 4252 }
4193 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE) 4253 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
4341 return ret; 4401 return ret;
4342 } 4402 }
4343 4403
4344 /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to 4404 /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to
4345 which we are casting. OTYPE is the type of the expression being 4405 which we are casting. OTYPE is the type of the expression being
4346 cast. Both TYPE and OTYPE are pointer types. -Wcast-qual appeared 4406 cast. Both TYPE and OTYPE are pointer types. LOC is the location
4347 on the command line. Named address space qualifiers are not handled 4407 of the cast. -Wcast-qual appeared on the command line. Named
4348 here, because they result in different warnings. */ 4408 address space qualifiers are not handled here, because they result
4409 in different warnings. */
4349 4410
4350 static void 4411 static void
4351 handle_warn_cast_qual (tree type, tree otype) 4412 handle_warn_cast_qual (location_t loc, tree type, tree otype)
4352 { 4413 {
4353 tree in_type = type; 4414 tree in_type = type;
4354 tree in_otype = otype; 4415 tree in_otype = otype;
4355 int added = 0; 4416 int added = 0;
4356 int discarded = 0; 4417 int discarded = 0;
4379 } 4440 }
4380 while (TREE_CODE (in_type) == POINTER_TYPE 4441 while (TREE_CODE (in_type) == POINTER_TYPE
4381 && TREE_CODE (in_otype) == POINTER_TYPE); 4442 && TREE_CODE (in_otype) == POINTER_TYPE);
4382 4443
4383 if (added) 4444 if (added)
4384 warning (OPT_Wcast_qual, "cast adds new qualifiers to function type"); 4445 warning_at (loc, OPT_Wcast_qual,
4446 "cast adds %q#v qualifier to function type", added);
4385 4447
4386 if (discarded) 4448 if (discarded)
4387 /* There are qualifiers present in IN_OTYPE that are not present 4449 /* There are qualifiers present in IN_OTYPE that are not present
4388 in IN_TYPE. */ 4450 in IN_TYPE. */
4389 warning (OPT_Wcast_qual, 4451 warning_at (loc, OPT_Wcast_qual,
4390 "cast discards qualifiers from pointer target type"); 4452 "cast discards %q#v qualifier from pointer target type",
4453 discarded);
4391 4454
4392 if (added || discarded) 4455 if (added || discarded)
4393 return; 4456 return;
4394 4457
4395 /* A cast from **T to const **T is unsafe, because it can cause a 4458 /* A cast from **T to const **T is unsafe, because it can cause a
4418 in_type = TREE_TYPE (in_type); 4481 in_type = TREE_TYPE (in_type);
4419 in_otype = TREE_TYPE (in_otype); 4482 in_otype = TREE_TYPE (in_otype);
4420 if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0 4483 if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
4421 && !is_const) 4484 && !is_const)
4422 { 4485 {
4423 warning (OPT_Wcast_qual, 4486 warning_at (loc, OPT_Wcast_qual,
4424 ("new qualifiers in middle of multi-level non-const cast " 4487 "to be safe all intermediate pointers in cast from "
4425 "are unsafe")); 4488 "%qT to %qT must be %<const%> qualified",
4489 otype, type);
4426 break; 4490 break;
4427 } 4491 }
4428 if (is_const) 4492 if (is_const)
4429 is_const = TYPE_READONLY (in_type); 4493 is_const = TYPE_READONLY (in_type);
4430 } 4494 }
4483 } 4547 }
4484 else if (TREE_CODE (type) == UNION_TYPE) 4548 else if (TREE_CODE (type) == UNION_TYPE)
4485 { 4549 {
4486 tree field; 4550 tree field;
4487 4551
4488 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) 4552 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
4489 if (TREE_TYPE (field) != error_mark_node 4553 if (TREE_TYPE (field) != error_mark_node
4490 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)), 4554 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
4491 TYPE_MAIN_VARIANT (TREE_TYPE (value)))) 4555 TYPE_MAIN_VARIANT (TREE_TYPE (value))))
4492 break; 4556 break;
4493 4557
4524 4588
4525 /* Optionally warn about potentially worrisome casts. */ 4589 /* Optionally warn about potentially worrisome casts. */
4526 if (warn_cast_qual 4590 if (warn_cast_qual
4527 && TREE_CODE (type) == POINTER_TYPE 4591 && TREE_CODE (type) == POINTER_TYPE
4528 && TREE_CODE (otype) == POINTER_TYPE) 4592 && TREE_CODE (otype) == POINTER_TYPE)
4529 handle_warn_cast_qual (type, otype); 4593 handle_warn_cast_qual (loc, type, otype);
4530 4594
4531 /* Warn about conversions between pointers to disjoint 4595 /* Warn about conversions between pointers to disjoint
4532 address spaces. */ 4596 address spaces. */
4533 if (TREE_CODE (type) == POINTER_TYPE 4597 if (TREE_CODE (type) == POINTER_TYPE
4534 && TREE_CODE (otype) == POINTER_TYPE 4598 && TREE_CODE (otype) == POINTER_TYPE
4696 } 4760 }
4697 4761
4698 if (CAN_HAVE_LOCATION_P (ret) && !EXPR_HAS_LOCATION (ret)) 4762 if (CAN_HAVE_LOCATION_P (ret) && !EXPR_HAS_LOCATION (ret))
4699 SET_EXPR_LOCATION (ret, loc); 4763 SET_EXPR_LOCATION (ret, loc);
4700 4764
4701 /* C++ does not permits types to be defined in a cast. */ 4765 /* C++ does not permits types to be defined in a cast, but it
4702 if (warn_cxx_compat && type_name->specs->tag_defined_p) 4766 allows references to incomplete types. */
4767 if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
4703 warning_at (loc, OPT_Wc___compat, 4768 warning_at (loc, OPT_Wc___compat,
4704 "defining a type in a cast is invalid in C++"); 4769 "defining a type in a cast is invalid in C++");
4705 4770
4706 return ret; 4771 return ret;
4707 } 4772 }
4735 4800
4736 /* Avoid duplicate error messages from operands that had errors. */ 4801 /* Avoid duplicate error messages from operands that had errors. */
4737 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK) 4802 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
4738 return error_mark_node; 4803 return error_mark_node;
4739 4804
4740 if (!lvalue_or_else (lhs, lv_assign)) 4805 /* For ObjC properties, defer this check. */
4806 if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
4741 return error_mark_node; 4807 return error_mark_node;
4742 4808
4743 if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR) 4809 if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
4744 { 4810 {
4745 rhs_semantic_type = TREE_TYPE (rhs); 4811 rhs_semantic_type = TREE_TYPE (rhs);
4776 /* The original type of the right hand side is no longer 4842 /* The original type of the right hand side is no longer
4777 meaningful. */ 4843 meaningful. */
4778 rhs_origtype = NULL_TREE; 4844 rhs_origtype = NULL_TREE;
4779 } 4845 }
4780 4846
4847 if (c_dialect_objc ())
4848 {
4849 /* Check if we are modifying an Objective-C property reference;
4850 if so, we need to generate setter calls. */
4851 result = objc_maybe_build_modify_expr (lhs, newrhs);
4852 if (result)
4853 return result;
4854
4855 /* Else, do the check that we postponed for Objective-C. */
4856 if (!lvalue_or_else (location, lhs, lv_assign))
4857 return error_mark_node;
4858 }
4859
4781 /* Give an error for storing in something that is 'const'. */ 4860 /* Give an error for storing in something that is 'const'. */
4782 4861
4783 if (TYPE_READONLY (lhstype) 4862 if (TYPE_READONLY (lhstype)
4784 || ((TREE_CODE (lhstype) == RECORD_TYPE 4863 || ((TREE_CODE (lhstype) == RECORD_TYPE
4785 || TREE_CODE (lhstype) == UNION_TYPE) 4864 || TREE_CODE (lhstype) == UNION_TYPE)
4871 ic_assign, false, NULL_TREE, NULL_TREE, 0); 4950 ic_assign, false, NULL_TREE, NULL_TREE, 0);
4872 protected_set_expr_location (result, location); 4951 protected_set_expr_location (result, location);
4873 return result; 4952 return result;
4874 } 4953 }
4875 4954
4955 /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
4956 This is used to implement -fplan9-extensions. */
4957
4958 static bool
4959 find_anonymous_field_with_type (tree struct_type, tree type)
4960 {
4961 tree field;
4962 bool found;
4963
4964 gcc_assert (TREE_CODE (struct_type) == RECORD_TYPE
4965 || TREE_CODE (struct_type) == UNION_TYPE);
4966 found = false;
4967 for (field = TYPE_FIELDS (struct_type);
4968 field != NULL_TREE;
4969 field = TREE_CHAIN (field))
4970 {
4971 if (DECL_NAME (field) == NULL
4972 && comptypes (type, TYPE_MAIN_VARIANT (TREE_TYPE (field))))
4973 {
4974 if (found)
4975 return false;
4976 found = true;
4977 }
4978 else if (DECL_NAME (field) == NULL
4979 && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
4980 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
4981 && find_anonymous_field_with_type (TREE_TYPE (field), type))
4982 {
4983 if (found)
4984 return false;
4985 found = true;
4986 }
4987 }
4988 return found;
4989 }
4990
4991 /* RHS is an expression whose type is pointer to struct. If there is
4992 an anonymous field in RHS with type TYPE, then return a pointer to
4993 that field in RHS. This is used with -fplan9-extensions. This
4994 returns NULL if no conversion could be found. */
4995
4996 static tree
4997 convert_to_anonymous_field (location_t location, tree type, tree rhs)
4998 {
4999 tree rhs_struct_type, lhs_main_type;
5000 tree field, found_field;
5001 bool found_sub_field;
5002 tree ret;
5003
5004 gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
5005 rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
5006 gcc_assert (TREE_CODE (rhs_struct_type) == RECORD_TYPE
5007 || TREE_CODE (rhs_struct_type) == UNION_TYPE);
5008
5009 gcc_assert (POINTER_TYPE_P (type));
5010 lhs_main_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
5011
5012 found_field = NULL_TREE;
5013 found_sub_field = false;
5014 for (field = TYPE_FIELDS (rhs_struct_type);
5015 field != NULL_TREE;
5016 field = TREE_CHAIN (field))
5017 {
5018 if (DECL_NAME (field) != NULL_TREE
5019 || (TREE_CODE (TREE_TYPE (field)) != RECORD_TYPE
5020 && TREE_CODE (TREE_TYPE (field)) != UNION_TYPE))
5021 continue;
5022 if (comptypes (lhs_main_type, TYPE_MAIN_VARIANT (TREE_TYPE (field))))
5023 {
5024 if (found_field != NULL_TREE)
5025 return NULL_TREE;
5026 found_field = field;
5027 }
5028 else if (find_anonymous_field_with_type (TREE_TYPE (field),
5029 lhs_main_type))
5030 {
5031 if (found_field != NULL_TREE)
5032 return NULL_TREE;
5033 found_field = field;
5034 found_sub_field = true;
5035 }
5036 }
5037
5038 if (found_field == NULL_TREE)
5039 return NULL_TREE;
5040
5041 ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
5042 build_fold_indirect_ref (rhs), found_field,
5043 NULL_TREE);
5044 ret = build_fold_addr_expr_loc (location, ret);
5045
5046 if (found_sub_field)
5047 {
5048 ret = convert_to_anonymous_field (location, type, ret);
5049 gcc_assert (ret != NULL_TREE);
5050 }
5051
5052 return ret;
5053 }
5054
4876 /* Convert value RHS to type TYPE as preparation for an assignment to 5055 /* Convert value RHS to type TYPE as preparation for an assignment to
4877 an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the 5056 an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the
4878 original type of RHS; this differs from TREE_TYPE (RHS) for enum 5057 original type of RHS; this differs from TREE_TYPE (RHS) for enum
4879 types. NULL_POINTER_CONSTANT says whether RHS was a null pointer 5058 types. NULL_POINTER_CONSTANT says whether RHS was a null pointer
4880 constant before any folding. 5059 constant before any folding.
4936 break; \ 5115 break; \
4937 case ic_assign: \ 5116 case ic_assign: \
4938 pedwarn (LOCATION, OPT, AS); \ 5117 pedwarn (LOCATION, OPT, AS); \
4939 break; \ 5118 break; \
4940 case ic_init: \ 5119 case ic_init: \
4941 pedwarn (LOCATION, OPT, IN); \ 5120 pedwarn_init (LOCATION, OPT, IN); \
4942 break; \ 5121 break; \
4943 case ic_return: \ 5122 case ic_return: \
4944 pedwarn (LOCATION, OPT, RE); \ 5123 pedwarn (LOCATION, OPT, RE); \
5124 break; \
5125 default: \
5126 gcc_unreachable (); \
5127 } \
5128 } while (0)
5129
5130 /* This macro is used to emit diagnostics to ensure that all format
5131 strings are complete sentences, visible to gettext and checked at
5132 compile time. It is the same as WARN_FOR_ASSIGNMENT but with an
5133 extra parameter to enumerate qualifiers. */
5134
5135 #define WARN_FOR_QUALIFIERS(LOCATION, OPT, AR, AS, IN, RE, QUALS) \
5136 do { \
5137 switch (errtype) \
5138 { \
5139 case ic_argpass: \
5140 if (pedwarn (LOCATION, OPT, AR, parmnum, rname, QUALS)) \
5141 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \
5142 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \
5143 "expected %qT but argument is of type %qT", \
5144 type, rhstype); \
5145 break; \
5146 case ic_assign: \
5147 pedwarn (LOCATION, OPT, AS, QUALS); \
5148 break; \
5149 case ic_init: \
5150 pedwarn (LOCATION, OPT, IN, QUALS); \
5151 break; \
5152 case ic_return: \
5153 pedwarn (LOCATION, OPT, RE, QUALS); \
4945 break; \ 5154 break; \
4946 default: \ 5155 default: \
4947 gcc_unreachable (); \ 5156 gcc_unreachable (); \
4948 } \ 5157 } \
4949 } while (0) 5158 } while (0)
5063 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE 5272 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
5064 || coder == BOOLEAN_TYPE)) 5273 || coder == BOOLEAN_TYPE))
5065 { 5274 {
5066 tree ret; 5275 tree ret;
5067 bool save = in_late_binary_op; 5276 bool save = in_late_binary_op;
5068 if (codel == BOOLEAN_TYPE) 5277 if (codel == BOOLEAN_TYPE || codel == COMPLEX_TYPE)
5069 in_late_binary_op = true; 5278 in_late_binary_op = true;
5070 ret = convert_and_check (type, orig_rhs); 5279 ret = convert_and_check (type, orig_rhs);
5071 if (codel == BOOLEAN_TYPE) 5280 if (codel == BOOLEAN_TYPE || codel == COMPLEX_TYPE)
5072 in_late_binary_op = save; 5281 in_late_binary_op = save;
5073 return ret; 5282 return ret;
5074 } 5283 }
5075 5284
5076 /* Aggregates in different TUs might need conversion. */ 5285 /* Aggregates in different TUs might need conversion. */
5085 && TYPE_TRANSPARENT_AGGR (type)) 5294 && TYPE_TRANSPARENT_AGGR (type))
5086 && errtype == ic_argpass) 5295 && errtype == ic_argpass)
5087 { 5296 {
5088 tree memb, marginal_memb = NULL_TREE; 5297 tree memb, marginal_memb = NULL_TREE;
5089 5298
5090 for (memb = TYPE_FIELDS (type); memb ; memb = TREE_CHAIN (memb)) 5299 for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
5091 { 5300 {
5092 tree memb_type = TREE_TYPE (memb); 5301 tree memb_type = TREE_TYPE (memb);
5093 5302
5094 if (comptypes (TYPE_MAIN_VARIANT (memb_type), 5303 if (comptypes (TYPE_MAIN_VARIANT (memb_type),
5095 TYPE_MAIN_VARIANT (rhstype))) 5304 TYPE_MAIN_VARIANT (rhstype)))
5153 certain things, it is okay to use a const or volatile 5362 certain things, it is okay to use a const or volatile
5154 function where an ordinary one is wanted, but not 5363 function where an ordinary one is wanted, but not
5155 vice-versa. */ 5364 vice-versa. */
5156 if (TYPE_QUALS_NO_ADDR_SPACE (ttl) 5365 if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
5157 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr)) 5366 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
5158 WARN_FOR_ASSIGNMENT (location, 0, 5367 WARN_FOR_QUALIFIERS (location, 0,
5159 G_("passing argument %d of %qE " 5368 G_("passing argument %d of %qE "
5160 "makes qualified function " 5369 "makes %q#v qualified function "
5161 "pointer from unqualified"), 5370 "pointer from unqualified"),
5162 G_("assignment makes qualified " 5371 G_("assignment makes %q#v qualified "
5163 "function pointer from " 5372 "function pointer from "
5164 "unqualified"), 5373 "unqualified"),
5165 G_("initialization makes qualified " 5374 G_("initialization makes %q#v qualified "
5166 "function pointer from " 5375 "function pointer from "
5167 "unqualified"), 5376 "unqualified"),
5168 G_("return makes qualified function " 5377 G_("return makes %q#v qualified function "
5169 "pointer from unqualified")); 5378 "pointer from unqualified"),
5379 TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
5170 } 5380 }
5171 else if (TYPE_QUALS_NO_ADDR_SPACE (ttr) 5381 else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
5172 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl)) 5382 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
5173 WARN_FOR_ASSIGNMENT (location, 0, 5383 WARN_FOR_QUALIFIERS (location, 0,
5174 G_("passing argument %d of %qE discards " 5384 G_("passing argument %d of %qE discards "
5175 "qualifiers from pointer target type"), 5385 "%qv qualifier from pointer target type"),
5176 G_("assignment discards qualifiers " 5386 G_("assignment discards %qv qualifier "
5177 "from pointer target type"), 5387 "from pointer target type"),
5178 G_("initialization discards qualifiers " 5388 G_("initialization discards %qv qualifier "
5179 "from pointer target type"), 5389 "from pointer target type"),
5180 G_("return discards qualifiers from " 5390 G_("return discards %qv qualifier from "
5181 "pointer target type")); 5391 "pointer target type"),
5392 TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
5182 5393
5183 memb = marginal_memb; 5394 memb = marginal_memb;
5184 } 5395 }
5185 5396
5186 if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)) 5397 if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
5209 mvl = TYPE_MAIN_VARIANT (mvl); 5420 mvl = TYPE_MAIN_VARIANT (mvl);
5210 if (TREE_CODE (mvr) != ARRAY_TYPE) 5421 if (TREE_CODE (mvr) != ARRAY_TYPE)
5211 mvr = TYPE_MAIN_VARIANT (mvr); 5422 mvr = TYPE_MAIN_VARIANT (mvr);
5212 /* Opaque pointers are treated like void pointers. */ 5423 /* Opaque pointers are treated like void pointers. */
5213 is_opaque_pointer = vector_targets_convertible_p (ttl, ttr); 5424 is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
5425
5426 /* The Plan 9 compiler permits a pointer to a struct to be
5427 automatically converted into a pointer to an anonymous field
5428 within the struct. */
5429 if (flag_plan9_extensions
5430 && (TREE_CODE (mvl) == RECORD_TYPE || TREE_CODE(mvl) == UNION_TYPE)
5431 && (TREE_CODE (mvr) == RECORD_TYPE || TREE_CODE(mvr) == UNION_TYPE)
5432 && mvl != mvr)
5433 {
5434 tree new_rhs = convert_to_anonymous_field (location, type, rhs);
5435 if (new_rhs != NULL_TREE)
5436 {
5437 rhs = new_rhs;
5438 rhstype = TREE_TYPE (rhs);
5439 coder = TREE_CODE (rhstype);
5440 ttr = TREE_TYPE (rhstype);
5441 mvr = TYPE_MAIN_VARIANT (ttr);
5442 }
5443 }
5214 5444
5215 /* C++ does not allow the implicit conversion void* -> T*. However, 5445 /* C++ does not allow the implicit conversion void* -> T*. However,
5216 for the purpose of reducing the number of false positives, we 5446 for the purpose of reducing the number of false positives, we
5217 tolerate the special case of 5447 tolerate the special case of
5218 5448
5318 && TREE_CODE (ttl) != FUNCTION_TYPE) 5548 && TREE_CODE (ttl) != FUNCTION_TYPE)
5319 { 5549 {
5320 if (TYPE_QUALS_NO_ADDR_SPACE (ttr) 5550 if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
5321 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl)) 5551 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
5322 { 5552 {
5323 /* Types differing only by the presence of the 'volatile' 5553 WARN_FOR_QUALIFIERS (location, 0,
5324 qualifier are acceptable if the 'volatile' has been added 5554 G_("passing argument %d of %qE discards "
5325 in by the Objective-C EH machinery. */ 5555 "%qv qualifier from pointer target type"),
5326 if (!objc_type_quals_match (ttl, ttr)) 5556 G_("assignment discards %qv qualifier "
5327 WARN_FOR_ASSIGNMENT (location, 0, 5557 "from pointer target type"),
5328 G_("passing argument %d of %qE discards " 5558 G_("initialization discards %qv qualifier "
5329 "qualifiers from pointer target type"), 5559 "from pointer target type"),
5330 G_("assignment discards qualifiers " 5560 G_("return discards %qv qualifier from "
5331 "from pointer target type"), 5561 "pointer target type"),
5332 G_("initialization discards qualifiers " 5562 TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
5333 "from pointer target type"),
5334 G_("return discards qualifiers from "
5335 "pointer target type"));
5336 } 5563 }
5337 /* If this is not a case of ignoring a mismatch in signedness, 5564 /* If this is not a case of ignoring a mismatch in signedness,
5338 no warning. */ 5565 no warning. */
5339 else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) 5566 else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
5340 || target_cmp) 5567 || target_cmp)
5358 that say the function will not do certain things, 5585 that say the function will not do certain things,
5359 it is okay to use a const or volatile function 5586 it is okay to use a const or volatile function
5360 where an ordinary one is wanted, but not vice-versa. */ 5587 where an ordinary one is wanted, but not vice-versa. */
5361 if (TYPE_QUALS_NO_ADDR_SPACE (ttl) 5588 if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
5362 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr)) 5589 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
5363 WARN_FOR_ASSIGNMENT (location, 0, 5590 WARN_FOR_QUALIFIERS (location, 0,
5364 G_("passing argument %d of %qE makes " 5591 G_("passing argument %d of %qE makes "
5365 "qualified function pointer " 5592 "%q#v qualified function pointer "
5366 "from unqualified"), 5593 "from unqualified"),
5367 G_("assignment makes qualified function " 5594 G_("assignment makes %q#v qualified function "
5368 "pointer from unqualified"), 5595 "pointer from unqualified"),
5369 G_("initialization makes qualified " 5596 G_("initialization makes %q#v qualified "
5370 "function pointer from unqualified"), 5597 "function pointer from unqualified"),
5371 G_("return makes qualified function " 5598 G_("return makes %q#v qualified function "
5372 "pointer from unqualified")); 5599 "pointer from unqualified"),
5600 TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
5373 } 5601 }
5374 } 5602 }
5375 else 5603 else
5376 /* Avoid warning about the volatile ObjC EH puts on decls. */ 5604 /* Avoid warning about the volatile ObjC EH puts on decls. */
5377 if (!objc_ok) 5605 if (!objc_ok)
5676 *d++ = '\0'; 5904 *d++ = '\0';
5677 return buffer; 5905 return buffer;
5678 } 5906 }
5679 5907
5680 /* Issue an error message for a bad initializer component. 5908 /* Issue an error message for a bad initializer component.
5681 MSGID identifies the message. 5909 GMSGID identifies the message.
5682 The component name is taken from the spelling stack. */ 5910 The component name is taken from the spelling stack. */
5683 5911
5684 void 5912 void
5685 error_init (const char *msgid) 5913 error_init (const char *gmsgid)
5686 { 5914 {
5687 char *ofwhat; 5915 char *ofwhat;
5688 5916
5689 error ("%s", _(msgid)); 5917 /* The gmsgid may be a format string with %< and %>. */
5918 error (gmsgid);
5690 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); 5919 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
5691 if (*ofwhat) 5920 if (*ofwhat)
5692 error ("(near initialization for %qs)", ofwhat); 5921 error ("(near initialization for %qs)", ofwhat);
5693 } 5922 }
5694 5923
5695 /* Issue a pedantic warning for a bad initializer component. OPT is 5924 /* Issue a pedantic warning for a bad initializer component. OPT is
5696 the option OPT_* (from options.h) controlling this warning or 0 if 5925 the option OPT_* (from options.h) controlling this warning or 0 if
5697 it is unconditionally given. MSGID identifies the message. The 5926 it is unconditionally given. GMSGID identifies the message. The
5698 component name is taken from the spelling stack. */ 5927 component name is taken from the spelling stack. */
5699 5928
5700 void 5929 void
5701 pedwarn_init (location_t location, int opt, const char *msgid) 5930 pedwarn_init (location_t location, int opt, const char *gmsgid)
5702 { 5931 {
5703 char *ofwhat; 5932 char *ofwhat;
5704 5933
5705 pedwarn (location, opt, "%s", _(msgid)); 5934 /* The gmsgid may be a format string with %< and %>. */
5935 pedwarn (location, opt, gmsgid);
5706 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); 5936 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
5707 if (*ofwhat) 5937 if (*ofwhat)
5708 pedwarn (location, opt, "(near initialization for %qs)", ofwhat); 5938 pedwarn (location, opt, "(near initialization for %qs)", ofwhat);
5709 } 5939 }
5710 5940
5711 /* Issue a warning for a bad initializer component. 5941 /* Issue a warning for a bad initializer component.
5712 5942
5713 OPT is the OPT_W* value corresponding to the warning option that 5943 OPT is the OPT_W* value corresponding to the warning option that
5714 controls this warning. MSGID identifies the message. The 5944 controls this warning. GMSGID identifies the message. The
5715 component name is taken from the spelling stack. */ 5945 component name is taken from the spelling stack. */
5716 5946
5717 static void 5947 static void
5718 warning_init (int opt, const char *msgid) 5948 warning_init (int opt, const char *gmsgid)
5719 { 5949 {
5720 char *ofwhat; 5950 char *ofwhat;
5721 5951
5722 warning (opt, "%s", _(msgid)); 5952 /* The gmsgid may be a format string with %< and %>. */
5953 warning (opt, gmsgid);
5723 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); 5954 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
5724 if (*ofwhat) 5955 if (*ofwhat)
5725 warning (opt, "(near initialization for %qs)", ofwhat); 5956 warning (opt, "(near initialization for %qs)", ofwhat);
5726 } 5957 }
5727 5958
6369 { 6600 {
6370 constructor_fields = TYPE_FIELDS (constructor_type); 6601 constructor_fields = TYPE_FIELDS (constructor_type);
6371 /* Skip any nameless bit fields at the beginning. */ 6602 /* Skip any nameless bit fields at the beginning. */
6372 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields) 6603 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
6373 && DECL_NAME (constructor_fields) == 0) 6604 && DECL_NAME (constructor_fields) == 0)
6374 constructor_fields = TREE_CHAIN (constructor_fields); 6605 constructor_fields = DECL_CHAIN (constructor_fields);
6375 6606
6376 constructor_unfilled_fields = constructor_fields; 6607 constructor_unfilled_fields = constructor_fields;
6377 constructor_bit_index = bitsize_zero_node; 6608 constructor_bit_index = bitsize_zero_node;
6378 } 6609 }
6379 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) 6610 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6384 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)); 6615 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
6385 6616
6386 /* Detect non-empty initializations of zero-length arrays. */ 6617 /* Detect non-empty initializations of zero-length arrays. */
6387 if (constructor_max_index == NULL_TREE 6618 if (constructor_max_index == NULL_TREE
6388 && TYPE_SIZE (constructor_type)) 6619 && TYPE_SIZE (constructor_type))
6389 constructor_max_index = build_int_cst (NULL_TREE, -1); 6620 constructor_max_index = integer_minus_one_node;
6390 6621
6391 /* constructor_max_index needs to be an INTEGER_CST. Attempts 6622 /* constructor_max_index needs to be an INTEGER_CST. Attempts
6392 to initialize VLAs will cause a proper error; avoid tree 6623 to initialize VLAs will cause a proper error; avoid tree
6393 checking errors as well by setting a safe value. */ 6624 checking errors as well by setting a safe value. */
6394 if (constructor_max_index 6625 if (constructor_max_index
6395 && TREE_CODE (constructor_max_index) != INTEGER_CST) 6626 && TREE_CODE (constructor_max_index) != INTEGER_CST)
6396 constructor_max_index = build_int_cst (NULL_TREE, -1); 6627 constructor_max_index = integer_minus_one_node;
6397 6628
6398 constructor_index 6629 constructor_index
6399 = convert (bitsizetype, 6630 = convert (bitsizetype,
6400 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); 6631 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
6401 } 6632 }
6569 { 6800 {
6570 constructor_fields = TYPE_FIELDS (constructor_type); 6801 constructor_fields = TYPE_FIELDS (constructor_type);
6571 /* Skip any nameless bit fields at the beginning. */ 6802 /* Skip any nameless bit fields at the beginning. */
6572 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields) 6803 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
6573 && DECL_NAME (constructor_fields) == 0) 6804 && DECL_NAME (constructor_fields) == 0)
6574 constructor_fields = TREE_CHAIN (constructor_fields); 6805 constructor_fields = DECL_CHAIN (constructor_fields);
6575 6806
6576 constructor_unfilled_fields = constructor_fields; 6807 constructor_unfilled_fields = constructor_fields;
6577 constructor_bit_index = bitsize_zero_node; 6808 constructor_bit_index = bitsize_zero_node;
6578 } 6809 }
6579 else if (TREE_CODE (constructor_type) == VECTOR_TYPE) 6810 else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
6592 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)); 6823 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
6593 6824
6594 /* Detect non-empty initializations of zero-length arrays. */ 6825 /* Detect non-empty initializations of zero-length arrays. */
6595 if (constructor_max_index == NULL_TREE 6826 if (constructor_max_index == NULL_TREE
6596 && TYPE_SIZE (constructor_type)) 6827 && TYPE_SIZE (constructor_type))
6597 constructor_max_index = build_int_cst (NULL_TREE, -1); 6828 constructor_max_index = integer_minus_one_node;
6598 6829
6599 /* constructor_max_index needs to be an INTEGER_CST. Attempts 6830 /* constructor_max_index needs to be an INTEGER_CST. Attempts
6600 to initialize VLAs will cause a proper error; avoid tree 6831 to initialize VLAs will cause a proper error; avoid tree
6601 checking errors as well by setting a safe value. */ 6832 checking errors as well by setting a safe value. */
6602 if (constructor_max_index 6833 if (constructor_max_index
6603 && TREE_CODE (constructor_max_index) != INTEGER_CST) 6834 && TREE_CODE (constructor_max_index) != INTEGER_CST)
6604 constructor_max_index = build_int_cst (NULL_TREE, -1); 6835 constructor_max_index = integer_minus_one_node;
6605 6836
6606 constructor_index 6837 constructor_index
6607 = convert (bitsizetype, 6838 = convert (bitsizetype,
6608 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); 6839 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
6609 } 6840 }
6688 "initialization of a flexible array member"); 6919 "initialization of a flexible array member");
6689 6920
6690 /* We have already issued an error message for the existence 6921 /* We have already issued an error message for the existence
6691 of a flexible array member not at the end of the structure. 6922 of a flexible array member not at the end of the structure.
6692 Discard the initializer so that we do not die later. */ 6923 Discard the initializer so that we do not die later. */
6693 if (TREE_CHAIN (constructor_fields) != NULL_TREE) 6924 if (DECL_CHAIN (constructor_fields) != NULL_TREE)
6694 constructor_type = NULL_TREE; 6925 constructor_type = NULL_TREE;
6695 } 6926 }
6696 } 6927 }
6697 6928
6698 /* Warn when some struct elements are implicitly initialized to zero. */ 6929 /* Warn when some struct elements are implicitly initialized to zero. */
6703 { 6934 {
6704 /* Do not warn for flexible array members or zero-length arrays. */ 6935 /* Do not warn for flexible array members or zero-length arrays. */
6705 while (constructor_unfilled_fields 6936 while (constructor_unfilled_fields
6706 && (!DECL_SIZE (constructor_unfilled_fields) 6937 && (!DECL_SIZE (constructor_unfilled_fields)
6707 || integer_zerop (DECL_SIZE (constructor_unfilled_fields)))) 6938 || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
6708 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields); 6939 constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
6709 6940
6710 /* Do not warn if this level of the initializer uses member 6941 /* Do not warn if this level of the initializer uses member
6711 designators; it is likely to be deliberate. */ 6942 designators; it is likely to be deliberate. */
6712 if (constructor_unfilled_fields && !constructor_designated) 6943 if (constructor_unfilled_fields && !constructor_designated)
6713 { 6944 {
7536 if (field 7767 if (field
7537 && (TREE_TYPE (field) == error_mark_node 7768 && (TREE_TYPE (field) == error_mark_node
7538 || (COMPLETE_TYPE_P (TREE_TYPE (field)) 7769 || (COMPLETE_TYPE_P (TREE_TYPE (field))
7539 && integer_zerop (TYPE_SIZE (TREE_TYPE (field))) 7770 && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
7540 && (TREE_CODE (constructor_type) == ARRAY_TYPE 7771 && (TREE_CODE (constructor_type) == ARRAY_TYPE
7541 || TREE_CHAIN (field))))) 7772 || DECL_CHAIN (field)))))
7542 return; 7773 return;
7543 7774
7544 if (semantic_type) 7775 if (semantic_type)
7545 value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value); 7776 value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
7546 value = digest_init (input_location, type, value, origtype, npc, 7777 value = digest_init (input_location, type, value, origtype, npc,
7624 = size_binop_loc (input_location, PLUS_EXPR, constructor_unfilled_index, 7855 = size_binop_loc (input_location, PLUS_EXPR, constructor_unfilled_index,
7625 bitsize_one_node); 7856 bitsize_one_node);
7626 else if (TREE_CODE (constructor_type) == RECORD_TYPE) 7857 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
7627 { 7858 {
7628 constructor_unfilled_fields 7859 constructor_unfilled_fields
7629 = TREE_CHAIN (constructor_unfilled_fields); 7860 = DECL_CHAIN (constructor_unfilled_fields);
7630 7861
7631 /* Skip any nameless bit fields. */ 7862 /* Skip any nameless bit fields. */
7632 while (constructor_unfilled_fields != 0 7863 while (constructor_unfilled_fields != 0
7633 && DECL_C_BIT_FIELD (constructor_unfilled_fields) 7864 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
7634 && DECL_NAME (constructor_unfilled_fields) == 0) 7865 && DECL_NAME (constructor_unfilled_fields) == 0)
7635 constructor_unfilled_fields = 7866 constructor_unfilled_fields =
7636 TREE_CHAIN (constructor_unfilled_fields); 7867 DECL_CHAIN (constructor_unfilled_fields);
7637 } 7868 }
7638 else if (TREE_CODE (constructor_type) == UNION_TYPE) 7869 else if (TREE_CODE (constructor_type) == UNION_TYPE)
7639 constructor_unfilled_fields = 0; 7870 constructor_unfilled_fields = 0;
7640 7871
7641 /* Now output any pending elements which have become next. */ 7872 /* Now output any pending elements which have become next. */
7900 8131
7901 /* Error for non-static initialization of a flexible array member. */ 8132 /* Error for non-static initialization of a flexible array member. */
7902 if (fieldcode == ARRAY_TYPE 8133 if (fieldcode == ARRAY_TYPE
7903 && !require_constant_value 8134 && !require_constant_value
7904 && TYPE_SIZE (fieldtype) == NULL_TREE 8135 && TYPE_SIZE (fieldtype) == NULL_TREE
7905 && TREE_CHAIN (constructor_fields) == NULL_TREE) 8136 && DECL_CHAIN (constructor_fields) == NULL_TREE)
7906 { 8137 {
7907 error_init ("non-static initialization of a flexible array member"); 8138 error_init ("non-static initialization of a flexible array member");
7908 break; 8139 break;
7909 } 8140 }
7910 8141
7948 8179
7949 /* If the current field was the first one not yet written out, 8180 /* If the current field was the first one not yet written out,
7950 it isn't now, so update. */ 8181 it isn't now, so update. */
7951 if (constructor_unfilled_fields == constructor_fields) 8182 if (constructor_unfilled_fields == constructor_fields)
7952 { 8183 {
7953 constructor_unfilled_fields = TREE_CHAIN (constructor_fields); 8184 constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
7954 /* Skip any nameless bit fields. */ 8185 /* Skip any nameless bit fields. */
7955 while (constructor_unfilled_fields != 0 8186 while (constructor_unfilled_fields != 0
7956 && DECL_C_BIT_FIELD (constructor_unfilled_fields) 8187 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
7957 && DECL_NAME (constructor_unfilled_fields) == 0) 8188 && DECL_NAME (constructor_unfilled_fields) == 0)
7958 constructor_unfilled_fields = 8189 constructor_unfilled_fields =
7959 TREE_CHAIN (constructor_unfilled_fields); 8190 DECL_CHAIN (constructor_unfilled_fields);
7960 } 8191 }
7961 } 8192 }
7962 8193
7963 constructor_fields = TREE_CHAIN (constructor_fields); 8194 constructor_fields = DECL_CHAIN (constructor_fields);
7964 /* Skip any nameless bit fields at the beginning. */ 8195 /* Skip any nameless bit fields at the beginning. */
7965 while (constructor_fields != 0 8196 while (constructor_fields != 0
7966 && DECL_C_BIT_FIELD (constructor_fields) 8197 && DECL_C_BIT_FIELD (constructor_fields)
7967 && DECL_NAME (constructor_fields) == 0) 8198 && DECL_NAME (constructor_fields) == 0)
7968 constructor_fields = TREE_CHAIN (constructor_fields); 8199 constructor_fields = DECL_CHAIN (constructor_fields);
7969 } 8200 }
7970 else if (TREE_CODE (constructor_type) == UNION_TYPE) 8201 else if (TREE_CODE (constructor_type) == UNION_TYPE)
7971 { 8202 {
7972 tree fieldtype; 8203 tree fieldtype;
7973 enum tree_code fieldcode; 8204 enum tree_code fieldcode;
8030 else 8261 else
8031 /* Do the bookkeeping for an element that was 8262 /* Do the bookkeeping for an element that was
8032 directly output as a constructor. */ 8263 directly output as a constructor. */
8033 { 8264 {
8034 constructor_bit_index = DECL_SIZE (constructor_fields); 8265 constructor_bit_index = DECL_SIZE (constructor_fields);
8035 constructor_unfilled_fields = TREE_CHAIN (constructor_fields); 8266 constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
8036 } 8267 }
8037 8268
8038 constructor_fields = 0; 8269 constructor_fields = 0;
8039 } 8270 }
8040 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) 8271 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
8248 primitive form of typechecking -- if the cast can be removed, then 8479 primitive form of typechecking -- if the cast can be removed, then
8249 the output operand had a type of the proper width; otherwise we'll 8480 the output operand had a type of the proper width; otherwise we'll
8250 get an error. Gross, but ... */ 8481 get an error. Gross, but ... */
8251 STRIP_NOPS (output); 8482 STRIP_NOPS (output);
8252 8483
8253 if (!lvalue_or_else (output, lv_asm)) 8484 if (!lvalue_or_else (loc, output, lv_asm))
8254 output = error_mark_node; 8485 output = error_mark_node;
8255 8486
8256 if (output != error_mark_node 8487 if (output != error_mark_node
8257 && (TREE_READONLY (output) 8488 && (TREE_READONLY (output)
8258 || TYPE_READONLY (TREE_TYPE (output)) 8489 || TYPE_READONLY (TREE_TYPE (output))
9165 9396
9166 /* True means this is an arithmetic operation that may need excess 9397 /* True means this is an arithmetic operation that may need excess
9167 precision. */ 9398 precision. */
9168 bool may_need_excess_precision; 9399 bool may_need_excess_precision;
9169 9400
9401 /* True means this is a boolean operation that converts both its
9402 operands to truth-values. */
9403 bool boolean_op = false;
9404
9170 if (location == UNKNOWN_LOCATION) 9405 if (location == UNKNOWN_LOCATION)
9171 location = input_location; 9406 location = input_location;
9172 9407
9173 op0 = orig_op0; 9408 op0 = orig_op0;
9174 op1 = orig_op1; 9409 op1 = orig_op1;
9392 converted to ints! */ 9627 converted to ints! */
9393 result_type = integer_type_node; 9628 result_type = integer_type_node;
9394 op0 = c_common_truthvalue_conversion (location, op0); 9629 op0 = c_common_truthvalue_conversion (location, op0);
9395 op1 = c_common_truthvalue_conversion (location, op1); 9630 op1 = c_common_truthvalue_conversion (location, op1);
9396 converted = 1; 9631 converted = 1;
9632 boolean_op = true;
9397 } 9633 }
9398 if (code == TRUTH_ANDIF_EXPR) 9634 if (code == TRUTH_ANDIF_EXPR)
9399 { 9635 {
9400 int_const_or_overflow = (int_operands 9636 int_const_or_overflow = (int_operands
9401 && TREE_CODE (orig_op0) == INTEGER_CST 9637 && TREE_CODE (orig_op0) == INTEGER_CST
9422 /* Shift operations: result has same type as first operand; 9658 /* Shift operations: result has same type as first operand;
9423 always convert second operand to int. 9659 always convert second operand to int.
9424 Also set SHORT_SHIFT if shifting rightward. */ 9660 Also set SHORT_SHIFT if shifting rightward. */
9425 9661
9426 case RSHIFT_EXPR: 9662 case RSHIFT_EXPR:
9427 if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE) 9663 if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE
9664 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
9665 {
9666 result_type = type0;
9667 converted = 1;
9668 }
9669 else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
9670 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
9671 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
9672 && TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1))
9673 {
9674 result_type = type0;
9675 converted = 1;
9676 }
9677 else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE)
9428 && code1 == INTEGER_TYPE) 9678 && code1 == INTEGER_TYPE)
9429 { 9679 {
9430 if (TREE_CODE (op1) == INTEGER_CST) 9680 if (TREE_CODE (op1) == INTEGER_CST)
9431 { 9681 {
9432 if (tree_int_cst_sgn (op1) < 0) 9682 if (tree_int_cst_sgn (op1) < 0)
9449 } 9699 }
9450 } 9700 }
9451 9701
9452 /* Use the type of the value to be shifted. */ 9702 /* Use the type of the value to be shifted. */
9453 result_type = type0; 9703 result_type = type0;
9454 /* Convert the shift-count to an integer, regardless of size 9704 /* Convert the non vector shift-count to an integer, regardless
9455 of value being shifted. */ 9705 of size of value being shifted. */
9456 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) 9706 if (TREE_CODE (TREE_TYPE (op1)) != VECTOR_TYPE
9707 && TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
9457 op1 = convert (integer_type_node, op1); 9708 op1 = convert (integer_type_node, op1);
9458 /* Avoid converting op1 to result_type later. */ 9709 /* Avoid converting op1 to result_type later. */
9459 converted = 1; 9710 converted = 1;
9460 } 9711 }
9461 break; 9712 break;
9462 9713
9463 case LSHIFT_EXPR: 9714 case LSHIFT_EXPR:
9464 if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE) 9715 if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE
9716 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
9717 {
9718 result_type = type0;
9719 converted = 1;
9720 }
9721 else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
9722 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
9723 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
9724 && TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1))
9725 {
9726 result_type = type0;
9727 converted = 1;
9728 }
9729 else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE)
9465 && code1 == INTEGER_TYPE) 9730 && code1 == INTEGER_TYPE)
9466 { 9731 {
9467 if (TREE_CODE (op1) == INTEGER_CST) 9732 if (TREE_CODE (op1) == INTEGER_CST)
9468 { 9733 {
9469 if (tree_int_cst_sgn (op1) < 0) 9734 if (tree_int_cst_sgn (op1) < 0)
9481 } 9746 }
9482 } 9747 }
9483 9748
9484 /* Use the type of the value to be shifted. */ 9749 /* Use the type of the value to be shifted. */
9485 result_type = type0; 9750 result_type = type0;
9486 /* Convert the shift-count to an integer, regardless of size 9751 /* Convert the non vector shift-count to an integer, regardless
9487 of value being shifted. */ 9752 of size of value being shifted. */
9488 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) 9753 if (TREE_CODE (TREE_TYPE (op1)) != VECTOR_TYPE
9754 && TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
9489 op1 = convert (integer_type_node, op1); 9755 op1 = convert (integer_type_node, op1);
9490 /* Avoid converting op1 to result_type later. */ 9756 /* Avoid converting op1 to result_type later. */
9491 converted = 1; 9757 converted = 1;
9492 } 9758 }
9493 break; 9759 break;
9708 int none_complex = (!first_complex && !second_complex); 9974 int none_complex = (!first_complex && !second_complex);
9709 9975
9710 if (shorten || common || short_compare) 9976 if (shorten || common || short_compare)
9711 { 9977 {
9712 result_type = c_common_type (type0, type1); 9978 result_type = c_common_type (type0, type1);
9979 do_warn_double_promotion (result_type, type0, type1,
9980 "implicit conversion from %qT to %qT "
9981 "to match other operand of binary "
9982 "expression",
9983 location);
9713 if (result_type == error_mark_node) 9984 if (result_type == error_mark_node)
9714 return error_mark_node; 9985 return error_mark_node;
9715 } 9986 }
9716 9987
9717 if (first_complex != second_complex 9988 if (first_complex != second_complex
9929 } 10200 }
9930 10201
9931 if (build_type == NULL_TREE) 10202 if (build_type == NULL_TREE)
9932 { 10203 {
9933 build_type = result_type; 10204 build_type = result_type;
9934 if (type0 != orig_type0 || type1 != orig_type1) 10205 if ((type0 != orig_type0 || type1 != orig_type1)
10206 && !boolean_op)
9935 { 10207 {
9936 gcc_assert (may_need_excess_precision && common); 10208 gcc_assert (may_need_excess_precision && common);
9937 semantic_result_type = c_common_type (orig_type0, orig_type1); 10209 semantic_result_type = c_common_type (orig_type0, orig_type1);
9938 } 10210 }
9939 } 10211 }
9996 10268
9997 case UNION_TYPE: 10269 case UNION_TYPE:
9998 error_at (location, "used union type value where scalar is required"); 10270 error_at (location, "used union type value where scalar is required");
9999 return error_mark_node; 10271 return error_mark_node;
10000 10272
10273 case VOID_TYPE:
10274 error_at (location, "void value not ignored as it ought to be");
10275 return error_mark_node;
10276
10001 case FUNCTION_TYPE: 10277 case FUNCTION_TYPE:
10002 gcc_unreachable (); 10278 gcc_unreachable ();
10003 10279
10004 default: 10280 default:
10005 break; 10281 break;
10008 int_const = (TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr)); 10284 int_const = (TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr));
10009 int_operands = EXPR_INT_CONST_OPERANDS (expr); 10285 int_operands = EXPR_INT_CONST_OPERANDS (expr);
10010 if (int_operands) 10286 if (int_operands)
10011 expr = remove_c_maybe_const_expr (expr); 10287 expr = remove_c_maybe_const_expr (expr);
10012 10288
10013 /* ??? Should we also give an error for void and vectors rather than 10289 /* ??? Should we also give an error for vectors rather than leaving
10014 leaving those to give errors later? */ 10290 those to give errors later? */
10015 expr = c_common_truthvalue_conversion (location, expr); 10291 expr = c_common_truthvalue_conversion (location, expr);
10016 10292
10017 if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const) 10293 if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
10018 { 10294 {
10019 if (TREE_OVERFLOW (expr)) 10295 if (TREE_OVERFLOW (expr))