00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "config.h"
00029 #include "system.h"
00030 #include "coretypes.h"
00031 #include "tm.h"
00032 #include "rtl.h"
00033 #include "tree.h"
00034 #include "langhooks.h"
00035 #include "c-tree.h"
00036 #include "tm_p.h"
00037 #include "flags.h"
00038 #include "output.h"
00039 #include "expr.h"
00040 #include "toplev.h"
00041 #include "intl.h"
00042 #include "ggc.h"
00043 #include "target.h"
00044 #include "tree-iterator.h"
00045 #include "tree-gimple.h"
00046 #include "tree-flow.h"
00047
00048
00049
00050 enum impl_conv {
00051 ic_argpass,
00052 ic_argpass_nonproto,
00053 ic_assign,
00054 ic_init,
00055 ic_return
00056 };
00057
00058
00059 int in_alignof;
00060
00061
00062 int in_sizeof;
00063
00064
00065 int in_typeof;
00066
00067 struct c_label_context_se *label_context_stack_se;
00068 struct c_label_context_vm *label_context_stack_vm;
00069
00070
00071
00072 static int missing_braces_mentioned;
00073
00074 static int require_constant_value;
00075 static int require_constant_elements;
00076
00077 static tree qualify_type (tree, tree);
00078 static int tagged_types_tu_compatible_p (tree, tree);
00079 static int comp_target_types (tree, tree, int);
00080 static int function_types_compatible_p (tree, tree);
00081 static int type_lists_compatible_p (tree, tree);
00082 static tree decl_constant_value_for_broken_optimization (tree);
00083 static tree default_function_array_conversion (tree);
00084 static tree lookup_field (tree, tree);
00085 static tree convert_arguments (tree, tree, tree, tree);
00086 static tree pointer_diff (tree, tree);
00087 static tree convert_for_assignment (tree, tree, enum impl_conv, tree, tree,
00088 int);
00089 static tree valid_compound_expr_initializer (tree, tree);
00090 static void push_string (const char *);
00091 static void push_member_name (tree);
00092 static void push_array_bounds (int);
00093 static int spelling_length (void);
00094 static char *print_spelling (char *);
00095 static void warning_init (const char *);
00096 static tree digest_init (tree, tree, bool, int);
00097 static void output_init_element (tree, bool, tree, tree, int);
00098 static void output_pending_init_elements (int);
00099 static int set_designator (int);
00100 static void push_range_stack (tree);
00101 static void add_pending_init (tree, tree);
00102 static void set_nonincremental_init (void);
00103 static void set_nonincremental_init_from_string (tree);
00104 static tree find_init_member (tree);
00105 static void readonly_error (tree, enum lvalue_use);
00106 static void record_maybe_used_decl (tree);
00107
00108
00109
00110
00111 tree
00112 require_complete_type (tree value)
00113 {
00114 tree type = TREE_TYPE (value);
00115
00116 if (value == error_mark_node || type == error_mark_node)
00117 return error_mark_node;
00118
00119
00120 if (COMPLETE_TYPE_P (type))
00121 return value;
00122
00123 c_incomplete_type_error (value, type);
00124 return error_mark_node;
00125 }
00126
00127
00128
00129
00130
00131 void
00132 c_incomplete_type_error (tree value, tree type)
00133 {
00134 const char *type_code_string;
00135
00136
00137 if (TREE_CODE (type) == ERROR_MARK)
00138 return;
00139
00140 if (value != 0 && (TREE_CODE (value) == VAR_DECL
00141 || TREE_CODE (value) == PARM_DECL))
00142 error ("%qs has an incomplete type",
00143 IDENTIFIER_POINTER (DECL_NAME (value)));
00144 else
00145 {
00146 retry:
00147
00148
00149 switch (TREE_CODE (type))
00150 {
00151 case RECORD_TYPE:
00152 type_code_string = "struct";
00153 break;
00154
00155 case UNION_TYPE:
00156 type_code_string = "union";
00157 break;
00158
00159 case ENUMERAL_TYPE:
00160 type_code_string = "enum";
00161 break;
00162
00163 case VOID_TYPE:
00164 error ("invalid use of void expression");
00165 return;
00166
00167 case ARRAY_TYPE:
00168 if (TYPE_DOMAIN (type))
00169 {
00170 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL)
00171 {
00172 error ("invalid use of flexible array member");
00173 return;
00174 }
00175 type = TREE_TYPE (type);
00176 goto retry;
00177 }
00178 error ("invalid use of array with unspecified bounds");
00179 return;
00180
00181 default:
00182 gcc_unreachable ();
00183 }
00184
00185 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
00186 error ("invalid use of undefined type %<%s %s%>",
00187 type_code_string, IDENTIFIER_POINTER (TYPE_NAME (type)));
00188 else
00189
00190 error ("invalid use of incomplete typedef %qs",
00191 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
00192 }
00193 }
00194
00195
00196
00197
00198 tree
00199 c_type_promotes_to (tree type)
00200 {
00201 if (TYPE_MAIN_VARIANT (type) == float_type_node)
00202 return double_type_node;
00203
00204 if (c_promoting_integer_type_p (type))
00205 {
00206
00207 if (TYPE_UNSIGNED (type)
00208 && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
00209 return unsigned_type_node;
00210 return integer_type_node;
00211 }
00212
00213 return type;
00214 }
00215
00216
00217
00218
00219 static tree
00220 qualify_type (tree type, tree like)
00221 {
00222 return c_build_qualified_type (type,
00223 TYPE_QUALS (type) | TYPE_QUALS (like));
00224 }
00225
00226
00227
00228
00229
00230
00231
00232 tree
00233 composite_type (tree t1, tree t2)
00234 {
00235 enum tree_code code1;
00236 enum tree_code code2;
00237 tree attributes;
00238
00239
00240
00241 if (t1 == t2) return t1;
00242
00243
00244 if (t1 == error_mark_node)
00245 return t2;
00246 if (t2 == error_mark_node)
00247 return t1;
00248
00249 code1 = TREE_CODE (t1);
00250 code2 = TREE_CODE (t2);
00251
00252
00253 attributes = targetm.merge_type_attributes (t1, t2);
00254
00255
00256
00257
00258
00259
00260 if (code1 == ENUMERAL_TYPE && code2 == INTEGER_TYPE)
00261 return t1;
00262 if (code2 == ENUMERAL_TYPE && code1 == INTEGER_TYPE)
00263 return t2;
00264
00265 gcc_assert (code1 == code2);
00266
00267 switch (code1)
00268 {
00269 case POINTER_TYPE:
00270
00271 {
00272 tree pointed_to_1 = TREE_TYPE (t1);
00273 tree pointed_to_2 = TREE_TYPE (t2);
00274 tree target = composite_type (pointed_to_1, pointed_to_2);
00275 t1 = build_pointer_type (target);
00276 t1 = build_type_attribute_variant (t1, attributes);
00277 return qualify_type (t1, t2);
00278 }
00279
00280 case ARRAY_TYPE:
00281 {
00282 tree elt = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
00283 int quals;
00284 tree unqual_elt;
00285
00286
00287 gcc_assert (!TYPE_QUALS (t1) && !TYPE_QUALS (t2));
00288
00289
00290 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
00291 return build_type_attribute_variant (t1, attributes);
00292 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
00293 return build_type_attribute_variant (t2, attributes);
00294
00295 if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
00296 return build_type_attribute_variant (t1, attributes);
00297 if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
00298 return build_type_attribute_variant (t2, attributes);
00299
00300
00301
00302
00303
00304
00305 quals = TYPE_QUALS (strip_array_types (elt));
00306 unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
00307 t1 = build_array_type (unqual_elt,
00308 TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
00309 t1 = c_build_qualified_type (t1, quals);
00310 return build_type_attribute_variant (t1, attributes);
00311 }
00312
00313 case FUNCTION_TYPE:
00314
00315
00316 {
00317 tree valtype = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
00318 tree p1 = TYPE_ARG_TYPES (t1);
00319 tree p2 = TYPE_ARG_TYPES (t2);
00320 int len;
00321 tree newargs, n;
00322 int i;
00323
00324
00325 if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
00326 return build_type_attribute_variant (t1, attributes);
00327 if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
00328 return build_type_attribute_variant (t2, attributes);
00329
00330
00331 if (TYPE_ARG_TYPES (t1) == 0)
00332 {
00333 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
00334 t1 = build_type_attribute_variant (t1, attributes);
00335 return qualify_type (t1, t2);
00336 }
00337 if (TYPE_ARG_TYPES (t2) == 0)
00338 {
00339 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
00340 t1 = build_type_attribute_variant (t1, attributes);
00341 return qualify_type (t1, t2);
00342 }
00343
00344
00345
00346
00347
00348 c_override_global_bindings_to_false = true;
00349
00350 len = list_length (p1);
00351 newargs = 0;
00352
00353 for (i = 0; i < len; i++)
00354 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
00355
00356 n = newargs;
00357
00358 for (; p1;
00359 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
00360 {
00361
00362
00363 if (TREE_VALUE (p1) == 0)
00364 {
00365 TREE_VALUE (n) = TREE_VALUE (p2);
00366 goto parm_done;
00367 }
00368 if (TREE_VALUE (p2) == 0)
00369 {
00370 TREE_VALUE (n) = TREE_VALUE (p1);
00371 goto parm_done;
00372 }
00373
00374
00375
00376
00377 if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
00378 && TREE_VALUE (p1) != TREE_VALUE (p2))
00379 {
00380 tree memb;
00381 tree mv2 = TREE_VALUE (p2);
00382 if (mv2 && mv2 != error_mark_node
00383 && TREE_CODE (mv2) != ARRAY_TYPE)
00384 mv2 = TYPE_MAIN_VARIANT (mv2);
00385 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
00386 memb; memb = TREE_CHAIN (memb))
00387 {
00388 tree mv3 = TREE_TYPE (memb);
00389 if (mv3 && mv3 != error_mark_node
00390 && TREE_CODE (mv3) != ARRAY_TYPE)
00391 mv3 = TYPE_MAIN_VARIANT (mv3);
00392 if (comptypes (mv3, mv2))
00393 {
00394 TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
00395 TREE_VALUE (p2));
00396 if (pedantic)
00397 pedwarn ("function types not truly compatible in ISO C");
00398 goto parm_done;
00399 }
00400 }
00401 }
00402 if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
00403 && TREE_VALUE (p2) != TREE_VALUE (p1))
00404 {
00405 tree memb;
00406 tree mv1 = TREE_VALUE (p1);
00407 if (mv1 && mv1 != error_mark_node
00408 && TREE_CODE (mv1) != ARRAY_TYPE)
00409 mv1 = TYPE_MAIN_VARIANT (mv1);
00410 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
00411 memb; memb = TREE_CHAIN (memb))
00412 {
00413 tree mv3 = TREE_TYPE (memb);
00414 if (mv3 && mv3 != error_mark_node
00415 && TREE_CODE (mv3) != ARRAY_TYPE)
00416 mv3 = TYPE_MAIN_VARIANT (mv3);
00417 if (comptypes (mv3, mv1))
00418 {
00419 TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
00420 TREE_VALUE (p1));
00421 if (pedantic)
00422 pedwarn ("function types not truly compatible in ISO C");
00423 goto parm_done;
00424 }
00425 }
00426 }
00427 TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2));
00428 parm_done: ;
00429 }
00430
00431 c_override_global_bindings_to_false = false;
00432 t1 = build_function_type (valtype, newargs);
00433 t1 = qualify_type (t1, t2);
00434
00435 }
00436
00437 default:
00438 return build_type_attribute_variant (t1, attributes);
00439 }
00440
00441 }
00442
00443
00444
00445
00446
00447
00448
00449 static tree
00450 common_pointer_type (tree t1, tree t2)
00451 {
00452 tree attributes;
00453 tree pointed_to_1, mv1;
00454 tree pointed_to_2, mv2;
00455 tree target;
00456
00457
00458
00459 if (t1 == t2) return t1;
00460
00461
00462 if (t1 == error_mark_node)
00463 return t2;
00464 if (t2 == error_mark_node)
00465 return t1;
00466
00467 gcc_assert (TREE_CODE (t1) == POINTER_TYPE
00468 && TREE_CODE (t2) == POINTER_TYPE);
00469
00470
00471 attributes = targetm.merge_type_attributes (t1, t2);
00472
00473
00474
00475
00476 mv1 = pointed_to_1 = TREE_TYPE (t1);
00477 mv2 = pointed_to_2 = TREE_TYPE (t2);
00478 if (TREE_CODE (mv1) != ARRAY_TYPE)
00479 mv1 = TYPE_MAIN_VARIANT (pointed_to_1);
00480 if (TREE_CODE (mv2) != ARRAY_TYPE)
00481 mv2 = TYPE_MAIN_VARIANT (pointed_to_2);
00482 target = composite_type (mv1, mv2);
00483 t1 = build_pointer_type (c_build_qualified_type
00484 (target,
00485 TYPE_QUALS (pointed_to_1) |
00486 TYPE_QUALS (pointed_to_2)));
00487 return build_type_attribute_variant (t1, attributes);
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498 static tree
00499 c_common_type (tree t1, tree t2)
00500 {
00501 enum tree_code code1;
00502 enum tree_code code2;
00503
00504
00505 if (t1 == error_mark_node)
00506 return t2;
00507 if (t2 == error_mark_node)
00508 return t1;
00509
00510 if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
00511 t1 = TYPE_MAIN_VARIANT (t1);
00512
00513 if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
00514 t2 = TYPE_MAIN_VARIANT (t2);
00515
00516 if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
00517 t1 = build_type_attribute_variant (t1, NULL_TREE);
00518
00519 if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
00520 t2 = build_type_attribute_variant (t2, NULL_TREE);
00521
00522
00523
00524 if (t1 == t2) return t1;
00525
00526 code1 = TREE_CODE (t1);
00527 code2 = TREE_CODE (t2);
00528
00529 gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
00530 || code1 == REAL_TYPE || code1 == INTEGER_TYPE);
00531 gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
00532 || code2 == REAL_TYPE || code2 == INTEGER_TYPE);
00533
00534
00535
00536
00537 if (code1 == VECTOR_TYPE)
00538 return t1;
00539
00540 if (code2 == VECTOR_TYPE)
00541 return t2;
00542
00543
00544
00545
00546 if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
00547 {
00548 tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
00549 tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
00550 tree subtype = c_common_type (subtype1, subtype2);
00551
00552 if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
00553 return t1;
00554 else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
00555 return t2;
00556 else
00557 return build_complex_type (subtype);
00558 }
00559
00560
00561
00562 if (code1 == REAL_TYPE && code2 != REAL_TYPE)
00563 return t1;
00564
00565 if (code2 == REAL_TYPE && code1 != REAL_TYPE)
00566 return t2;
00567
00568
00569
00570 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
00571 return t1;
00572 else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
00573 return t2;
00574
00575
00576
00577
00578
00579 if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
00580 || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
00581 return long_long_unsigned_type_node;
00582
00583 if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
00584 || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
00585 {
00586 if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
00587 return long_long_unsigned_type_node;
00588 else
00589 return long_long_integer_type_node;
00590 }
00591
00592 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
00593 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
00594 return long_unsigned_type_node;
00595
00596 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
00597 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
00598 {
00599
00600
00601 if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
00602 return long_unsigned_type_node;
00603 else
00604 return long_integer_type_node;
00605 }
00606
00607
00608 if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
00609 || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
00610 return long_double_type_node;
00611
00612
00613
00614 if (TYPE_UNSIGNED (t1))
00615 return t1;
00616 else
00617 return t2;
00618 }
00619
00620
00621
00622
00623 tree
00624 common_type (tree t1, tree t2)
00625 {
00626 if (TREE_CODE (t1) == ENUMERAL_TYPE)
00627 t1 = c_common_type_for_size (TYPE_PRECISION (t1), 1);
00628 if (TREE_CODE (t2) == ENUMERAL_TYPE)
00629 t2 = c_common_type_for_size (TYPE_PRECISION (t2), 1);
00630 return c_common_type (t1, t2);
00631 }
00632
00633
00634
00635
00636
00637 int
00638 comptypes (tree type1, tree type2)
00639 {
00640 tree t1 = type1;
00641 tree t2 = type2;
00642 int attrval, val;
00643
00644
00645
00646 if (t1 == t2 || !t1 || !t2
00647 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
00648 return 1;
00649
00650
00651
00652 if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1)
00653 && TYPE_ORIG_SIZE_TYPE (t1))
00654 t1 = TYPE_ORIG_SIZE_TYPE (t1);
00655
00656 if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2)
00657 && TYPE_ORIG_SIZE_TYPE (t2))
00658 t2 = TYPE_ORIG_SIZE_TYPE (t2);
00659
00660
00661
00662
00663
00664
00665 if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE)
00666 t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1));
00667 else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE)
00668 t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2));
00669
00670 if (t1 == t2)
00671 return 1;
00672
00673
00674
00675 if (TREE_CODE (t1) != TREE_CODE (t2))
00676 return 0;
00677
00678
00679
00680 if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
00681 return 0;
00682
00683
00684
00685
00686
00687 if (TREE_CODE (t1) != ARRAY_TYPE
00688 && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
00689 return 1;
00690
00691
00692 if (!(attrval = targetm.comp_type_attributes (t1, t2)))
00693 return 0;
00694
00695
00696 val = 0;
00697
00698 switch (TREE_CODE (t1))
00699 {
00700 case POINTER_TYPE:
00701
00702
00703 if (c_dialect_objc () && (val = objc_comptypes (t1, t2, 0)) >= 0)
00704 break;
00705
00706 if (TYPE_MODE (t1) != TYPE_MODE (t2)
00707 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
00708 break;
00709 val = (TREE_TYPE (t1) == TREE_TYPE (t2)
00710 ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
00711 break;
00712
00713 case FUNCTION_TYPE:
00714 val = function_types_compatible_p (t1, t2);
00715 break;
00716
00717 case ARRAY_TYPE:
00718 {
00719 tree d1 = TYPE_DOMAIN (t1);
00720 tree d2 = TYPE_DOMAIN (t2);
00721 bool d1_variable, d2_variable;
00722 bool d1_zero, d2_zero;
00723 val = 1;
00724
00725
00726 if (TREE_TYPE (t1) != TREE_TYPE (t2)
00727 && 0 == (val = comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
00728 return 0;
00729
00730
00731 if (d1 == 0 || d2 == 0 || d1 == d2)
00732 break;
00733
00734 d1_zero = !TYPE_MAX_VALUE (d1);
00735 d2_zero = !TYPE_MAX_VALUE (d2);
00736
00737 d1_variable = (!d1_zero
00738 && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
00739 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
00740 d2_variable = (!d2_zero
00741 && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
00742 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
00743
00744 if (d1_variable || d2_variable)
00745 break;
00746 if (d1_zero && d2_zero)
00747 break;
00748 if (d1_zero || d2_zero
00749 || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
00750 || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
00751 val = 0;
00752
00753 break;
00754 }
00755
00756 case RECORD_TYPE:
00757
00758
00759 if (c_dialect_objc () && objc_comptypes (t1, t2, 0) == 1)
00760 val = 1;
00761
00762 case ENUMERAL_TYPE:
00763 case UNION_TYPE:
00764 if (val != 1 && !same_translation_unit_p (t1, t2))
00765 val = tagged_types_tu_compatible_p (t1, t2);
00766 break;
00767
00768 case VECTOR_TYPE:
00769 val = TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
00770 && comptypes (TREE_TYPE (t1), TREE_TYPE (t2));
00771 break;
00772
00773 default:
00774 break;
00775 }
00776 return attrval == 2 && val == 1 ? 2 : val;
00777 }
00778
00779
00780
00781
00782
00783
00784
00785
00786 static int
00787 comp_target_types (tree ttl, tree ttr, int reflexive)
00788 {
00789 int val;
00790 tree mvl, mvr;
00791
00792
00793 if ((val = objc_comptypes (ttl, ttr, reflexive)) >= 0)
00794 return val;
00795
00796
00797
00798 mvl = TREE_TYPE (ttl);
00799 mvr = TREE_TYPE (ttr);
00800 if (TREE_CODE (mvl) != ARRAY_TYPE)
00801 mvl = TYPE_MAIN_VARIANT (mvl);
00802 if (TREE_CODE (mvr) != ARRAY_TYPE)
00803 mvr = TYPE_MAIN_VARIANT (mvr);
00804 val = comptypes (mvl, mvr);
00805
00806 if (val == 2 && pedantic)
00807 pedwarn ("types are not quite compatible");
00808 return val;
00809 }
00810
00811
00812
00813
00814
00815
00816
00817 int
00818 same_translation_unit_p (tree t1, tree t2)
00819 {
00820 while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL)
00821 switch (TREE_CODE_CLASS (TREE_CODE (t1)))
00822 {
00823 case tcc_declaration:
00824 t1 = DECL_CONTEXT (t1); break;
00825 case tcc_type:
00826 t1 = TYPE_CONTEXT (t1); break;
00827 case tcc_exceptional:
00828 t1 = BLOCK_SUPERCONTEXT (t1); break;
00829 default: gcc_unreachable ();
00830 }
00831
00832 while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL)
00833 switch (TREE_CODE_CLASS (TREE_CODE (t2)))
00834 {
00835 case tcc_declaration:
00836 t2 = DECL_CONTEXT (t2); break;
00837 case tcc_type:
00838 t2 = TYPE_CONTEXT (t2); break;
00839 case tcc_exceptional:
00840 t2 = BLOCK_SUPERCONTEXT (t2); break;
00841 default: gcc_unreachable ();
00842 }
00843
00844 return t1 == t2;
00845 }
00846
00847
00848
00849
00850
00851
00852 struct tagged_tu_seen {
00853 const struct tagged_tu_seen * next;
00854 tree t1;
00855 tree t2;
00856 };
00857
00858
00859
00860
00861 static const struct tagged_tu_seen * tagged_tu_seen_base;
00862
00863
00864
00865
00866
00867
00868
00869 static int
00870 tagged_types_tu_compatible_p (tree t1, tree t2)
00871 {
00872 tree s1, s2;
00873 bool needs_warning = false;
00874
00875
00876
00877
00878
00879
00880
00881 while (TYPE_NAME (t1)
00882 && TREE_CODE (TYPE_NAME (t1)) == TYPE_DECL
00883 && DECL_ORIGINAL_TYPE (TYPE_NAME (t1)))
00884 t1 = DECL_ORIGINAL_TYPE (TYPE_NAME (t1));
00885
00886 while (TYPE_NAME (t2)
00887 && TREE_CODE (TYPE_NAME (t2)) == TYPE_DECL
00888 && DECL_ORIGINAL_TYPE (TYPE_NAME (t2)))
00889 t2 = DECL_ORIGINAL_TYPE (TYPE_NAME (t2));
00890
00891
00892 if (flag_isoc99 && TYPE_NAME (t1) != TYPE_NAME (t2))
00893 return 0;
00894
00895
00896
00897
00898 if (TYPE_SIZE (t1) == NULL
00899 || TYPE_SIZE (t2) == NULL)
00900 return 1;
00901
00902 {
00903 const struct tagged_tu_seen * tts_i;
00904 for (tts_i = tagged_tu_seen_base; tts_i != NULL; tts_i = tts_i->next)
00905 if (tts_i->t1 == t1 && tts_i->t2 == t2)
00906 return 1;
00907 }
00908
00909 switch (TREE_CODE (t1))
00910 {
00911 case ENUMERAL_TYPE:
00912 {
00913
00914
00915 tree tv1 = TYPE_VALUES (t1);
00916 tree tv2 = TYPE_VALUES (t2);
00917
00918 if (tv1 == tv2)
00919 return 1;
00920
00921 for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
00922 {
00923 if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
00924 break;
00925 if (simple_cst_equal (TREE_VALUE (tv1), TREE_VALUE (tv2)) != 1)
00926 return 0;
00927 }
00928
00929 if (tv1 == NULL_TREE && tv2 == NULL_TREE)
00930 return 1;
00931 if (tv1 == NULL_TREE || tv2 == NULL_TREE)
00932 return 0;
00933
00934 if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
00935 return 0;
00936
00937 for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
00938 {
00939 s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
00940 if (s2 == NULL
00941 || simple_cst_equal (TREE_VALUE (s1), TREE_VALUE (s2)) != 1)
00942 return 0;
00943 }
00944 return 1;
00945 }
00946
00947 case UNION_TYPE:
00948 {
00949 if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
00950 return 0;
00951
00952 for (s1 = TYPE_FIELDS (t1); s1; s1 = TREE_CHAIN (s1))
00953 {
00954 bool ok = false;
00955 struct tagged_tu_seen tts;
00956
00957 tts.next = tagged_tu_seen_base;
00958 tts.t1 = t1;
00959 tts.t2 = t2;
00960 tagged_tu_seen_base = &tts;
00961
00962 if (DECL_NAME (s1) != NULL)
00963 for (s2 = TYPE_FIELDS (t2); s2; s2 = TREE_CHAIN (s2))
00964 if (DECL_NAME (s1) == DECL_NAME (s2))
00965 {
00966 int result;
00967 result = comptypes (TREE_TYPE (s1), TREE_TYPE (s2));
00968 if (result == 0)
00969 break;
00970 if (result == 2)
00971 needs_warning = true;
00972
00973 if (TREE_CODE (s1) == FIELD_DECL
00974 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
00975 DECL_FIELD_BIT_OFFSET (s2)) != 1)
00976 break;
00977
00978 ok = true;
00979 break;
00980 }
00981 tagged_tu_seen_base = tts.next;
00982 if (!ok)
00983 return 0;
00984 }
00985 return needs_warning ? 2 : 1;
00986 }
00987
00988 case RECORD_TYPE:
00989 {
00990 struct tagged_tu_seen tts;
00991
00992 tts.next = tagged_tu_seen_base;
00993 tts.t1 = t1;
00994 tts.t2 = t2;
00995 tagged_tu_seen_base = &tts;
00996
00997 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
00998 s1 && s2;
00999 s1 = TREE_CHAIN (s1), s2 = TREE_CHAIN (s2))
01000 {
01001 int result;
01002 if (TREE_CODE (s1) != TREE_CODE (s2)
01003 || DECL_NAME (s1) != DECL_NAME (s2))
01004 break;
01005 result = comptypes (TREE_TYPE (s1), TREE_TYPE (s2));
01006 if (result == 0)
01007 break;
01008 if (result == 2)
01009 needs_warning = true;
01010
01011 if (TREE_CODE (s1) == FIELD_DECL
01012 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
01013 DECL_FIELD_BIT_OFFSET (s2)) != 1)
01014 break;
01015 }
01016 tagged_tu_seen_base = tts.next;
01017 if (s1 && s2)
01018 return 0;
01019 return needs_warning ? 2 : 1;
01020 }
01021
01022 default:
01023 gcc_unreachable ();
01024 }
01025 }
01026
01027
01028
01029
01030
01031
01032
01033
01034 static int
01035 function_types_compatible_p (tree f1, tree f2)
01036 {
01037 tree args1, args2;
01038
01039 int val = 1;
01040 int val1;
01041 tree ret1, ret2;
01042
01043 ret1 = TREE_TYPE (f1);
01044 ret2 = TREE_TYPE (f2);
01045
01046
01047
01048 if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
01049 pedwarn ("function return types not compatible due to %<volatile%>");
01050 if (TYPE_VOLATILE (ret1))
01051 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
01052 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
01053 if (TYPE_VOLATILE (ret2))
01054 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
01055 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
01056 val = comptypes (ret1, ret2);
01057 if (val == 0)
01058 return 0;
01059
01060 args1 = TYPE_ARG_TYPES (f1);
01061 args2 = TYPE_ARG_TYPES (f2);
01062
01063
01064
01065
01066 if (args1 == 0)
01067 {
01068 if (!self_promoting_args_p (args2))
01069 return 0;
01070
01071
01072
01073 if (TYPE_ACTUAL_ARG_TYPES (f1)
01074 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
01075 val = 2;
01076 return val;
01077 }
01078 if (args2 == 0)
01079 {
01080 if (!self_promoting_args_p (args1))
01081 return 0;
01082 if (TYPE_ACTUAL_ARG_TYPES (f2)
01083 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
01084 val = 2;
01085 return val;
01086 }
01087
01088
01089 val1 = type_lists_compatible_p (args1, args2);
01090 return val1 != 1 ? val1 : val;
01091 }
01092
01093
01094
01095
01096
01097 static int
01098 type_lists_compatible_p (tree args1, tree args2)
01099 {
01100
01101 int val = 1;
01102 int newval = 0;
01103
01104 while (1)
01105 {
01106 tree a1, mv1, a2, mv2;
01107 if (args1 == 0 && args2 == 0)
01108 return val;
01109
01110
01111 if (args1 == 0 || args2 == 0)
01112 return 0;
01113 mv1 = a1 = TREE_VALUE (args1);
01114 mv2 = a2 = TREE_VALUE (args2);
01115 if (mv1 && mv1 != error_mark_node && TREE_CODE (mv1) != ARRAY_TYPE)
01116 mv1 = TYPE_MAIN_VARIANT (mv1);
01117 if (mv2 && mv2 != error_mark_node && TREE_CODE (mv2) != ARRAY_TYPE)
01118 mv2 = TYPE_MAIN_VARIANT (mv2);
01119
01120
01121
01122
01123 if (a1 == 0)
01124 {
01125 if (c_type_promotes_to (a2) != a2)
01126 return 0;
01127 }
01128 else if (a2 == 0)
01129 {
01130 if (c_type_promotes_to (a1) != a1)
01131 return 0;
01132 }
01133
01134 else if (TREE_CODE (a1) == ERROR_MARK
01135 || TREE_CODE (a2) == ERROR_MARK)
01136 ;
01137 else if (!(newval = comptypes (mv1, mv2)))
01138 {
01139
01140
01141 if (TREE_CODE (a1) == UNION_TYPE
01142 && (TYPE_NAME (a1) == 0
01143 || TYPE_TRANSPARENT_UNION (a1))
01144 && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
01145 && tree_int_cst_equal (TYPE_SIZE (a1),
01146 TYPE_SIZE (a2)))
01147 {
01148 tree memb;
01149 for (memb = TYPE_FIELDS (a1);
01150 memb; memb = TREE_CHAIN (memb))
01151 {
01152 tree mv3 = TREE_TYPE (memb);
01153 if (mv3 && mv3 != error_mark_node
01154 && TREE_CODE (mv3) != ARRAY_TYPE)
01155 mv3 = TYPE_MAIN_VARIANT (mv3);
01156 if (comptypes (mv3, mv2))
01157 break;
01158 }
01159 if (memb == 0)
01160 return 0;
01161 }
01162 else if (TREE_CODE (a2) == UNION_TYPE
01163 && (TYPE_NAME (a2) == 0
01164 || TYPE_TRANSPARENT_UNION (a2))
01165 && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
01166 && tree_int_cst_equal (TYPE_SIZE (a2),
01167 TYPE_SIZE (a1)))
01168 {
01169 tree memb;
01170 for (memb = TYPE_FIELDS (a2);
01171 memb; memb = TREE_CHAIN (memb))
01172 {
01173 tree mv3 = TREE_TYPE (memb);
01174 if (mv3 && mv3 != error_mark_node
01175 && TREE_CODE (mv3) != ARRAY_TYPE)
01176 mv3 = TYPE_MAIN_VARIANT (mv3);
01177 if (comptypes (mv3, mv1))
01178 break;
01179 }
01180 if (memb == 0)
01181 return 0;
01182 }
01183 else
01184 return 0;
01185 }
01186
01187
01188 if (newval > val)
01189 val = newval;
01190
01191 args1 = TREE_CHAIN (args1);
01192 args2 = TREE_CHAIN (args2);
01193 }
01194 }
01195
01196
01197
01198 static tree
01199 c_size_in_bytes (tree type)
01200 {
01201 enum tree_code code = TREE_CODE (type);
01202
01203 if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
01204 return size_one_node;
01205
01206 if (!COMPLETE_OR_VOID_TYPE_P (type))
01207 {
01208 error ("arithmetic on pointer to an incomplete type");
01209 return size_one_node;
01210 }
01211
01212
01213 return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
01214 size_int (TYPE_PRECISION (char_type_node)
01215 / BITS_PER_UNIT));
01216 }
01217
01218
01219
01220 tree
01221 decl_constant_value (tree decl)
01222 {
01223 if (
01224
01225
01226 current_function_decl != 0
01227 && TREE_CODE (decl) != PARM_DECL
01228 && !TREE_THIS_VOLATILE (decl)
01229 && TREE_READONLY (decl)
01230 && DECL_INITIAL (decl) != 0
01231 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
01232
01233
01234
01235 && TREE_CONSTANT (DECL_INITIAL (decl))
01236
01237 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
01238 return DECL_INITIAL (decl);
01239 return decl;
01240 }
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250 static tree
01251 decl_constant_value_for_broken_optimization (tree decl)
01252 {
01253 tree ret;
01254
01255 if (pedantic || DECL_MODE (decl) == BLKmode)
01256 return decl;
01257
01258 ret = decl_constant_value (decl);
01259
01260
01261
01262 if (ret != decl && TREE_STATIC (decl))
01263 ret = unshare_expr (ret);
01264 return ret;
01265 }
01266
01267
01268
01269
01270
01271
01272 static tree
01273 default_function_array_conversion (tree exp)
01274 {
01275 tree orig_exp;
01276 tree type = TREE_TYPE (exp);
01277 enum tree_code code = TREE_CODE (type);
01278 int not_lvalue = 0;
01279
01280
01281
01282
01283
01284
01285 orig_exp = exp;
01286 while (TREE_CODE (exp) == NON_LVALUE_EXPR
01287 || (TREE_CODE (exp) == NOP_EXPR
01288 && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
01289 {
01290 if (TREE_CODE (exp) == NON_LVALUE_EXPR)
01291 not_lvalue = 1;
01292 exp = TREE_OPERAND (exp, 0);
01293 }
01294
01295 if (TREE_NO_WARNING (orig_exp))
01296 TREE_NO_WARNING (exp) = 1;
01297
01298 if (code == FUNCTION_TYPE)
01299 {
01300 return build_unary_op (ADDR_EXPR, exp, 0);
01301 }
01302 if (code == ARRAY_TYPE)
01303 {
01304 tree adr;
01305 tree restype = TREE_TYPE (type);
01306 tree ptrtype;
01307 int constp = 0;
01308 int volatilep = 0;
01309 int lvalue_array_p;
01310
01311 if (REFERENCE_CLASS_P (exp) || DECL_P (exp))
01312 {
01313 constp = TREE_READONLY (exp);
01314 volatilep = TREE_THIS_VOLATILE (exp);
01315 }
01316
01317 if (TYPE_QUALS (type) || constp || volatilep)
01318 restype
01319 = c_build_qualified_type (restype,
01320 TYPE_QUALS (type)
01321 | (constp * TYPE_QUAL_CONST)
01322 | (volatilep * TYPE_QUAL_VOLATILE));
01323
01324 if (TREE_CODE (exp) == INDIRECT_REF)
01325 return convert (build_pointer_type (restype),
01326 TREE_OPERAND (exp, 0));
01327
01328 if (TREE_CODE (exp) == COMPOUND_EXPR)
01329 {
01330 tree op1 = default_conversion (TREE_OPERAND (exp, 1));
01331 return build2 (COMPOUND_EXPR, TREE_TYPE (op1),
01332 TREE_OPERAND (exp, 0), op1);
01333 }
01334
01335 lvalue_array_p = !not_lvalue && lvalue_p (exp);
01336 if (!flag_isoc99 && !lvalue_array_p)
01337 {
01338
01339
01340
01341
01342 return exp;
01343 }
01344
01345 ptrtype = build_pointer_type (restype);
01346
01347 if (TREE_CODE (exp) == VAR_DECL)
01348 {
01349
01350
01351
01352
01353 adr = build1 (ADDR_EXPR, ptrtype, exp);
01354 if (!c_mark_addressable (exp))
01355 return error_mark_node;
01356 TREE_SIDE_EFFECTS (adr) = 0;
01357 return adr;
01358 }
01359
01360
01361 adr = build_unary_op (ADDR_EXPR, exp, 1);
01362 return convert (ptrtype, adr);
01363 }
01364 return exp;
01365 }
01366
01367
01368
01369
01370
01371
01372 tree
01373 default_conversion (tree exp)
01374 {
01375 tree orig_exp;
01376 tree type = TREE_TYPE (exp);
01377 enum tree_code code = TREE_CODE (type);
01378
01379 if (code == FUNCTION_TYPE || code == ARRAY_TYPE)
01380 return default_function_array_conversion (exp);
01381
01382
01383 if (TREE_CODE (exp) == CONST_DECL)
01384 exp = DECL_INITIAL (exp);
01385
01386
01387
01388
01389 else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE)
01390 {
01391 exp = decl_constant_value_for_broken_optimization (exp);
01392 type = TREE_TYPE (exp);
01393 }
01394
01395
01396
01397
01398
01399
01400 orig_exp = exp;
01401 while (TREE_CODE (exp) == NON_LVALUE_EXPR
01402 || (TREE_CODE (exp) == NOP_EXPR
01403 && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
01404 exp = TREE_OPERAND (exp, 0);
01405
01406 if (TREE_NO_WARNING (orig_exp))
01407 TREE_NO_WARNING (exp) = 1;
01408
01409
01410
01411 if (code == ENUMERAL_TYPE)
01412 {
01413 type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
01414 TYPE_PRECISION (integer_type_node)),
01415 ((TYPE_PRECISION (type)
01416 >= TYPE_PRECISION (integer_type_node))
01417 && TYPE_UNSIGNED (type)));
01418
01419 return convert (type, exp);
01420 }
01421
01422 if (TREE_CODE (exp) == COMPONENT_REF
01423 && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
01424
01425
01426 && 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
01427 TYPE_PRECISION (integer_type_node)))
01428 return convert (integer_type_node, exp);
01429
01430 if (c_promoting_integer_type_p (type))
01431 {
01432
01433 if (TYPE_UNSIGNED (type)
01434 && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
01435 return convert (unsigned_type_node, exp);
01436
01437 return convert (integer_type_node, exp);
01438 }
01439
01440 if (code == VOID_TYPE)
01441 {
01442 error ("void value not ignored as it ought to be");
01443 return error_mark_node;
01444 }
01445 return exp;
01446 }
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457 static tree
01458 lookup_field (tree decl, tree component)
01459 {
01460 tree type = TREE_TYPE (decl);
01461 tree field;
01462
01463
01464
01465
01466
01467
01468 if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s)
01469 {
01470 int bot, top, half;
01471 tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
01472
01473 field = TYPE_FIELDS (type);
01474 bot = 0;
01475 top = TYPE_LANG_SPECIFIC (type)->s->len;
01476 while (top - bot > 1)
01477 {
01478 half = (top - bot + 1) >> 1;
01479 field = field_array[bot+half];
01480
01481 if (DECL_NAME (field) == NULL_TREE)
01482 {
01483
01484 while (DECL_NAME (field_array[bot]) == NULL_TREE)
01485 {
01486 field = field_array[bot++];
01487 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
01488 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
01489 {
01490 tree anon = lookup_field (field, component);
01491
01492 if (anon)
01493 return tree_cons (NULL_TREE, field, anon);
01494 }
01495 }
01496
01497
01498 if (bot > top)
01499 return NULL_TREE;
01500
01501
01502 continue;
01503 }
01504
01505 if (DECL_NAME (field) == component)
01506 break;
01507 if (DECL_NAME (field) < component)
01508 bot += half;
01509 else
01510 top = bot + half;
01511 }
01512
01513 if (DECL_NAME (field_array[bot]) == component)
01514 field = field_array[bot];
01515 else if (DECL_NAME (field) != component)
01516 return NULL_TREE;
01517 }
01518 else
01519 {
01520 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
01521 {
01522 if (DECL_NAME (field) == NULL_TREE
01523 && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
01524 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE))
01525 {
01526 tree anon = lookup_field (field, component);
01527
01528 if (anon)
01529 return tree_cons (NULL_TREE, field, anon);
01530 }
01531
01532 if (DECL_NAME (field) == component)
01533 break;
01534 }
01535
01536 if (field == NULL_TREE)
01537 return NULL_TREE;
01538 }
01539
01540 return tree_cons (NULL_TREE, field, NULL_TREE);
01541 }
01542
01543
01544
01545
01546 tree
01547 build_component_ref (tree datum, tree component)
01548 {
01549 tree type = TREE_TYPE (datum);
01550 enum tree_code code = TREE_CODE (type);
01551 tree field = NULL;
01552 tree ref;
01553
01554 if (!objc_is_public (datum, component))
01555 return error_mark_node;
01556
01557
01558
01559 if (code == RECORD_TYPE || code == UNION_TYPE)
01560 {
01561 if (!COMPLETE_TYPE_P (type))
01562 {
01563 c_incomplete_type_error (NULL_TREE, type);
01564 return error_mark_node;
01565 }
01566
01567 field = lookup_field (datum, component);
01568
01569 if (!field)
01570 {
01571 error ("%qT has no member named %qs", type,
01572 IDENTIFIER_POINTER (component));
01573 return error_mark_node;
01574 }
01575
01576
01577
01578
01579
01580
01581 do
01582 {
01583 tree subdatum = TREE_VALUE (field);
01584
01585 if (TREE_TYPE (subdatum) == error_mark_node)
01586 return error_mark_node;
01587
01588 ref = build3 (COMPONENT_REF, TREE_TYPE (subdatum), datum, subdatum,
01589 NULL_TREE);
01590 if (TREE_READONLY (datum) || TREE_READONLY (subdatum))
01591 TREE_READONLY (ref) = 1;
01592 if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (subdatum))
01593 TREE_THIS_VOLATILE (ref) = 1;
01594
01595 if (TREE_DEPRECATED (subdatum))
01596 warn_deprecated_use (subdatum);
01597
01598 datum = ref;
01599
01600 field = TREE_CHAIN (field);
01601 }
01602 while (field);
01603
01604 return ref;
01605 }
01606 else if (code != ERROR_MARK)
01607 error ("request for member %qs in something not a structure or union",
01608 IDENTIFIER_POINTER (component));
01609
01610 return error_mark_node;
01611 }
01612
01613
01614
01615
01616
01617 tree
01618 build_indirect_ref (tree ptr, const char *errorstring)
01619 {
01620 tree pointer = default_conversion (ptr);
01621 tree type = TREE_TYPE (pointer);
01622
01623 if (TREE_CODE (type) == POINTER_TYPE)
01624 {
01625 if (TREE_CODE (pointer) == ADDR_EXPR
01626 && (TREE_TYPE (TREE_OPERAND (pointer, 0))
01627 == TREE_TYPE (type)))
01628 return TREE_OPERAND (pointer, 0);
01629 else
01630 {
01631 tree t = TREE_TYPE (type);
01632 tree mvt = t;
01633 tree ref;
01634
01635 if (TREE_CODE (mvt) != ARRAY_TYPE)
01636 mvt = TYPE_MAIN_VARIANT (mvt);
01637 ref = build1 (INDIRECT_REF, mvt, pointer);
01638
01639 if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE)
01640 {
01641 error ("dereferencing pointer to incomplete type");
01642 return error_mark_node;
01643 }
01644 if (VOID_TYPE_P (t) && skip_evaluation == 0)
01645 warning ("dereferencing %<void *%> pointer");
01646
01647
01648
01649
01650
01651
01652
01653
01654 TREE_READONLY (ref) = TYPE_READONLY (t);
01655 TREE_SIDE_EFFECTS (ref)
01656 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
01657 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
01658 return ref;
01659 }
01660 }
01661 else if (TREE_CODE (pointer) != ERROR_MARK)
01662 error ("invalid type argument of %qs", errorstring);
01663 return error_mark_node;
01664 }
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675 tree
01676 build_array_ref (tree array, tree index)
01677 {
01678 bool swapped = false;
01679 if (TREE_TYPE (array) == error_mark_node
01680 || TREE_TYPE (index) == error_mark_node)
01681 return error_mark_node;
01682
01683 if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
01684 && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE)
01685 {
01686 tree temp;
01687 if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
01688 && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
01689 {
01690 error ("subscripted value is neither array nor pointer");
01691 return error_mark_node;
01692 }
01693 temp = array;
01694 array = index;
01695 index = temp;
01696 swapped = true;
01697 }
01698
01699 if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
01700 {
01701 error ("array subscript is not an integer");
01702 return error_mark_node;
01703 }
01704
01705 if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
01706 {
01707 error ("subscripted value is pointer to function");
01708 return error_mark_node;
01709 }
01710
01711
01712
01713
01714
01715
01716
01717
01718 if (warn_char_subscripts && !swapped
01719 && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
01720 warning ("array subscript has type %<char%>");
01721
01722
01723 index = default_conversion (index);
01724
01725 gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE);
01726
01727 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
01728 {
01729 tree rval, type;
01730
01731
01732
01733
01734
01735 if (TREE_CODE (index) != INTEGER_CST
01736 || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
01737 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
01738 {
01739 if (!c_mark_addressable (array))
01740 return error_mark_node;
01741 }
01742
01743
01744
01745
01746 if (TREE_CODE (index) == INTEGER_CST
01747 && TYPE_DOMAIN (TREE_TYPE (array))
01748 && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
01749 {
01750 if (!c_mark_addressable (array))
01751 return error_mark_node;
01752 }
01753
01754 if (pedantic)
01755 {
01756 tree foo = array;
01757 while (TREE_CODE (foo) == COMPONENT_REF)
01758 foo = TREE_OPERAND (foo, 0);
01759 if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo))
01760 pedwarn ("ISO C forbids subscripting %<register%> array");
01761 else if (!flag_isoc99 && !lvalue_p (foo))
01762 pedwarn ("ISO C90 forbids subscripting non-lvalue array");
01763 }
01764
01765 type = TREE_TYPE (TREE_TYPE (array));
01766 if (TREE_CODE (type) != ARRAY_TYPE)
01767 type = TYPE_MAIN_VARIANT (type);
01768 rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
01769
01770
01771 TREE_READONLY (rval)
01772 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
01773 | TREE_READONLY (array));
01774 TREE_SIDE_EFFECTS (rval)
01775 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
01776 | TREE_SIDE_EFFECTS (array));
01777 TREE_THIS_VOLATILE (rval)
01778 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
01779
01780
01781
01782
01783 | TREE_THIS_VOLATILE (array));
01784 return require_complete_type (fold (rval));
01785 }
01786 else
01787 {
01788 tree ar = default_conversion (array);
01789
01790 if (ar == error_mark_node)
01791 return ar;
01792
01793 gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
01794 gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
01795
01796 return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, index, 0),
01797 "array indexing");
01798 }
01799 }
01800
01801
01802
01803 tree
01804 build_external_ref (tree id, int fun)
01805 {
01806 tree ref;
01807 tree decl = lookup_name (id);
01808
01809
01810
01811 decl = objc_lookup_ivar (decl, id);
01812
01813 if (decl && decl != error_mark_node)
01814 ref = decl;
01815 else if (fun)
01816
01817 ref = implicitly_declare (id);
01818 else if (decl == error_mark_node)
01819
01820
01821 return error_mark_node;
01822 else
01823 {
01824 undeclared_variable (id);
01825 return error_mark_node;
01826 }
01827
01828 if (TREE_TYPE (ref) == error_mark_node)
01829 return error_mark_node;
01830
01831 if (TREE_DEPRECATED (ref))
01832 warn_deprecated_use (ref);
01833
01834 if (!skip_evaluation)
01835 assemble_external (ref);
01836 TREE_USED (ref) = 1;
01837
01838 if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof)
01839 {
01840 if (!in_sizeof && !in_typeof)
01841 C_DECL_USED (ref) = 1;
01842 else if (DECL_INITIAL (ref) == 0
01843 && DECL_EXTERNAL (ref)
01844 && !TREE_PUBLIC (ref))
01845 record_maybe_used_decl (ref);
01846 }
01847
01848 if (TREE_CODE (ref) == CONST_DECL)
01849 {
01850 ref = DECL_INITIAL (ref);
01851 TREE_CONSTANT (ref) = 1;
01852 TREE_INVARIANT (ref) = 1;
01853 }
01854 else if (current_function_decl != 0
01855 && !DECL_FILE_SCOPE_P (current_function_decl)
01856 && (TREE_CODE (ref) == VAR_DECL
01857 || TREE_CODE (ref) == PARM_DECL
01858 || TREE_CODE (ref) == FUNCTION_DECL))
01859 {
01860 tree context = decl_function_context (ref);
01861
01862 if (context != 0 && context != current_function_decl)
01863 DECL_NONLOCAL (ref) = 1;
01864 }
01865
01866 return ref;
01867 }
01868
01869
01870 struct maybe_used_decl
01871 {
01872
01873 tree decl;
01874
01875 int level;
01876
01877 struct maybe_used_decl *next;
01878 };
01879
01880 static struct maybe_used_decl *maybe_used_decls;
01881
01882
01883
01884
01885
01886
01887 static void
01888 record_maybe_used_decl (tree decl)
01889 {
01890 struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
01891 t->decl = decl;
01892 t->level = in_sizeof + in_typeof;
01893 t->next = maybe_used_decls;
01894 maybe_used_decls = t;
01895 }
01896
01897
01898
01899
01900
01901
01902 void
01903 pop_maybe_used (bool used)
01904 {
01905 struct maybe_used_decl *p = maybe_used_decls;
01906 int cur_level = in_sizeof + in_typeof;
01907 while (p && p->level > cur_level)
01908 {
01909 if (used)
01910 {
01911 if (cur_level == 0)
01912 C_DECL_USED (p->decl) = 1;
01913 else
01914 p->level = cur_level;
01915 }
01916 p = p->next;
01917 }
01918 if (!used || cur_level == 0)
01919 maybe_used_decls = p;
01920 }
01921
01922
01923
01924 struct c_expr
01925 c_expr_sizeof_expr (struct c_expr expr)
01926 {
01927 struct c_expr ret;
01928 if (expr.value == error_mark_node)
01929 {
01930 ret.value = error_mark_node;
01931 ret.original_code = ERROR_MARK;
01932 pop_maybe_used (false);
01933 }
01934 else
01935 {
01936 ret.value = c_sizeof (TREE_TYPE (expr.value));
01937 ret.original_code = ERROR_MARK;
01938 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr.value)));
01939 }
01940 return ret;
01941 }
01942
01943
01944
01945
01946 struct c_expr
01947 c_expr_sizeof_type (struct c_type_name *t)
01948 {
01949 tree type;
01950 struct c_expr ret;
01951 type = groktypename (t);
01952 ret.value = c_sizeof (type);
01953 ret.original_code = ERROR_MARK;
01954 pop_maybe_used (C_TYPE_VARIABLE_SIZE (type));
01955 return ret;
01956 }
01957
01958
01959
01960
01961
01962
01963 tree
01964 build_function_call (tree function, tree params)
01965 {
01966 tree fntype, fundecl = 0;
01967 tree coerced_params;
01968 tree name = NULL_TREE, result;
01969 tree tem;
01970
01971
01972 STRIP_TYPE_NOPS (function);
01973
01974
01975 if (TREE_CODE (function) == FUNCTION_DECL)
01976 {
01977 name = DECL_NAME (function);
01978
01979
01980
01981
01982 fntype = build_type_variant (TREE_TYPE (function),
01983 TREE_READONLY (function),
01984 TREE_THIS_VOLATILE (function));
01985 fundecl = function;
01986 function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
01987 }
01988 else
01989 function = default_conversion (function);
01990
01991 fntype = TREE_TYPE (function);
01992
01993 if (TREE_CODE (fntype) == ERROR_MARK)
01994 return error_mark_node;
01995
01996 if (!(TREE_CODE (fntype) == POINTER_TYPE
01997 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
01998 {
01999 error ("called object %qE is not a function", function);
02000 return error_mark_node;
02001 }
02002
02003 if (fundecl && TREE_THIS_VOLATILE (fundecl))
02004 current_function_returns_abnormally = 1;
02005
02006
02007 fntype = TREE_TYPE (fntype);
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018 if (!c_dialect_objc ()
02019 && TREE_CODE (function) == NOP_EXPR
02020 && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
02021 && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
02022 && !comptypes (fntype, TREE_TYPE (tem)))
02023 {
02024 tree return_type = TREE_TYPE (fntype);
02025 tree trap = build_function_call (built_in_decls[BUILT_IN_TRAP],
02026 NULL_TREE);
02027
02028
02029
02030
02031 warning ("function called through a non-compatible type");
02032
02033
02034
02035 inform ("if this code is reached, the program will abort");
02036
02037 if (VOID_TYPE_P (return_type))
02038 return trap;
02039 else
02040 {
02041 tree rhs;
02042
02043 if (AGGREGATE_TYPE_P (return_type))
02044 rhs = build_compound_literal (return_type,
02045 build_constructor (return_type,
02046 NULL_TREE));
02047 else
02048 rhs = fold (build1 (NOP_EXPR, return_type, integer_zero_node));
02049
02050 return build2 (COMPOUND_EXPR, return_type, trap, rhs);
02051 }
02052 }
02053
02054
02055
02056
02057 coerced_params
02058 = convert_arguments (TYPE_ARG_TYPES (fntype), params, function, fundecl);
02059
02060 if (coerced_params == error_mark_node)
02061 return error_mark_node;
02062
02063
02064
02065 check_function_arguments (TYPE_ATTRIBUTES (fntype), coerced_params,
02066 TYPE_ARG_TYPES (fntype));
02067
02068 result = build3 (CALL_EXPR, TREE_TYPE (fntype),
02069 function, coerced_params, NULL_TREE);
02070 TREE_SIDE_EFFECTS (result) = 1;
02071
02072 if (require_constant_value)
02073 {
02074 result = fold_initializer (result);
02075
02076 if (TREE_CONSTANT (result)
02077 && (name == NULL_TREE
02078 || strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10) != 0))
02079 pedwarn_init ("initializer element is not constant");
02080 }
02081 else
02082 result = fold (result);
02083
02084 if (VOID_TYPE_P (TREE_TYPE (result)))
02085 return result;
02086 return require_complete_type (result);
02087 }
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109 static tree
02110 convert_arguments (tree typelist, tree values, tree function, tree fundecl)
02111 {
02112 tree typetail, valtail;
02113 tree result = NULL;
02114 int parmnum;
02115 tree selector;
02116
02117
02118
02119 if (TREE_CODE (function) == ADDR_EXPR
02120 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
02121 function = TREE_OPERAND (function, 0);
02122
02123
02124 selector = objc_message_selector ();
02125
02126
02127
02128
02129 for (valtail = values, typetail = typelist, parmnum = 0;
02130 valtail;
02131 valtail = TREE_CHAIN (valtail), parmnum++)
02132 {
02133 tree type = typetail ? TREE_VALUE (typetail) : 0;
02134 tree val = TREE_VALUE (valtail);
02135 tree rname = function;
02136 int argnum = parmnum + 1;
02137
02138 if (type == void_type_node)
02139 {
02140 error ("too many arguments to function %qE", function);
02141 break;
02142 }
02143
02144 if (selector && argnum > 2)
02145 {
02146 rname = selector;
02147 argnum -= 2;
02148 }
02149
02150
02151
02152
02153 if (TREE_CODE (val) == NON_LVALUE_EXPR)
02154 val = TREE_OPERAND (val, 0);
02155
02156 val = default_function_array_conversion (val);
02157
02158 val = require_complete_type (val);
02159
02160 if (type != 0)
02161 {
02162
02163 tree parmval;
02164
02165 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
02166 {
02167 error ("type of formal parameter %d is incomplete", parmnum + 1);
02168 parmval = val;
02169 }
02170 else
02171 {
02172
02173
02174 if (warn_conversion || warn_traditional)
02175 {
02176 unsigned int formal_prec = TYPE_PRECISION (type);
02177
02178 if (INTEGRAL_TYPE_P (type)
02179 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
02180 warning ("passing argument %d of %qE as integer "
02181 "rather than floating due to prototype",
02182 argnum, rname);
02183 if (INTEGRAL_TYPE_P (type)
02184 && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
02185 warning ("passing argument %d of %qE as integer "
02186 "rather than complex due to prototype",
02187 argnum, rname);
02188 else if (TREE_CODE (type) == COMPLEX_TYPE
02189 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
02190 warning ("passing argument %d of %qE as complex "
02191 "rather than floating due to prototype",
02192 argnum, rname);
02193 else if (TREE_CODE (type) == REAL_TYPE
02194 && INTEGRAL_TYPE_P (TREE_TYPE (val)))
02195 warning ("passing argument %d of %qE as floating "
02196 "rather than integer due to prototype",
02197 argnum, rname);
02198 else if (TREE_CODE (type) == COMPLEX_TYPE
02199 && INTEGRAL_TYPE_P (TREE_TYPE (val)))
02200 warning ("passing argument %d of %qE as complex "
02201 "rather than integer due to prototype",
02202 argnum, rname);
02203 else if (TREE_CODE (type) == REAL_TYPE
02204 && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
02205 warning ("passing argument %d of %qE as floating "
02206 "rather than complex due to prototype",
02207 argnum, rname);
02208
02209
02210
02211 else if (TREE_CODE (type) == REAL_TYPE
02212 && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
02213 {
02214
02215
02216 if (formal_prec == TYPE_PRECISION (float_type_node))
02217 warning ("passing argument %d of %qE as %<float%> "
02218 "rather than %<double%> due to prototype",
02219 argnum, rname);
02220 }
02221
02222
02223
02224 else if (warn_conversion && INTEGRAL_TYPE_P (type)
02225 && INTEGRAL_TYPE_P (TREE_TYPE (val)))
02226 {
02227 tree would_have_been = default_conversion (val);
02228 tree type1 = TREE_TYPE (would_have_been);
02229
02230 if (TREE_CODE (type) == ENUMERAL_TYPE
02231 && (TYPE_MAIN_VARIANT (type)
02232 == TYPE_MAIN_VARIANT (TREE_TYPE (val))))
02233
02234
02235 ;
02236 else if (formal_prec != TYPE_PRECISION (type1))
02237 warning ("passing argument %d of %qE with different "
02238 "width due to prototype", argnum, rname);
02239 else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
02240 ;
02241
02242
02243
02244 else if (TREE_CODE (type) == ENUMERAL_TYPE)
02245 ;
02246 else if (TREE_CODE (val) == INTEGER_CST
02247 && int_fits_type_p (val, type))
02248
02249
02250 ;
02251
02252 else if (TREE_CODE (val) == NOP_EXPR
02253 && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST
02254 && int_fits_type_p (TREE_OPERAND (val, 0), type))
02255 ;
02256
02257
02258
02259
02260 else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
02261 && TYPE_UNSIGNED (TREE_TYPE (val)))
02262 ;
02263 else if (TYPE_UNSIGNED (type))
02264 warning ("passing argument %d of %qE as unsigned "
02265 "due to prototype", argnum, rname);
02266 else
02267 warning ("passing argument %d of %qE as signed "
02268 "due to prototype", argnum, rname);
02269 }
02270 }
02271
02272 parmval = convert_for_assignment (type, val, ic_argpass,
02273 fundecl, function,
02274 parmnum + 1);
02275
02276 if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0)
02277 && INTEGRAL_TYPE_P (type)
02278 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
02279 parmval = default_conversion (parmval);
02280 }
02281 result = tree_cons (NULL_TREE, parmval, result);
02282 }
02283 else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
02284 && (TYPE_PRECISION (TREE_TYPE (val))
02285 < TYPE_PRECISION (double_type_node)))
02286
02287 result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
02288 else
02289
02290 result = tree_cons (NULL_TREE, default_conversion (val), result);
02291
02292 if (typetail)
02293 typetail = TREE_CHAIN (typetail);
02294 }
02295
02296 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
02297 {
02298 error ("too few arguments to function %qE", function);
02299 return error_mark_node;
02300 }
02301
02302 return nreverse (result);
02303 }
02304
02305
02306
02307
02308
02309
02310
02311 struct c_expr
02312 parser_build_binary_op (enum tree_code code, struct c_expr arg1,
02313 struct c_expr arg2)
02314 {
02315 struct c_expr result;
02316
02317 enum tree_code code1 = arg1.original_code;
02318 enum tree_code code2 = arg2.original_code;
02319
02320 result.value = build_binary_op (code, arg1.value, arg2.value, 1);
02321 result.original_code = code;
02322
02323 if (TREE_CODE (result.value) == ERROR_MARK)
02324 return result;
02325
02326
02327
02328 if (warn_parentheses)
02329 {
02330 if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
02331 {
02332 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
02333 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
02334 warning ("suggest parentheses around + or - inside shift");
02335 }
02336
02337 if (code == TRUTH_ORIF_EXPR)
02338 {
02339 if (code1 == TRUTH_ANDIF_EXPR
02340 || code2 == TRUTH_ANDIF_EXPR)
02341 warning ("suggest parentheses around && within ||");
02342 }
02343
02344 if (code == BIT_IOR_EXPR)
02345 {
02346 if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
02347 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
02348 || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
02349 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
02350 warning ("suggest parentheses around arithmetic in operand of |");
02351
02352 if (TREE_CODE_CLASS (code1) == tcc_comparison
02353 || TREE_CODE_CLASS (code2) == tcc_comparison)
02354 warning ("suggest parentheses around comparison in operand of |");
02355 }
02356
02357 if (code == BIT_XOR_EXPR)
02358 {
02359 if (code1 == BIT_AND_EXPR
02360 || code1 == PLUS_EXPR || code1 == MINUS_EXPR
02361 || code2 == BIT_AND_EXPR
02362 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
02363 warning ("suggest parentheses around arithmetic in operand of ^");
02364
02365 if (TREE_CODE_CLASS (code1) == tcc_comparison
02366 || TREE_CODE_CLASS (code2) == tcc_comparison)
02367 warning ("suggest parentheses around comparison in operand of ^");
02368 }
02369
02370 if (code == BIT_AND_EXPR)
02371 {
02372 if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
02373 || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
02374 warning ("suggest parentheses around + or - in operand of &");
02375
02376 if (TREE_CODE_CLASS (code1) == tcc_comparison
02377 || TREE_CODE_CLASS (code2) == tcc_comparison)
02378 warning ("suggest parentheses around comparison in operand of &");
02379 }
02380
02381 if (TREE_CODE_CLASS (code) == tcc_comparison
02382 && (TREE_CODE_CLASS (code1) == tcc_comparison
02383 || TREE_CODE_CLASS (code2) == tcc_comparison))
02384 warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
02385
02386 }
02387
02388 unsigned_conversion_warning (result.value, arg1.value);
02389 unsigned_conversion_warning (result.value, arg2.value);
02390 overflow_warning (result.value);
02391
02392 return result;
02393 }
02394
02395
02396
02397
02398 static tree
02399 pointer_diff (tree op0, tree op1)
02400 {
02401 tree restype = ptrdiff_type_node;
02402
02403 tree target_type = TREE_TYPE (TREE_TYPE (op0));
02404 tree con0, con1, lit0, lit1;
02405 tree orig_op1 = op1;
02406
02407 if (pedantic || warn_pointer_arith)
02408 {
02409 if (TREE_CODE (target_type) == VOID_TYPE)
02410 pedwarn ("pointer of type %<void *%> used in subtraction");
02411 if (TREE_CODE (target_type) == FUNCTION_TYPE)
02412 pedwarn ("pointer to a function used in subtraction");
02413 }
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423 con0 = TREE_CODE (op0) == NOP_EXPR ? TREE_OPERAND (op0, 0) : op0;
02424 con1 = TREE_CODE (op1) == NOP_EXPR ? TREE_OPERAND (op1, 0) : op1;
02425
02426 if (TREE_CODE (con0) == PLUS_EXPR)
02427 {
02428 lit0 = TREE_OPERAND (con0, 1);
02429 con0 = TREE_OPERAND (con0, 0);
02430 }
02431 else
02432 lit0 = integer_zero_node;
02433
02434 if (TREE_CODE (con1) == PLUS_EXPR)
02435 {
02436 lit1 = TREE_OPERAND (con1, 1);
02437 con1 = TREE_OPERAND (con1, 0);
02438 }
02439 else
02440 lit1 = integer_zero_node;
02441
02442 if (operand_equal_p (con0, con1, 0))
02443 {
02444 op0 = lit0;
02445 op1 = lit1;
02446 }
02447
02448
02449
02450
02451
02452
02453
02454 op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
02455 convert (restype, op1), 0);
02456
02457 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
02458 error ("arithmetic on pointer to an incomplete type");
02459
02460
02461 op1 = c_size_in_bytes (target_type);
02462
02463
02464 return fold (build2 (EXACT_DIV_EXPR, restype, op0, convert (restype, op1)));
02465 }
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476 tree
02477 build_unary_op (enum tree_code code, tree xarg, int flag)
02478 {
02479
02480 tree arg = xarg;
02481 tree argtype = 0;
02482 enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
02483 tree val;
02484 int noconvert = flag;
02485
02486 if (typecode == ERROR_MARK)
02487 return error_mark_node;
02488 if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
02489 typecode = INTEGER_TYPE;
02490
02491 switch (code)
02492 {
02493 case CONVERT_EXPR:
02494
02495
02496
02497 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
02498 || typecode == COMPLEX_TYPE
02499 || typecode == VECTOR_TYPE))
02500 {
02501 error ("wrong type argument to unary plus");
02502 return error_mark_node;
02503 }
02504 else if (!noconvert)
02505 arg = default_conversion (arg);
02506 arg = non_lvalue (arg);
02507 break;
02508
02509 case NEGATE_EXPR:
02510 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
02511 || typecode == COMPLEX_TYPE
02512 || typecode == VECTOR_TYPE))
02513 {
02514 error ("wrong type argument to unary minus");
02515 return error_mark_node;
02516 }
02517 else if (!noconvert)
02518 arg = default_conversion (arg);
02519 break;
02520
02521 case BIT_NOT_EXPR:
02522 if (typecode == INTEGER_TYPE || typecode == VECTOR_TYPE)
02523 {
02524 if (!noconvert)
02525 arg = default_conversion (arg);
02526 }
02527 else if (typecode == COMPLEX_TYPE)
02528 {
02529 code = CONJ_EXPR;
02530 if (pedantic)
02531 pedwarn ("ISO C does not support %<~%> for complex conjugation");
02532 if (!noconvert)
02533 arg = default_conversion (arg);
02534 }
02535 else
02536 {
02537 error ("wrong type argument to bit-complement");
02538 return error_mark_node;
02539 }
02540 break;
02541
02542 case ABS_EXPR:
02543 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
02544 {
02545 error ("wrong type argument to abs");
02546 return error_mark_node;
02547 }
02548 else if (!noconvert)
02549 arg = default_conversion (arg);
02550 break;
02551
02552 case CONJ_EXPR:
02553
02554 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
02555 || typecode == COMPLEX_TYPE))
02556 {
02557 error ("wrong type argument to conjugation");
02558 return error_mark_node;
02559 }
02560 else if (!noconvert)
02561 arg = default_conversion (arg);
02562 break;
02563
02564 case TRUTH_NOT_EXPR:
02565 if (typecode != INTEGER_TYPE
02566 && typecode != REAL_TYPE && typecode != POINTER_TYPE
02567 && typecode != COMPLEX_TYPE
02568
02569 && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
02570 {
02571 error ("wrong type argument to unary exclamation mark");
02572 return error_mark_node;
02573 }
02574 arg = lang_hooks.truthvalue_conversion (arg);
02575 return invert_truthvalue (arg);
02576
02577 case NOP_EXPR:
02578 break;
02579
02580 case REALPART_EXPR:
02581 if (TREE_CODE (arg) == COMPLEX_CST)
02582 return TREE_REALPART (arg);
02583 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
02584 return fold (build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
02585 else
02586 return arg;
02587
02588 case IMAGPART_EXPR:
02589 if (TREE_CODE (arg) == COMPLEX_CST)
02590 return TREE_IMAGPART (arg);
02591 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
02592 return fold (build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
02593 else
02594 return convert (TREE_TYPE (arg), integer_zero_node);
02595
02596 case PREINCREMENT_EXPR:
02597 case POSTINCREMENT_EXPR:
02598 case PREDECREMENT_EXPR:
02599 case POSTDECREMENT_EXPR:
02600
02601
02602
02603 if (typecode == COMPLEX_TYPE)
02604 {
02605 tree real, imag;
02606
02607 if (pedantic)
02608 pedwarn ("ISO C does not support %<++%> and %<--%>"
02609 " on complex types");
02610
02611 arg = stabilize_reference (arg);
02612 real = build_unary_op (REALPART_EXPR, arg, 1);
02613 imag = build_unary_op (IMAGPART_EXPR, arg, 1);
02614 return build2 (COMPLEX_EXPR, TREE_TYPE (arg),
02615 build_unary_op (code, real, 1), imag);
02616 }
02617
02618
02619
02620 if (typecode != POINTER_TYPE
02621 && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
02622 {
02623 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
02624 error ("wrong type argument to increment");
02625 else
02626 error ("wrong type argument to decrement");
02627
02628 return error_mark_node;
02629 }
02630
02631 {
02632 tree inc;
02633 tree result_type = TREE_TYPE (arg);
02634
02635 arg = get_unwidened (arg, 0);
02636 argtype = TREE_TYPE (arg);
02637
02638
02639
02640 if (typecode == POINTER_TYPE)
02641 {
02642
02643
02644 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (result_type)))
02645 {
02646 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
02647 error ("increment of pointer to unknown structure");
02648 else
02649 error ("decrement of pointer to unknown structure");
02650 }
02651 else if ((pedantic || warn_pointer_arith)
02652 && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
02653 || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
02654 {
02655 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
02656 pedwarn ("wrong type argument to increment");
02657 else
02658 pedwarn ("wrong type argument to decrement");
02659 }
02660
02661 inc = c_size_in_bytes (TREE_TYPE (result_type));
02662 }
02663 else
02664 inc = integer_one_node;
02665
02666 inc = convert (argtype, inc);
02667
02668
02669 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
02670 || code == POSTINCREMENT_EXPR)
02671 ? lv_increment
02672 : lv_decrement)))
02673 return error_mark_node;
02674
02675
02676 if (TREE_READONLY (arg))
02677 readonly_error (arg,
02678 ((code == PREINCREMENT_EXPR
02679 || code == POSTINCREMENT_EXPR)
02680 ? lv_increment : lv_decrement));
02681
02682 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
02683 val = boolean_increment (code, arg);
02684 else
02685 val = build2 (code, TREE_TYPE (arg), arg, inc);
02686 TREE_SIDE_EFFECTS (val) = 1;
02687 val = convert (result_type, val);
02688 if (TREE_CODE (val) != code)
02689 TREE_NO_WARNING (val) = 1;
02690 return val;
02691 }
02692
02693 case ADDR_EXPR:
02694
02695
02696
02697 if (TREE_CODE (arg) == INDIRECT_REF)
02698 {
02699
02700 if (lvalue_p (TREE_OPERAND (arg, 0)))
02701 return non_lvalue (TREE_OPERAND (arg, 0));
02702 return TREE_OPERAND (arg, 0);
02703 }
02704
02705
02706 if (TREE_CODE (arg) == ARRAY_REF)
02707 {
02708 if (!c_mark_addressable (TREE_OPERAND (arg, 0)))
02709 return error_mark_node;
02710 return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
02711 TREE_OPERAND (arg, 1), 1);
02712 }
02713
02714
02715
02716 else if (typecode != FUNCTION_TYPE && !flag
02717 && !lvalue_or_else (arg, lv_addressof))
02718 return error_mark_node;
02719
02720
02721 argtype = TREE_TYPE (arg);
02722
02723
02724
02725
02726
02727 if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
02728 && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg)))
02729 argtype = c_build_type_variant (argtype,
02730 TREE_READONLY (arg),
02731 TREE_THIS_VOLATILE (arg));
02732
02733 if (!c_mark_addressable (arg))
02734 return error_mark_node;
02735
02736 gcc_assert (TREE_CODE (arg) != COMPONENT_REF
02737 || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
02738
02739 argtype = build_pointer_type (argtype);
02740
02741
02742
02743 val = get_base_address (arg);
02744 if (val && TREE_CODE (val) == INDIRECT_REF
02745 && integer_zerop (TREE_OPERAND (val, 0)))
02746 return fold_convert (argtype, fold_offsetof (arg));
02747
02748 val = build1 (ADDR_EXPR, argtype, arg);
02749
02750 return val;
02751
02752 default:
02753 break;
02754 }
02755
02756 if (argtype == 0)
02757 argtype = TREE_TYPE (arg);
02758 val = build1 (code, argtype, arg);
02759 return require_constant_value ? fold_initializer (val) : fold (val);
02760 }
02761
02762
02763
02764
02765
02766 int
02767 lvalue_p (tree ref)
02768 {
02769 enum tree_code code = TREE_CODE (ref);
02770
02771 switch (code)
02772 {
02773 case REALPART_EXPR:
02774 case IMAGPART_EXPR:
02775 case COMPONENT_REF:
02776 return lvalue_p (TREE_OPERAND (ref, 0));
02777
02778 case COMPOUND_LITERAL_EXPR:
02779 case STRING_CST:
02780 return 1;
02781
02782 case INDIRECT_REF:
02783 case ARRAY_REF:
02784 case VAR_DECL:
02785 case PARM_DECL:
02786 case RESULT_DECL:
02787 case ERROR_MARK:
02788 return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
02789 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
02790
02791 case BIND_EXPR:
02792 return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
02793
02794 default:
02795 return 0;
02796 }
02797 }
02798
02799
02800
02801 static void
02802 readonly_error (tree arg, enum lvalue_use use)
02803 {
02804 gcc_assert (use == lv_assign || use == lv_increment || use == lv_decrement);
02805
02806
02807
02808 #define READONLY_MSG(A, I, D) (use == lv_assign \
02809 ? (A) \
02810 : (use == lv_increment ? (I) : (D)))
02811 if (TREE_CODE (arg) == COMPONENT_REF)
02812 {
02813 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
02814 readonly_error (TREE_OPERAND (arg, 0), use);
02815 else
02816 error (READONLY_MSG (G_("assignment of read-only member %qs"),
02817 G_("increment of read-only member %qs"),
02818 G_("decrement of read-only member %qs")),
02819 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
02820 }
02821 else if (TREE_CODE (arg) == VAR_DECL)
02822 error (READONLY_MSG (G_("assignment of read-only variable %qs"),
02823 G_("increment of read-only variable %qs"),
02824 G_("decrement of read-only variable %qs")),
02825 IDENTIFIER_POINTER (DECL_NAME (arg)));
02826 else
02827 error (READONLY_MSG (G_("assignment of read-only location"),
02828 G_("increment of read-only location"),
02829 G_("decrement of read-only location")));
02830 }
02831
02832
02833
02834
02835
02836 bool
02837 c_mark_addressable (tree exp)
02838 {
02839 tree x = exp;
02840
02841 while (1)
02842 switch (TREE_CODE (x))
02843 {
02844 case COMPONENT_REF:
02845 if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
02846 {
02847 error
02848 ("cannot take address of bit-field %qD", TREE_OPERAND (x, 1));
02849 return false;
02850 }
02851
02852
02853
02854 case ADDR_EXPR:
02855 case ARRAY_REF:
02856 case REALPART_EXPR:
02857 case IMAGPART_EXPR:
02858 x = TREE_OPERAND (x, 0);
02859 break;
02860
02861 case COMPOUND_LITERAL_EXPR:
02862 case CONSTRUCTOR:
02863 TREE_ADDRESSABLE (x) = 1;
02864 return true;
02865
02866 case VAR_DECL:
02867 case CONST_DECL:
02868 case PARM_DECL:
02869 case RESULT_DECL:
02870 if (C_DECL_REGISTER (x)
02871 && DECL_NONLOCAL (x))
02872 {
02873 if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
02874 {
02875 error
02876 ("global register variable %qD used in nested function", x);
02877 return false;
02878 }
02879 pedwarn ("register variable %qD used in nested function", x);
02880 }
02881 else if (C_DECL_REGISTER (x))
02882 {
02883 if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
02884 error ("address of global register variable %qD requested", x);
02885 else
02886 error ("address of register variable %qD requested", x);
02887 return false;
02888 }
02889
02890
02891 case FUNCTION_DECL:
02892 TREE_ADDRESSABLE (x) = 1;
02893
02894 default:
02895 return true;
02896 }
02897 }
02898
02899
02900
02901 tree
02902 build_conditional_expr (tree ifexp, tree op1, tree op2)
02903 {
02904 tree type1;
02905 tree type2;
02906 enum tree_code code1;
02907 enum tree_code code2;
02908 tree result_type = NULL;
02909 tree orig_op1 = op1, orig_op2 = op2;
02910
02911 ifexp = lang_hooks.truthvalue_conversion (default_conversion (ifexp));
02912
02913
02914
02915 if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
02916 op1 = default_conversion (op1);
02917 if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
02918 op2 = default_conversion (op2);
02919
02920 if (TREE_CODE (ifexp) == ERROR_MARK
02921 || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
02922 || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
02923 return error_mark_node;
02924
02925 type1 = TREE_TYPE (op1);
02926 code1 = TREE_CODE (type1);
02927 type2 = TREE_TYPE (op2);
02928 code2 = TREE_CODE (type2);
02929
02930
02931
02932 if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
02933 {
02934 error ("non-lvalue array in conditional expression");
02935 return error_mark_node;
02936 }
02937
02938
02939
02940 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
02941 {
02942 if (type1 == type2)
02943 result_type = type1;
02944 else
02945 result_type = TYPE_MAIN_VARIANT (type1);
02946 }
02947 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
02948 || code1 == COMPLEX_TYPE)
02949 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
02950 || code2 == COMPLEX_TYPE))
02951 {
02952 result_type = c_common_type (type1, type2);
02953
02954
02955
02956
02957
02958
02959 if (warn_sign_compare && !skip_evaluation)
02960 {
02961 int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
02962 int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
02963
02964 if (unsigned_op1 ^ unsigned_op2)
02965 {
02966
02967
02968
02969 if (!TYPE_UNSIGNED (result_type))
02970 ;
02971
02972
02973
02974 else if ((unsigned_op2 && tree_expr_nonnegative_p (op1))
02975 || (unsigned_op1 && tree_expr_nonnegative_p (op2)))
02976 ;
02977 else
02978 warning ("signed and unsigned type in conditional expression");
02979 }
02980 }
02981 }
02982 else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
02983 {
02984 if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
02985 pedwarn ("ISO C forbids conditional expr with only one void side");
02986 result_type = void_type_node;
02987 }
02988 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
02989 {
02990 if (comp_target_types (type1, type2, 1))
02991 result_type = common_pointer_type (type1, type2);
02992 else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
02993 && TREE_CODE (orig_op1) != NOP_EXPR)
02994 result_type = qualify_type (type2, type1);
02995 else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
02996 && TREE_CODE (orig_op2) != NOP_EXPR)
02997 result_type = qualify_type (type1, type2);
02998 else if (VOID_TYPE_P (TREE_TYPE (type1)))
02999 {
03000 if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
03001 pedwarn ("ISO C forbids conditional expr between "
03002 "%<void *%> and function pointer");
03003 result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
03004 TREE_TYPE (type2)));
03005 }
03006 else if (VOID_TYPE_P (TREE_TYPE (type2)))
03007 {
03008 if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
03009 pedwarn ("ISO C forbids conditional expr between "
03010 "%<void *%> and function pointer");
03011 result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
03012 TREE_TYPE (type1)));
03013 }
03014 else
03015 {
03016 pedwarn ("pointer type mismatch in conditional expression");
03017 result_type = build_pointer_type (void_type_node);
03018 }
03019 }
03020 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
03021 {
03022 if (!integer_zerop (op2))
03023 pedwarn ("pointer/integer type mismatch in conditional expression");
03024 else
03025 {
03026 op2 = null_pointer_node;
03027 }
03028 result_type = type1;
03029 }
03030 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
03031 {
03032 if (!integer_zerop (op1))
03033 pedwarn ("pointer/integer type mismatch in conditional expression");
03034 else
03035 {
03036 op1 = null_pointer_node;
03037 }
03038 result_type = type2;
03039 }
03040
03041 if (!result_type)
03042 {
03043 if (flag_cond_mismatch)
03044 result_type = void_type_node;
03045 else
03046 {
03047 error ("type mismatch in conditional expression");
03048 return error_mark_node;
03049 }
03050 }
03051
03052
03053 result_type
03054 = build_type_variant (result_type,
03055 TREE_READONLY (op1) || TREE_READONLY (op2),
03056 TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
03057
03058 if (result_type != TREE_TYPE (op1))
03059 op1 = convert_and_check (result_type, op1);
03060 if (result_type != TREE_TYPE (op2))
03061 op2 = convert_and_check (result_type, op2);
03062
03063 if (TREE_CODE (ifexp) == INTEGER_CST)
03064 return non_lvalue (integer_zerop (ifexp) ? op2 : op1);
03065
03066 return fold (build3 (COND_EXPR, result_type, ifexp, op1, op2));
03067 }
03068
03069
03070
03071
03072 tree
03073 build_compound_expr (tree expr1, tree expr2)
03074 {
03075
03076 expr2 = default_function_array_conversion (expr2);
03077
03078 if (!TREE_SIDE_EFFECTS (expr1))
03079 {
03080
03081
03082
03083 if (warn_unused_value)
03084 {
03085 if (VOID_TYPE_P (TREE_TYPE (expr1))
03086 && TREE_CODE (expr1) == CONVERT_EXPR)
03087 ;
03088 else if (VOID_TYPE_P (TREE_TYPE (expr1))
03089 && TREE_CODE (expr1) == COMPOUND_EXPR
03090 && TREE_CODE (TREE_OPERAND (expr1, 1)) == CONVERT_EXPR)
03091 ;
03092 else
03093 warning ("left-hand operand of comma expression has no effect");
03094 }
03095 }
03096
03097
03098
03099
03100
03101 else if (warn_unused_value)
03102 warn_if_unused_value (expr1, input_location);
03103
03104 return build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
03105 }
03106
03107
03108
03109 tree
03110 build_c_cast (tree type, tree expr)
03111 {
03112 tree value = expr;
03113
03114 if (type == error_mark_node || expr == error_mark_node)
03115 return error_mark_node;
03116
03117
03118
03119
03120 if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
03121 return build1 (NOP_EXPR, type, expr);
03122
03123 type = TYPE_MAIN_VARIANT (type);
03124
03125 if (TREE_CODE (type) == ARRAY_TYPE)
03126 {
03127 error ("cast specifies array type");
03128 return error_mark_node;
03129 }
03130
03131 if (TREE_CODE (type) == FUNCTION_TYPE)
03132 {
03133 error ("cast specifies function type");
03134 return error_mark_node;
03135 }
03136
03137 if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
03138 {
03139 if (pedantic)
03140 {
03141 if (TREE_CODE (type) == RECORD_TYPE
03142 || TREE_CODE (type) == UNION_TYPE)
03143 pedwarn ("ISO C forbids casting nonscalar to the same type");
03144 }
03145 }
03146 else if (TREE_CODE (type) == UNION_TYPE)
03147 {
03148 tree field;
03149 value = default_function_array_conversion (value);
03150
03151 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
03152 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
03153 TYPE_MAIN_VARIANT (TREE_TYPE (value))))
03154 break;
03155
03156 if (field)
03157 {
03158 tree t;
03159
03160 if (pedantic)
03161 pedwarn ("ISO C forbids casts to union type");
03162 t = digest_init (type,
03163 build_constructor (type,
03164 build_tree_list (field, value)),
03165 true, 0);
03166 TREE_CONSTANT (t) = TREE_CONSTANT (value);
03167 TREE_INVARIANT (t) = TREE_INVARIANT (value);
03168 return t;
03169 }
03170 error ("cast to union type from type not present in union");
03171 return error_mark_node;
03172 }
03173 else
03174 {
03175 tree otype, ovalue;
03176
03177
03178
03179 if (type == void_type_node)
03180 return build1 (CONVERT_EXPR, type, value);
03181
03182
03183
03184 value = default_function_array_conversion (value);
03185 otype = TREE_TYPE (value);
03186
03187
03188
03189 if (warn_cast_qual
03190 && TREE_CODE (type) == POINTER_TYPE
03191 && TREE_CODE (otype) == POINTER_TYPE)
03192 {
03193 tree in_type = type;
03194 tree in_otype = otype;
03195 int added = 0;
03196 int discarded = 0;
03197
03198
03199
03200
03201
03202 do
03203 {
03204 in_otype = TREE_TYPE (in_otype);
03205 in_type = TREE_TYPE (in_type);
03206
03207
03208
03209
03210
03211 if (TREE_CODE (in_otype) == FUNCTION_TYPE
03212 && TREE_CODE (in_type) == FUNCTION_TYPE)
03213 added |= (TYPE_QUALS (in_type) & ~TYPE_QUALS (in_otype));
03214 else
03215 discarded |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type));
03216 }
03217 while (TREE_CODE (in_type) == POINTER_TYPE
03218 && TREE_CODE (in_otype) == POINTER_TYPE);
03219
03220 if (added)
03221 warning ("cast adds new qualifiers to function type");
03222
03223 if (discarded)
03224
03225
03226 warning ("cast discards qualifiers from pointer target type");
03227 }
03228
03229
03230 if (STRICT_ALIGNMENT && warn_cast_align
03231 && TREE_CODE (type) == POINTER_TYPE
03232 && TREE_CODE (otype) == POINTER_TYPE
03233 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
03234 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
03235
03236
03237 && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
03238 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
03239 && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
03240 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
03241 warning ("cast increases required alignment of target type");
03242
03243 if (TREE_CODE (type) == INTEGER_TYPE
03244 && TREE_CODE (otype) == POINTER_TYPE
03245 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
03246 && !TREE_CONSTANT (value))
03247 warning ("cast from pointer to integer of different size");
03248
03249 if (warn_bad_function_cast
03250 && TREE_CODE (value) == CALL_EXPR
03251 && TREE_CODE (type) != TREE_CODE (otype))
03252 warning ("cast from function call of type %qT to non-matching "
03253 "type %qT", otype, type);
03254
03255 if (TREE_CODE (type) == POINTER_TYPE
03256 && TREE_CODE (otype) == INTEGER_TYPE
03257 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
03258
03259 && !TREE_CONSTANT (value))
03260 warning ("cast to pointer from integer of different size");
03261
03262 if (TREE_CODE (type) == POINTER_TYPE
03263 && TREE_CODE (otype) == POINTER_TYPE
03264 && TREE_CODE (expr) == ADDR_EXPR
03265 && DECL_P (TREE_OPERAND (expr, 0))
03266 && flag_strict_aliasing && warn_strict_aliasing
03267 && !VOID_TYPE_P (TREE_TYPE (type)))
03268 {
03269
03270
03271 if (!COMPLETE_TYPE_P (TREE_TYPE (type)))
03272 warning ("type-punning to incomplete type might break strict-aliasing rules");
03273 else
03274 {
03275 HOST_WIDE_INT set1 = get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0)));
03276 HOST_WIDE_INT set2 = get_alias_set (TREE_TYPE (type));
03277
03278 if (!alias_sets_conflict_p (set1, set2))
03279 warning ("dereferencing type-punned pointer will break strict-aliasing rules");
03280 else if (warn_strict_aliasing > 1
03281 && !alias_sets_might_conflict_p (set1, set2))
03282 warning ("dereferencing type-punned pointer might break strict-aliasing rules");
03283 }
03284 }
03285
03286
03287
03288
03289 if (pedantic
03290 && TREE_CODE (type) == POINTER_TYPE
03291 && TREE_CODE (otype) == POINTER_TYPE
03292 && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
03293 && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
03294 pedwarn ("ISO C forbids conversion of function pointer to object pointer type");
03295
03296 if (pedantic
03297 && TREE_CODE (type) == POINTER_TYPE
03298 && TREE_CODE (otype) == POINTER_TYPE
03299 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
03300 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
03301 && !(integer_zerop (value) && TREE_TYPE (otype) == void_type_node
03302 && TREE_CODE (expr) != NOP_EXPR))
03303 pedwarn ("ISO C forbids conversion of object pointer to function pointer type");
03304
03305 ovalue = value;
03306 value = convert (type, value);
03307
03308
03309 if (TREE_CODE (value) == INTEGER_CST)
03310 {
03311 if (EXPR_P (ovalue))
03312
03313
03314 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
03315 else
03316 TREE_OVERFLOW (value) = 0;
03317
03318 if (CONSTANT_CLASS_P (ovalue))
03319
03320
03321 TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
03322 }
03323 }
03324
03325
03326 if (value == expr)
03327 value = non_lvalue (value);
03328
03329 return value;
03330 }
03331
03332
03333 tree
03334 c_cast_expr (struct c_type_name *type_name, tree expr)
03335 {
03336 tree type;
03337 int saved_wsp = warn_strict_prototypes;
03338
03339
03340
03341 if (TREE_CODE (expr) == INTEGER_CST)
03342 warn_strict_prototypes = 0;
03343 type = groktypename (type_name);
03344 warn_strict_prototypes = saved_wsp;
03345
03346 return build_c_cast (type, expr);
03347 }
03348
03349
03350
03351
03352
03353
03354
03355 tree
03356 build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
03357 {
03358 tree result;
03359 tree newrhs;
03360 tree lhstype = TREE_TYPE (lhs);
03361 tree olhstype = lhstype;
03362
03363
03364 lhs = require_complete_type (lhs);
03365
03366
03367 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
03368 return error_mark_node;
03369
03370
03371
03372
03373 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
03374 rhs = TREE_OPERAND (rhs, 0);
03375
03376 newrhs = rhs;
03377
03378
03379
03380
03381 if (modifycode != NOP_EXPR)
03382 {
03383 lhs = stabilize_reference (lhs);
03384 newrhs = build_binary_op (modifycode, lhs, rhs, 1);
03385 }
03386
03387 if (!lvalue_or_else (lhs, lv_assign))
03388 return error_mark_node;
03389
03390
03391
03392 if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
03393 || ((TREE_CODE (lhstype) == RECORD_TYPE
03394 || TREE_CODE (lhstype) == UNION_TYPE)
03395 && C_TYPE_FIELDS_READONLY (lhstype)))
03396 readonly_error (lhs, lv_assign);
03397
03398
03399
03400
03401
03402
03403 if (TREE_CODE (lhs) == COMPONENT_REF
03404 && (TREE_CODE (lhstype) == INTEGER_TYPE
03405 || TREE_CODE (lhstype) == BOOLEAN_TYPE
03406 || TREE_CODE (lhstype) == REAL_TYPE
03407 || TREE_CODE (lhstype) == ENUMERAL_TYPE))
03408 lhstype = TREE_TYPE (get_unwidened (lhs, 0));
03409
03410
03411
03412
03413 if (lhstype != TREE_TYPE (lhs))
03414 {
03415 lhs = copy_node (lhs);
03416 TREE_TYPE (lhs) = lhstype;
03417 }
03418
03419
03420
03421 newrhs = convert_for_assignment (lhstype, newrhs, ic_assign,
03422 NULL_TREE, NULL_TREE, 0);
03423 if (TREE_CODE (newrhs) == ERROR_MARK)
03424 return error_mark_node;
03425
03426
03427
03428 result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
03429 TREE_SIDE_EFFECTS (result) = 1;
03430
03431
03432
03433
03434
03435
03436 if (olhstype == TREE_TYPE (result))
03437 return result;
03438 return convert_for_assignment (olhstype, result, ic_assign,
03439 NULL_TREE, NULL_TREE, 0);
03440 }
03441
03442
03443
03444
03445
03446
03447
03448
03449
03450
03451
03452
03453 static tree
03454 convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
03455 tree fundecl, tree function, int parmnum)
03456 {
03457 enum tree_code codel = TREE_CODE (type);
03458 tree rhstype;
03459 enum tree_code coder;
03460 tree rname = NULL_TREE;
03461
03462 if (errtype == ic_argpass || errtype == ic_argpass_nonproto)
03463 {
03464 tree selector;
03465
03466
03467 if (TREE_CODE (function) == ADDR_EXPR
03468 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
03469 function = TREE_OPERAND (function, 0);
03470
03471
03472 selector = objc_message_selector ();
03473 rname = function;
03474 if (selector && parmnum > 2)
03475 {
03476 rname = selector;
03477 parmnum -= 2;
03478 }
03479 }
03480
03481
03482
03483
03484 #define WARN_FOR_ASSIGNMENT(AR, AS, IN, RE) \
03485 do { \
03486 switch (errtype) \
03487 { \
03488 case ic_argpass: \
03489 pedwarn (AR, parmnum, rname); \
03490 break; \
03491 case ic_argpass_nonproto: \
03492 warning (AR, parmnum, rname); \
03493 break; \
03494 case ic_assign: \
03495 pedwarn (AS); \
03496 break; \
03497 case ic_init: \
03498 pedwarn (IN); \
03499 break; \
03500 case ic_return: \
03501 pedwarn (RE); \
03502 break; \
03503 default: \
03504 gcc_unreachable (); \
03505 } \
03506 } while (0)
03507
03508
03509
03510
03511 if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
03512 rhs = TREE_OPERAND (rhs, 0);
03513
03514 if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
03515 || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
03516 rhs = default_conversion (rhs);
03517 else if (optimize && TREE_CODE (rhs) == VAR_DECL)
03518 rhs = decl_constant_value_for_broken_optimization (rhs);
03519
03520 rhstype = TREE_TYPE (rhs);
03521 coder = TREE_CODE (rhstype);
03522
03523 if (coder == ERROR_MARK)
03524 return error_mark_node;
03525
03526 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
03527 {
03528 overflow_warning (rhs);
03529
03530
03531
03532 if (c_dialect_objc ())
03533 objc_comptypes (type, rhstype, 0);
03534 return rhs;
03535 }
03536
03537 if (coder == VOID_TYPE)
03538 {
03539
03540
03541
03542
03543
03544 error ("void value not ignored as it ought to be");
03545 return error_mark_node;
03546 }
03547
03548
03549
03550 if (codel == REFERENCE_TYPE
03551 && comptypes (TREE_TYPE (type), TREE_TYPE (rhs)) == 1)
03552 {
03553 if (!lvalue_p (rhs))
03554 {
03555 error ("cannot pass rvalue to reference parameter");
03556 return error_mark_node;
03557 }
03558 if (!c_mark_addressable (rhs))
03559 return error_mark_node;
03560 rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs);
03561
03562
03563
03564
03565
03566
03567 if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type))
03568 rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs);
03569
03570 rhs = build1 (NOP_EXPR, type, rhs);
03571 return rhs;
03572 }
03573
03574 else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
03575 && vector_types_convertible_p (type, TREE_TYPE (rhs)))
03576 return convert (type, rhs);
03577
03578 else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
03579 || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
03580 || codel == BOOLEAN_TYPE)
03581 && (coder == INTEGER_TYPE || coder == REAL_TYPE
03582 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
03583 || coder == BOOLEAN_TYPE))
03584 return convert_and_check (type, rhs);
03585
03586
03587
03588 else if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type)
03589 && (errtype == ic_argpass || errtype == ic_argpass_nonproto))
03590 {
03591 tree memb_types;
03592 tree marginal_memb_type = 0;
03593
03594 for (memb_types = TYPE_FIELDS (type); memb_types;
03595 memb_types = TREE_CHAIN (memb_types))
03596 {
03597 tree memb_type = TREE_TYPE (memb_types);
03598
03599 if (comptypes (TYPE_MAIN_VARIANT (memb_type),
03600 TYPE_MAIN_VARIANT (rhstype)))
03601 break;
03602
03603 if (TREE_CODE (memb_type) != POINTER_TYPE)
03604 continue;
03605
03606 if (coder == POINTER_TYPE)
03607 {
03608 tree ttl = TREE_TYPE (memb_type);
03609 tree ttr = TREE_TYPE (rhstype);
03610
03611
03612
03613
03614
03615 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
03616 || comp_target_types (memb_type, rhstype, 0))
03617 {
03618
03619 if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
03620 || ((TREE_CODE (ttr) == FUNCTION_TYPE
03621 && TREE_CODE (ttl) == FUNCTION_TYPE)
03622 ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
03623 == TYPE_QUALS (ttr))
03624 : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
03625 == TYPE_QUALS (ttl))))
03626 break;
03627
03628
03629 if (!marginal_memb_type)
03630 marginal_memb_type = memb_type;
03631 }
03632 }
03633
03634
03635 if (integer_zerop (rhs)
03636 || (TREE_CODE (rhs) == NOP_EXPR
03637 && integer_zerop (TREE_OPERAND (rhs, 0))))
03638 {
03639 rhs = null_pointer_node;
03640 break;
03641 }
03642 }
03643
03644 if (memb_types || marginal_memb_type)
03645 {
03646 if (!memb_types)
03647 {
03648
03649
03650 tree ttl = TREE_TYPE (marginal_memb_type);
03651 tree ttr = TREE_TYPE (rhstype);
03652
03653
03654
03655 if (TREE_CODE (ttr) == FUNCTION_TYPE
03656 && TREE_CODE (ttl) == FUNCTION_TYPE)
03657 {
03658
03659
03660
03661
03662
03663 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
03664 WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE "
03665 "makes qualified function "
03666 "pointer from unqualified"),
03667 G_("assignment makes qualified "
03668 "function pointer from "
03669 "unqualified"),
03670 G_("initialization makes qualified "
03671 "function pointer from "
03672 "unqualified"),
03673 G_("return makes qualified function "
03674 "pointer from unqualified"));
03675 }
03676 else if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
03677 WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE discards "
03678 "qualifiers from pointer target type"),
03679 G_("assignment discards qualifiers "
03680 "from pointer target type"),
03681 G_("initialization discards qualifiers "
03682 "from pointer target type"),
03683 G_("return discards qualifiers from "
03684 "pointer target type"));
03685 }
03686
03687 if (pedantic && !DECL_IN_SYSTEM_HEADER (fundecl))
03688 pedwarn ("ISO C prohibits argument conversion to union type");
03689
03690 return build1 (NOP_EXPR, type, rhs);
03691 }
03692 }
03693
03694
03695 else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
03696 && (coder == codel))
03697 {
03698 tree ttl = TREE_TYPE (type);
03699 tree ttr = TREE_TYPE (rhstype);
03700 tree mvl = ttl;
03701 tree mvr = ttr;
03702 bool is_opaque_pointer;
03703 int target_cmp = 0;
03704
03705 if (TREE_CODE (mvl) != ARRAY_TYPE)
03706 mvl = TYPE_MAIN_VARIANT (mvl);
03707 if (TREE_CODE (mvr) != ARRAY_TYPE)
03708 mvr = TYPE_MAIN_VARIANT (mvr);
03709
03710 is_opaque_pointer = (targetm.vector_opaque_p (type)
03711 || targetm.vector_opaque_p (rhstype))
03712 && TREE_CODE (ttl) == VECTOR_TYPE
03713 && TREE_CODE (ttr) == VECTOR_TYPE;
03714
03715
03716
03717
03718 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
03719 || (target_cmp = comp_target_types (type, rhstype, 0))
03720 || is_opaque_pointer
03721 || (c_common_unsigned_type (mvl)
03722 == c_common_unsigned_type (mvr)))
03723 {
03724 if (pedantic
03725 && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
03726 ||
03727 (VOID_TYPE_P (ttr)
03728
03729
03730 && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR)
03731 && TREE_CODE (ttl) == FUNCTION_TYPE)))
03732 WARN_FOR_ASSIGNMENT (G_("ISO C forbids passing argument %d of "
03733 "%qE between function pointer "
03734 "and %<void *%>"),
03735 G_("ISO C forbids assignment between "
03736 "function pointer and %<void *%>"),
03737 G_("ISO C forbids initialization between "
03738 "function pointer and %<void *%>"),
03739 G_("ISO C forbids return between function "
03740 "pointer and %<void *%>"));
03741
03742
03743 else if (TREE_CODE (ttr) != FUNCTION_TYPE
03744 && TREE_CODE (ttl) != FUNCTION_TYPE)
03745 {
03746 if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
03747 WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE discards "
03748 "qualifiers from pointer target type"),
03749 G_("assignment discards qualifiers "
03750 "from pointer target type"),
03751 G_("initialization discards qualifiers "
03752 "from pointer target type"),
03753 G_("return discards qualifiers from "
03754 "pointer target type"));
03755
03756
03757 else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
03758 || target_cmp)
03759 ;
03760
03761 else if (warn_pointer_sign)
03762 WARN_FOR_ASSIGNMENT (G_("pointer targets in passing argument "
03763 "%d of %qE differ in signedness"),
03764 G_("pointer targets in assignment "
03765 "differ in signedness"),
03766 G_("pointer targets in initialization "
03767 "differ in signedness"),
03768 G_("pointer targets in return differ "
03769 "in signedness"));
03770 }
03771 else if (TREE_CODE (ttl) == FUNCTION_TYPE
03772 && TREE_CODE (ttr) == FUNCTION_TYPE)
03773 {
03774
03775
03776
03777
03778 if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
03779 WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes "
03780 "qualified function pointer "
03781 "from unqualified"),
03782 G_("assignment makes qualified function "
03783 "pointer from unqualified"),
03784 G_("initialization makes qualified "
03785 "function pointer from unqualified"),
03786 G_("return makes qualified function "
03787 "pointer from unqualified"));
03788 }
03789 }
03790 else
03791 WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE from "
03792 "incompatible pointer type"),
03793 G_("assignment from incompatible pointer type"),
03794 G_("initialization from incompatible "
03795 "pointer type"),
03796 G_("return from incompatible pointer type"));
03797 return convert (type, rhs);
03798 }
03799 else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
03800 {
03801
03802
03803 error ("invalid use of non-lvalue array");
03804 return error_mark_node;
03805 }
03806 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
03807 {
03808
03809
03810
03811 if (!(TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
03812 &&
03813 !(TREE_CODE (rhs) == NOP_EXPR
03814 && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
03815 && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
03816 && integer_zerop (TREE_OPERAND (rhs, 0))))
03817 WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes "
03818 "pointer from integer without a cast"),
03819 G_("assignment makes pointer from integer "
03820 "without a cast"),
03821 G_("initialization makes pointer from "
03822 "integer without a cast"),
03823 G_("return makes pointer from integer "
03824 "without a cast"));
03825
03826 return convert (type, rhs);
03827 }
03828 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
03829 {
03830 WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes integer "
03831 "from pointer without a cast"),
03832 G_("assignment makes integer from pointer "
03833 "without a cast"),
03834 G_("initialization makes integer from pointer "
03835 "without a cast"),
03836 G_("return makes integer from pointer "
03837 "without a cast"));
03838 return convert (type, rhs);
03839 }
03840 else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE)
03841 return convert (type, rhs);
03842
03843 switch (errtype)
03844 {
03845 case ic_argpass:
03846 case ic_argpass_nonproto:
03847
03848
03849 error ("incompatible type for argument %d of %qE", parmnum, rname);
03850 break;
03851 case ic_assign:
03852 error ("incompatible types in assignment");
03853 break;
03854 case ic_init:
03855 error ("incompatible types in initialization");
03856 break;
03857 case ic_return:
03858 error ("incompatible types in return");
03859 break;
03860 default:
03861 gcc_unreachable ();
03862 }
03863
03864 return error_mark_node;
03865 }
03866
03867
03868
03869
03870
03871 tree
03872 c_convert_parm_for_inlining (tree parm, tree value, tree fn, int argnum)
03873 {
03874 tree ret, type;
03875
03876
03877
03878 if (!value || TYPE_ARG_TYPES (TREE_TYPE (fn)))
03879 return value;
03880
03881 type = TREE_TYPE (parm);
03882 ret = convert_for_assignment (type, value,
03883 ic_argpass_nonproto, fn,
03884 fn, argnum);
03885 if (targetm.calls.promote_prototypes (TREE_TYPE (fn))
03886 && INTEGRAL_TYPE_P (type)
03887 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
03888 ret = default_conversion (ret);
03889 return ret;
03890 }
03891
03892
03893
03894
03895
03896
03897
03898 static tree
03899 valid_compound_expr_initializer (tree value, tree endtype)
03900 {
03901 if (TREE_CODE (value) == COMPOUND_EXPR)
03902 {
03903 if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
03904 == error_mark_node)
03905 return error_mark_node;
03906 return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
03907 endtype);
03908 }
03909 else if (!initializer_constant_valid_p (value, endtype))
03910 return error_mark_node;
03911 else
03912 return value;
03913 }
03914
03915
03916
03917
03918
03919
03920 void
03921 store_init_value (tree decl, tree init)
03922 {
03923 tree value, type;
03924
03925
03926
03927 type = TREE_TYPE (decl);
03928 if (TREE_CODE (type) == ERROR_MARK)
03929 return;
03930
03931
03932
03933 value = digest_init (type, init, true, TREE_STATIC (decl));
03934
03935
03936
03937 if (warn_traditional && !in_system_header
03938 && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
03939 warning ("traditional C rejects automatic aggregate initialization");
03940
03941 DECL_INITIAL (decl) = value;
03942
03943
03944 STRIP_TYPE_NOPS (value);
03945 constant_expression_warning (value);
03946
03947
03948 if (TREE_CODE (type) == ARRAY_TYPE
03949 && TYPE_DOMAIN (type) == 0
03950 && value != error_mark_node)
03951 {
03952 tree inside_init = init;
03953
03954 if (TREE_CODE (init) == NON_LVALUE_EXPR)
03955 inside_init = TREE_OPERAND (init, 0);
03956 inside_init = fold (inside_init);
03957
03958 if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
03959 {
03960 tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
03961
03962 if (TYPE_DOMAIN (TREE_TYPE (decl)))
03963 {
03964
03965
03966
03967 TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (decl));
03968 layout_type (type);
03969 layout_decl (decl, 0);
03970 }
03971 }
03972 }
03973 }
03974
03975
03976
03977
03978
03979
03980 struct spelling
03981 {
03982 int kind;
03983 union
03984 {
03985 int i;
03986 const char *s;
03987 } u;
03988 };
03989
03990 #define SPELLING_STRING 1
03991 #define SPELLING_MEMBER 2
03992 #define SPELLING_BOUNDS 3
03993
03994 static struct spelling *spelling;
03995 static struct spelling *spelling_base;
03996 static int spelling_size;
03997
03998
03999
04000
04001 #define SPELLING_DEPTH() (spelling - spelling_base)
04002 #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
04003
04004
04005
04006
04007 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \
04008 { \
04009 int depth = SPELLING_DEPTH (); \
04010 \
04011 if (depth >= spelling_size) \
04012 { \
04013 spelling_size += 10; \
04014 spelling_base = XRESIZEVEC (struct spelling, spelling_base, \
04015 spelling_size); \
04016 RESTORE_SPELLING_DEPTH (depth); \
04017 } \
04018 \
04019 spelling->kind = (KIND); \
04020 spelling->MEMBER = (VALUE); \
04021 spelling++; \
04022 }
04023
04024
04025
04026 static void
04027 push_string (const char *string)
04028 {
04029 PUSH_SPELLING (SPELLING_STRING, string, u.s);
04030 }
04031
04032
04033
04034 static void
04035 push_member_name (tree decl)
04036 {
04037 const char *const string
04038 = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
04039 PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
04040 }
04041
04042
04043
04044 static void
04045 push_array_bounds (int bounds)
04046 {
04047 PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
04048 }
04049
04050
04051
04052 static int
04053 spelling_length (void)
04054 {
04055 int size = 0;
04056 struct spelling *p;
04057
04058 for (p = spelling_base; p < spelling; p++)
04059 {
04060 if (p->kind == SPELLING_BOUNDS)
04061 size += 25;
04062 else
04063 size += strlen (p->u.s) + 1;
04064 }
04065
04066 return size;
04067 }
04068
04069
04070
04071 static char *
04072 print_spelling (char *buffer)
04073 {
04074 char *d = buffer;
04075 struct spelling *p;
04076
04077 for (p = spelling_base; p < spelling; p++)
04078 if (p->kind == SPELLING_BOUNDS)
04079 {
04080 sprintf (d, "[%d]", p->u.i);
04081 d += strlen (d);
04082 }
04083 else
04084 {
04085 const char *s;
04086 if (p->kind == SPELLING_MEMBER)
04087 *d++ = '.';
04088 for (s = p->u.s; (*d = *s++); d++)
04089 ;
04090 }
04091 *d++ = '\0';
04092 return buffer;
04093 }
04094
04095
04096
04097
04098
04099 void
04100 error_init (const char *msgid)
04101 {
04102 char *ofwhat;
04103
04104 error ("%s", _(msgid));
04105 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
04106 if (*ofwhat)
04107 error ("(near initialization for %qs)", ofwhat);
04108 }
04109
04110
04111
04112
04113
04114 void
04115 pedwarn_init (const char *msgid)
04116 {
04117 char *ofwhat;
04118
04119 pedwarn ("%s", _(msgid));
04120 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
04121 if (*ofwhat)
04122 pedwarn ("(near initialization for %qs)", ofwhat);
04123 }
04124
04125
04126
04127
04128
04129 static void
04130 warning_init (const char *msgid)
04131 {
04132 char *ofwhat;
04133
04134 warning ("%s", _(msgid));
04135 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
04136 if (*ofwhat)
04137 warning ("(near initialization for %qs)", ofwhat);
04138 }
04139
04140
04141
04142
04143
04144 void
04145 maybe_warn_string_init (tree type, struct c_expr expr)
04146 {
04147 if (pedantic
04148 && TREE_CODE (type) == ARRAY_TYPE
04149 && TREE_CODE (expr.value) == STRING_CST
04150 && expr.original_code != STRING_CST)
04151 pedwarn_init ("array initialized from parenthesized string constant");
04152 }
04153
04154
04155
04156
04157
04158
04159
04160
04161
04162
04163
04164 static tree
04165 digest_init (tree type, tree init, bool strict_string, int require_constant)
04166 {
04167 enum tree_code code = TREE_CODE (type);
04168 tree inside_init = init;
04169
04170 if (type == error_mark_node
04171 || init == error_mark_node
04172 || TREE_TYPE (init) == error_mark_node)
04173 return error_mark_node;
04174
04175
04176
04177
04178 if (TREE_CODE (init) == NON_LVALUE_EXPR)
04179 inside_init = TREE_OPERAND (init, 0);
04180
04181 inside_init = fold (inside_init);
04182
04183
04184
04185
04186 if (code == ARRAY_TYPE && inside_init
04187 && TREE_CODE (inside_init) == STRING_CST)
04188 {
04189 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
04190
04191
04192
04193 bool char_array = (typ1 == char_type_node
04194 || typ1 == signed_char_type_node
04195 || typ1 == unsigned_char_type_node);
04196 bool wchar_array = !!comptypes (typ1, wchar_type_node);
04197 if (char_array || wchar_array)
04198 {
04199 struct c_expr expr;
04200 bool char_string;
04201 expr.value = inside_init;
04202 expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
04203 maybe_warn_string_init (type, expr);
04204
04205 char_string
04206 = (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
04207 == char_type_node);
04208
04209 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
04210 TYPE_MAIN_VARIANT (type)))
04211 return inside_init;
04212
04213 if (!wchar_array && !char_string)
04214 {
04215 error_init ("char-array initialized from wide string");
04216 return error_mark_node;
04217 }
04218 if (char_string && !char_array)
04219 {
04220 error_init ("wchar_t-array initialized from non-wide string");
04221 return error_mark_node;
04222 }
04223
04224 TREE_TYPE (inside_init) = type;
04225 if (TYPE_DOMAIN (type) != 0
04226 && TYPE_SIZE (type) != 0
04227 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
04228
04229
04230
04231 && 0 > compare_tree_int (TYPE_SIZE_UNIT (type),
04232 TREE_STRING_LENGTH (inside_init)
04233 - ((TYPE_PRECISION (typ1)
04234 != TYPE_PRECISION (char_type_node))
04235 ? (TYPE_PRECISION (wchar_type_node)
04236 / BITS_PER_UNIT)
04237 : 1)))
04238 pedwarn_init ("initializer-string for array of chars is too long");
04239
04240 return inside_init;
04241 }
04242 else if (INTEGRAL_TYPE_P (typ1))
04243 {
04244 error_init ("array of inappropriate type initialized "
04245 "from string constant");
04246 return error_mark_node;
04247 }
04248 }
04249
04250
04251
04252
04253 if (code == VECTOR_TYPE
04254 && TREE_CODE (TREE_TYPE (inside_init)) == VECTOR_TYPE
04255 && vector_types_convertible_p (TREE_TYPE (inside_init), type)
04256 && TREE_CONSTANT (inside_init))
04257 {
04258 if (TREE_CODE (inside_init) == VECTOR_CST
04259 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
04260 TYPE_MAIN_VARIANT (type)))
04261 return inside_init;
04262
04263 if (TREE_CODE (inside_init) == CONSTRUCTOR)
04264 {
04265 tree link;
04266
04267
04268
04269 for (link = CONSTRUCTOR_ELTS (inside_init);
04270 link;
04271 link = TREE_CHAIN (link))
04272 if (! CONSTANT_CLASS_P (TREE_VALUE (link)))
04273 break;
04274
04275 if (link == NULL)
04276 return build_vector (type, CONSTRUCTOR_ELTS (inside_init));
04277 }
04278 }
04279
04280
04281
04282
04283 if (inside_init && TREE_TYPE (inside_init) != 0
04284 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
04285 TYPE_MAIN_VARIANT (type))
04286 || (code == ARRAY_TYPE
04287 && comptypes (TREE_TYPE (inside_init), type))
04288 || (code == VECTOR_TYPE
04289 && comptypes (TREE_TYPE (inside_init), type))
04290 || (code == POINTER_TYPE
04291 && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
04292 && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
04293 TREE_TYPE (type)))
04294 || (code == POINTER_TYPE
04295 && TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE
04296 && comptypes (TREE_TYPE (inside_init),
04297 TREE_TYPE (type)))))
04298 {
04299 if (code == POINTER_TYPE)
04300 {
04301 inside_init = default_function_array_conversion (inside_init);
04302
04303 if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
04304 {
04305 error_init ("invalid use of non-lvalue array");
04306 return error_mark_node;
04307 }
04308 }
04309
04310 if (code == VECTOR_TYPE)
04311
04312
04313 inside_init = convert (type, inside_init);
04314
04315 if (require_constant && !flag_isoc99
04316 && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
04317 {
04318
04319
04320
04321 tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
04322 inside_init = DECL_INITIAL (decl);
04323 }
04324
04325 if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
04326 && TREE_CODE (inside_init) != CONSTRUCTOR)
04327 {
04328 error_init ("array initialized from non-constant array expression");
04329 return error_mark_node;
04330 }
04331
04332 if (optimize && TREE_CODE (inside_init) == VAR_DECL)
04333 inside_init = decl_constant_value_for_broken_optimization (inside_init);
04334
04335
04336
04337
04338 if (require_constant && pedantic
04339 && TREE_CODE (inside_init) == COMPOUND_EXPR)
04340 {
04341 inside_init
04342 = valid_compound_expr_initializer (inside_init,
04343 TREE_TYPE (inside_init));
04344 if (inside_init == error_mark_node)
04345 error_init ("initializer element is not constant");
04346 else
04347 pedwarn_init ("initializer element is not constant");
04348 if (flag_pedantic_errors)
04349 inside_init = error_mark_node;
04350 }
04351 else if (require_constant
04352 && !initializer_constant_valid_p (inside_init,
04353 TREE_TYPE (inside_init)))
04354 {
04355 error_init ("initializer element is not constant");
04356 inside_init = error_mark_node;
04357 }
04358
04359 return inside_init;
04360 }
04361
04362
04363
04364 if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
04365 || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE || code == COMPLEX_TYPE
04366 || code == VECTOR_TYPE)
04367 {
04368
04369
04370
04371 inside_init
04372 = convert_for_assignment (type, init, ic_init,
04373 NULL_TREE, NULL_TREE, 0);
04374
04375
04376 if (inside_init == error_mark_node)
04377 ;
04378 else if (require_constant && !TREE_CONSTANT (inside_init))
04379 {
04380 error_init ("initializer element is not constant");
04381 inside_init = error_mark_node;
04382 }
04383 else if (require_constant
04384 && !initializer_constant_valid_p (inside_init,
04385 TREE_TYPE (inside_init)))
04386 {
04387 error_init ("initializer element is not computable at load time");
04388 inside_init = error_mark_node;
04389 }
04390
04391 return inside_init;
04392 }
04393
04394
04395
04396 if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
04397 {
04398 error_init ("variable-sized object may not be initialized");
04399 return error_mark_node;
04400 }
04401
04402 error_init ("invalid initializer");
04403 return error_mark_node;
04404 }
04405
04406
04407
04408
04409
04410 static tree constructor_type;
04411
04412
04413
04414 static tree constructor_fields;
04415
04416
04417
04418 static tree constructor_index;
04419
04420
04421 static tree constructor_max_index;
04422
04423
04424 static tree constructor_unfilled_fields;
04425
04426
04427
04428 static tree constructor_unfilled_index;
04429
04430
04431
04432 static tree constructor_bit_index;
04433
04434
04435
04436
04437 static tree constructor_elements;
04438
04439
04440
04441 static int constructor_incremental;
04442
04443
04444 static int constructor_constant;
04445
04446
04447 static int constructor_simple;
04448
04449
04450 static int constructor_erroneous;
04451
04452
04453
04454
04455 struct init_node
04456 {
04457 struct init_node *left, *right;
04458 struct init_node *parent;
04459 int balance;
04460 tree purpose;
04461 tree value;
04462 };
04463
04464
04465
04466
04467
04468
04469 static struct init_node *constructor_pending_elts;
04470
04471
04472 static int constructor_depth;
04473
04474
04475
04476
04477 static tree constructor_decl;
04478
04479
04480 static int constructor_top_level;
04481
04482
04483 static int constructor_designated;
04484
04485
04486 static int designator_depth;
04487
04488
04489 static int designator_errorneous;
04490
04491
04492
04493
04494
04495
04496 struct constructor_range_stack;
04497
04498 struct constructor_stack
04499 {
04500 struct constructor_stack *next;
04501 tree type;
04502 tree fields;
04503 tree index;
04504 tree max_index;
04505 tree unfilled_index;
04506 tree unfilled_fields;
04507 tree bit_index;
04508 tree elements;
04509 struct init_node *pending_elts;
04510 int offset;
04511 int depth;
04512
04513
04514 struct c_expr replacement_value;
04515 struct constructor_range_stack *range_stack;
04516 char constant;
04517 char simple;
04518 char implicit;
04519 char erroneous;
04520 char outer;
04521 char incremental;
04522 char designated;
04523 };
04524
04525 struct constructor_stack *constructor_stack;
04526
04527
04528
04529
04530 struct constructor_range_stack
04531 {
04532 struct constructor_range_stack *next, *prev;
04533 struct constructor_stack *stack;
04534 tree range_start;
04535 tree index;
04536 tree range_end;
04537 tree fields;
04538 };
04539
04540 struct constructor_range_stack *constructor_range_stack;
04541
04542
04543
04544
04545
04546 struct initializer_stack
04547 {
04548 struct initializer_stack *next;
04549 tree decl;
04550 struct constructor_stack *constructor_stack;
04551 struct constructor_range_stack *constructor_range_stack;
04552 tree elements;
04553 struct spelling *spelling;
04554 struct spelling *spelling_base;
04555 int spelling_size;
04556 char top_level;
04557 char require_constant_value;
04558 char require_constant_elements;
04559 };
04560
04561 struct initializer_stack *initializer_stack;
04562
04563
04564
04565 void
04566 start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED, int top_level)
04567 {
04568 const char *locus;
04569 struct initializer_stack *p = xmalloc (sizeof (struct initializer_stack));
04570
04571 p->decl = constructor_decl;
04572 p->require_constant_value = require_constant_value;
04573 p->require_constant_elements = require_constant_elements;
04574 p->constructor_stack = constructor_stack;
04575 p->constructor_range_stack = constructor_range_stack;
04576 p->elements = constructor_elements;
04577 p->spelling = spelling;
04578 p->spelling_base = spelling_base;
04579 p->spelling_size = spelling_size;
04580 p->top_level = constructor_top_level;
04581 p->next = initializer_stack;
04582 initializer_stack = p;
04583
04584 constructor_decl = decl;
04585 constructor_designated = 0;
04586 constructor_top_level = top_level;
04587
04588 if (decl != 0 && decl != error_mark_node)
04589 {
04590 require_constant_value = TREE_STATIC (decl);
04591 require_constant_elements
04592 = ((TREE_STATIC (decl) || (pedantic && !flag_isoc99))
04593
04594
04595 && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
04596 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
04597 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
04598 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
04599 locus = IDENTIFIER_POINTER (DECL_NAME (decl));
04600 }
04601 else
04602 {
04603 require_constant_value = 0;
04604 require_constant_elements = 0;
04605 locus = "(anonymous)";
04606 }
04607
04608 constructor_stack = 0;
04609 constructor_range_stack = 0;
04610
04611 missing_braces_mentioned = 0;
04612
04613 spelling_base = 0;
04614 spelling_size = 0;
04615 RESTORE_SPELLING_DEPTH (0);
04616
04617 if (locus)
04618 push_string (locus);
04619 }
04620
04621 void
04622 finish_init (void)
04623 {
04624 struct initializer_stack *p = initializer_stack;
04625
04626
04627 while (constructor_stack)
04628 {
04629 struct constructor_stack *q = constructor_stack;
04630 constructor_stack = q->next;
04631 free (q);
04632 }
04633
04634 gcc_assert (!constructor_range_stack);
04635
04636
04637 free (spelling_base);
04638
04639 constructor_decl = p->decl;
04640 require_constant_value = p->require_constant_value;
04641 require_constant_elements = p->require_constant_elements;
04642 constructor_stack = p->constructor_stack;
04643 constructor_range_stack = p->constructor_range_stack;
04644 constructor_elements = p->elements;
04645 spelling = p->spelling;
04646 spelling_base = p->spelling_base;
04647 spelling_size = p->spelling_size;
04648 constructor_top_level = p->top_level;
04649 initializer_stack = p->next;
04650 free (p);
04651 }
04652
04653
04654
04655
04656
04657
04658
04659
04660 void
04661 really_start_incremental_init (tree type)
04662 {
04663 struct constructor_stack *p = XNEW (struct constructor_stack);
04664
04665 if (type == 0)
04666 type = TREE_TYPE (constructor_decl);
04667
04668 if (targetm.vector_opaque_p (type))
04669 error ("opaque vector types cannot be initialized");
04670
04671 p->type = constructor_type;
04672 p->fields = constructor_fields;
04673 p->index = constructor_index;
04674 p->max_index = constructor_max_index;
04675 p->unfilled_index = constructor_unfilled_index;
04676 p->unfilled_fields = constructor_unfilled_fields;
04677 p->bit_index = constructor_bit_index;
04678 p->elements = constructor_elements;
04679 p->constant = constructor_constant;
04680 p->simple = constructor_simple;
04681 p->erroneous = constructor_erroneous;
04682 p->pending_elts = constructor_pending_elts;
04683 p->depth = constructor_depth;
04684 p->replacement_value.value = 0;
04685 p->replacement_value.original_code = ERROR_MARK;
04686 p->implicit = 0;
04687 p->range_stack = 0;
04688 p->outer = 0;
04689 p->incremental = constructor_incremental;
04690 p->designated = constructor_designated;
04691 p->next = 0;
04692 constructor_stack = p;
04693
04694 constructor_constant = 1;
04695 constructor_simple = 1;
04696 constructor_depth = SPELLING_DEPTH ();
04697 constructor_elements = 0;
04698 constructor_pending_elts = 0;
04699 constructor_type = type;
04700 constructor_incremental = 1;
04701 constructor_designated = 0;
04702 designator_depth = 0;
04703 designator_errorneous = 0;
04704
04705 if (TREE_CODE (constructor_type) == RECORD_TYPE
04706 || TREE_CODE (constructor_type) == UNION_TYPE)
04707 {
04708 constructor_fields = TYPE_FIELDS (constructor_type);
04709
04710 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
04711 && DECL_NAME (constructor_fields) == 0)
04712 constructor_fields = TREE_CHAIN (constructor_fields);
04713
04714 constructor_unfilled_fields = constructor_fields;
04715 constructor_bit_index = bitsize_zero_node;
04716 }
04717 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
04718 {
04719 if (TYPE_DOMAIN (constructor_type))
04720 {
04721 constructor_max_index
04722 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
04723
04724
04725 if (constructor_max_index == NULL_TREE
04726 && TYPE_SIZE (constructor_type))
04727 constructor_max_index = build_int_cst (NULL_TREE, -1);
04728
04729
04730
04731
04732 if (constructor_max_index
04733 && TREE_CODE (constructor_max_index) != INTEGER_CST)
04734 constructor_max_index = build_int_cst (NULL_TREE, -1);
04735
04736 constructor_index
04737 = convert (bitsizetype,
04738 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
04739 }
04740 else
04741 {
04742 constructor_index = bitsize_zero_node;
04743 constructor_max_index = NULL_TREE;
04744 }
04745
04746 constructor_unfilled_index = constructor_index;
04747 }
04748 else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
04749 {
04750
04751 constructor_max_index =
04752 build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
04753 constructor_index = convert (bitsizetype, bitsize_zero_node);
04754 constructor_unfilled_index = constructor_index;
04755 }
04756 else
04757 {
04758
04759 constructor_fields = constructor_type;
04760 constructor_unfilled_fields = constructor_type;
04761 }
04762 }
04763
04764
04765
04766
04767
04768
04769 void
04770 push_init_level (int implicit)
04771 {
04772 struct constructor_stack *p;
04773 tree value = NULL_TREE;
04774
04775
04776
04777
04778
04779
04780
04781 if (implicit != 1)
04782 {
04783 while (constructor_stack->implicit)
04784 {
04785 if ((TREE_CODE (constructor_type) == RECORD_TYPE
04786 || TREE_CODE (constructor_type) == UNION_TYPE)
04787 && constructor_fields == 0)
04788 process_init_element (pop_init_level (1));
04789 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
04790 && constructor_max_index
04791 && tree_int_cst_lt (constructor_max_index,
04792 constructor_index))
04793 process_init_element (pop_init_level (1));
04794 else
04795 break;
04796 }
04797 }
04798
04799
04800
04801 if (implicit)
04802 {
04803 if ((TREE_CODE (constructor_type) == RECORD_TYPE
04804 || TREE_CODE (constructor_type) == UNION_TYPE)
04805 && constructor_fields)
04806 value = find_init_member (constructor_fields);
04807 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
04808 value = find_init_member (constructor_index);
04809 }
04810
04811 p = XNEW (struct constructor_stack);
04812 p->type = constructor_type;
04813 p->fields = constructor_fields;
04814 p->index = constructor_index;
04815 p->max_index = constructor_max_index;
04816 p->unfilled_index = constructor_unfilled_index;
04817 p->unfilled_fields = constructor_unfilled_fields;
04818 p->bit_index = constructor_bit_index;
04819 p->elements = constructor_elements;
04820 p->constant = constructor_constant;
04821 p->simple = constructor_simple;
04822 p->erroneous = constructor_erroneous;
04823 p->pending_elts = constructor_pending_elts;
04824 p->depth = constructor_depth;
04825 p->replacement_value.value = 0;
04826 p->replacement_value.original_code = ERROR_MARK;
04827 p->implicit = implicit;
04828 p->outer = 0;
04829 p->incremental = constructor_incremental;
04830 p->designated = constructor_designated;
04831 p->next = constructor_stack;
04832 p->range_stack = 0;
04833 constructor_stack = p;
04834
04835 constructor_constant = 1;
04836 constructor_simple = 1;
04837 constructor_depth = SPELLING_DEPTH ();
04838 constructor_elements = 0;
04839 constructor_incremental = 1;
04840 constructor_designated = 0;
04841 constructor_pending_elts = 0;
04842 if (!implicit)
04843 {
04844 p->range_stack = constructor_range_stack;
04845 constructor_range_stack = 0;
04846 designator_depth = 0;
04847 designator_errorneous = 0;
04848 }
04849
04850
04851
04852 if (constructor_type == 0)
04853 ;
04854 else if (TREE_CODE (constructor_type) == RECORD_TYPE
04855 || TREE_CODE (constructor_type) == UNION_TYPE)
04856 {
04857
04858 if (constructor_fields == 0)
04859 constructor_type = 0;
04860 else
04861 {
04862 constructor_type = TREE_TYPE (constructor_fields);
04863 push_member_name (constructor_fields);
04864 constructor_depth++;
04865 }
04866 }
04867 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
04868 {
04869 constructor_type = TREE_TYPE (constructor_type);
04870 push_array_bounds (tree_low_cst (constructor_index, 0));
04871 constructor_depth++;
04872 }
04873
04874 if (constructor_type == 0)
04875 {
04876 error_init ("extra brace group at end of initializer");
04877 constructor_fields = 0;
04878 constructor_unfilled_fields = 0;
04879 return;
04880 }
04881
04882 if (value && TREE_CODE (value) == CONSTRUCTOR)
04883 {
04884 constructor_constant = TREE_CONSTANT (value);
04885 constructor_simple = TREE_STATIC (value);
04886 constructor_elements = CONSTRUCTOR_ELTS (value);
04887 if (constructor_elements
04888 && (TREE_CODE (constructor_type) == RECORD_TYPE
04889 || TREE_CODE (constructor_type) == ARRAY_TYPE))
04890 set_nonincremental_init ();
04891 }
04892
04893 if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
04894 {
04895 missing_braces_mentioned = 1;
04896 warning_init ("missing braces around initializer");
04897 }
04898
04899 if (TREE_CODE (constructor_type) == RECORD_TYPE
04900 || TREE_CODE (constructor_type) == UNION_TYPE)
04901 {
04902 constructor_fields = TYPE_FIELDS (constructor_type);
04903
04904 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
04905 && DECL_NAME (constructor_fields) == 0)
04906 constructor_fields = TREE_CHAIN (constructor_fields);
04907
04908 constructor_unfilled_fields = constructor_fields;
04909 constructor_bit_index = bitsize_zero_node;
04910 }
04911 else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
04912 {
04913
04914 constructor_max_index =
04915 build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
04916 constructor_index = convert (bitsizetype, integer_zero_node);
04917 constructor_unfilled_index = constructor_index;
04918 }
04919 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
04920 {
04921 if (TYPE_DOMAIN (constructor_type))
04922 {
04923 constructor_max_index
04924 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
04925
04926
04927 if (constructor_max_index == NULL_TREE
04928 && TYPE_SIZE (constructor_type))
04929 constructor_max_index = build_int_cst (NULL_TREE, -1);
04930
04931
04932
04933
04934 if (constructor_max_index
04935 && TREE_CODE (constructor_max_index) != INTEGER_CST)
04936 constructor_max_index = build_int_cst (NULL_TREE, -1);
04937
04938 constructor_index
04939 = convert (bitsizetype,
04940 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
04941 }
04942 else
04943 constructor_index = bitsize_zero_node;
04944
04945 constructor_unfilled_index = constructor_index;
04946 if (value && TREE_CODE (value) == STRING_CST)
04947 {
04948
04949
04950
04951 set_nonincremental_init_from_string (value);
04952 }
04953 }
04954 else
04955 {
04956 if (constructor_type != error_mark_node)
04957 warning_init ("braces around scalar initializer");
04958 constructor_fields = constructor_type;
04959 constructor_unfilled_fields = constructor_type;
04960 }
04961 }
04962
04963
04964
04965
04966
04967
04968
04969
04970
04971
04972
04973
04974 struct c_expr
04975 pop_init_level (int implicit)
04976 {
04977 struct constructor_stack *p;
04978 struct c_expr ret;
04979 ret.value = 0;
04980 ret.original_code = ERROR_MARK;
04981
04982 if (implicit == 0)
04983 {
04984
04985
04986 while (constructor_stack->implicit)
04987 process_init_element (pop_init_level (1));
04988
04989 gcc_assert (!constructor_range_stack);
04990 }
04991
04992
04993 constructor_incremental = 1;
04994 output_pending_init_elements (1);
04995
04996 p = constructor_stack;
04997
04998
04999
05000 if (constructor_type && constructor_fields
05001 && TREE_CODE (constructor_type) == ARRAY_TYPE
05002 && TYPE_DOMAIN (constructor_type)
05003 && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
05004 {
05005
05006
05007 if (integer_zerop (constructor_unfilled_index))
05008 constructor_type = NULL_TREE;
05009 else
05010 {
05011 gcc_assert (!TYPE_SIZE (constructor_type));
05012
05013 if (constructor_depth > 2)
05014 error_init ("initialization of flexible array member in a nested context");
05015 else if (pedantic)
05016 pedwarn_init ("initialization of a flexible array member");
05017
05018
05019
05020
05021 if (TREE_CHAIN (constructor_fields) != NULL_TREE)
05022 constructor_type = NULL_TREE;
05023 }
05024 }
05025
05026
05027 if (warn_missing_field_initializers
05028 && constructor_type
05029 && TREE_CODE (constructor_type) == RECORD_TYPE
05030 && constructor_unfilled_fields)
05031 {
05032
05033 while (constructor_unfilled_fields
05034 && (!DECL_SIZE (constructor_unfilled_fields)
05035 || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
05036 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
05037
05038
05039
05040 if (constructor_unfilled_fields && !constructor_designated)
05041 {
05042 push_member_name (constructor_unfilled_fields);
05043 warning_init ("missing initializer");
05044 RESTORE_SPELLING_DEPTH (constructor_depth);
05045 }
05046 }
05047
05048
05049 if (p->replacement_value.value)
05050
05051
05052 ret = p->replacement_value;
05053 else if (constructor_type == 0)
05054 ;
05055 else if (TREE_CODE (constructor_type) != RECORD_TYPE
05056 && TREE_CODE (constructor_type) != UNION_TYPE
05057 && TREE_CODE (constructor_type) != ARRAY_TYPE
05058 && TREE_CODE (constructor_type) != VECTOR_TYPE)
05059 {
05060
05061
05062 if (constructor_elements == 0)
05063 {
05064 if (!constructor_erroneous)
05065 error_init ("empty scalar initializer");
05066 ret.value = error_mark_node;
05067 }
05068 else if (TREE_CHAIN (constructor_elements) != 0)
05069 {
05070 error_init ("extra elements in scalar initializer");
05071 ret.value = TREE_VALUE (constructor_elements);
05072 }
05073 else
05074 ret.value = TREE_VALUE (constructor_elements);
05075 }
05076 else
05077 {
05078 if (constructor_erroneous)
05079 ret.value = error_mark_node;
05080 else
05081 {
05082 ret.value = build_constructor (constructor_type,
05083 nreverse (constructor_elements));
05084 if (constructor_constant)
05085 TREE_CONSTANT (ret.value) = TREE_INVARIANT (ret.value) = 1;
05086 if (constructor_constant && constructor_simple)
05087 TREE_STATIC (ret.value) = 1;
05088 }
05089 }
05090
05091 constructor_type = p->type;
05092 constructor_fields = p->fields;
05093 constructor_index = p->index;
05094 constructor_max_index = p->max_index;
05095 constructor_unfilled_index = p->unfilled_index;
05096 constructor_unfilled_fields = p->unfilled_fields;
05097 constructor_bit_index = p->bit_index;
05098 constructor_elements = p->elements;
05099 constructor_constant = p->constant;
05100 constructor_simple = p->simple;
05101 constructor_erroneous = p->erroneous;
05102 constructor_incremental = p->incremental;
05103 constructor_designated = p->designated;
05104 constructor_pending_elts = p->pending_elts;
05105 constructor_depth = p->depth;
05106 if (!p->implicit)
05107 constructor_range_stack = p->range_stack;
05108 RESTORE_SPELLING_DEPTH (constructor_depth);
05109
05110 constructor_stack = p->next;
05111 free (p);
05112
05113 if (ret.value == 0)
05114 {
05115 if (constructor_stack == 0)
05116 {
05117 ret.value = error_mark_node;
05118 return ret;
05119 }
05120 return ret;
05121 }
05122 return ret;
05123 }
05124
05125
05126
05127
05128 static int
05129 set_designator (int array)
05130 {
05131 tree subtype;
05132 enum tree_code subcode;
05133
05134
05135
05136 if (constructor_type == 0)
05137 return 1;
05138
05139
05140
05141 if (designator_errorneous)
05142 return 1;
05143
05144 if (!designator_depth)
05145 {
05146 gcc_assert (!constructor_range_stack);
05147
05148
05149
05150 while (constructor_stack->implicit)
05151 process_init_element (pop_init_level (1));
05152 constructor_designated = 1;
05153 return 0;
05154 }
05155
05156 switch (TREE_CODE (constructor_type))
05157 {
05158 case RECORD_TYPE:
05159 case UNION_TYPE:
05160 subtype = TREE_TYPE (constructor_fields);
05161 if (subtype != error_mark_node)
05162 subtype = TYPE_MAIN_VARIANT (subtype);
05163 break;
05164 case ARRAY_TYPE:
05165 subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
05166 break;
05167 default:
05168 gcc_unreachable ();
05169 }
05170
05171 subcode = TREE_CODE (subtype);
05172 if (array && subcode != ARRAY_TYPE)
05173 {
05174 error_init ("array index in non-array initializer");
05175 return 1;
05176 }
05177 else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
05178 {
05179 error_init ("field name not in record or union initializer");
05180 return 1;
05181 }
05182
05183 constructor_designated = 1;
05184 push_init_level (2);
05185 return 0;
05186 }
05187
05188
05189
05190
05191
05192 static void
05193 push_range_stack (tree range_end)
05194 {
05195 struct constructor_range_stack *p;
05196
05197 p = GGC_NEW (struct constructor_range_stack);
05198 p->prev = constructor_range_stack;
05199 p->next = 0;
05200 p->fields = constructor_fields;
05201 p->range_start = constructor_index;
05202 p->index = constructor_index;
05203 p->stack = constructor_stack;
05204 p->range_end = range_end;
05205 if (constructor_range_stack)
05206 constructor_range_stack->next = p;
05207 constructor_range_stack = p;
05208 }
05209
05210
05211
05212
05213
05214 void
05215 set_init_index (tree first, tree last)
05216 {
05217 if (set_designator (1))
05218 return;
05219
05220 designator_errorneous = 1;
05221
05222 if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
05223 || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
05224 {
05225 error_init ("array index in initializer not of integer type");
05226 return;
05227 }
05228
05229 while ((TREE_CODE (first) == NOP_EXPR
05230 || TREE_CODE (first) == CONVERT_EXPR
05231 || TREE_CODE (first) == NON_LVALUE_EXPR)
05232 && (TYPE_MODE (TREE_TYPE (first))
05233 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first, 0)))))
05234 first = TREE_OPERAND (first, 0);
05235
05236 if (last)
05237 while ((TREE_CODE (last) == NOP_EXPR
05238 || TREE_CODE (last) == CONVERT_EXPR
05239 || TREE_CODE (last) == NON_LVALUE_EXPR)
05240 && (TYPE_MODE (TREE_TYPE (last))
05241 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
05242 last = TREE_OPERAND (last, 0);
05243
05244 if (TREE_CODE (first) != INTEGER_CST)
05245 error_init ("nonconstant array index in initializer");
05246 else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
05247 error_init ("nonconstant array index in initializer");
05248 else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
05249 error_init ("array index in non-array initializer");
05250 else if (tree_int_cst_sgn (first) == -1)
05251 error_init ("array index in initializer exceeds array bounds");
05252 else if (constructor_max_index
05253 && tree_int_cst_lt (constructor_max_index, first))
05254 error_init ("array index in initializer exceeds array bounds");
05255 else
05256 {
05257 constructor_index = convert (bitsizetype, first);
05258
05259 if (last)
05260 {
05261 if (tree_int_cst_equal (first, last))
05262 last = 0;
05263 else if (tree_int_cst_lt (last, first))
05264 {
05265 error_init ("empty index range in initializer");
05266 last = 0;
05267 }
05268 else
05269 {
05270 last = convert (bitsizetype, last);
05271 if (constructor_max_index != 0
05272 && tree_int_cst_lt (constructor_max_index, last))
05273 {
05274 error_init ("array index range in initializer exceeds array bounds");
05275 last = 0;
05276 }
05277 }
05278 }
05279
05280 designator_depth++;
05281 designator_errorneous = 0;
05282 if (constructor_range_stack || last)
05283 push_range_stack (last);
05284 }
05285 }
05286
05287
05288
05289 void
05290 set_init_label (tree fieldname)
05291 {
05292 tree tail;
05293
05294 if (set_designator (0))
05295 return;
05296
05297 designator_errorneous = 1;
05298
05299 if (TREE_CODE (constructor_type) != RECORD_TYPE
05300 && TREE_CODE (constructor_type) != UNION_TYPE)
05301 {
05302 error_init ("field name not in record or union initializer");
05303 return;
05304 }
05305
05306 for (tail = TYPE_FIELDS (constructor_type); tail;
05307 tail = TREE_CHAIN (tail))
05308 {
05309 if (DECL_NAME (tail) == fieldname)
05310 break;
05311 }
05312
05313 if (tail == 0)
05314 error ("unknown field %qs specified in initializer",
05315 IDENTIFIER_POINTER (fieldname));
05316 else
05317 {
05318 constructor_fields = tail;
05319 designator_depth++;
05320 designator_errorneous = 0;
05321 if (constructor_range_stack)
05322 push_range_stack (NULL_TREE);
05323 }
05324 }
05325
05326
05327
05328
05329
05330 static void
05331 add_pending_init (tree purpose, tree value)
05332 {
05333 struct init_node *p, **q, *r;
05334
05335 q = &constructor_pending_elts;
05336 p = 0;
05337
05338 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05339 {
05340 while (*q != 0)
05341 {
05342 p = *q;
05343 if (tree_int_cst_lt (purpose, p->purpose))
05344 q = &p->left;
05345 else if (tree_int_cst_lt (p->purpose, purpose))
05346 q = &p->right;
05347 else
05348 {
05349 if (TREE_SIDE_EFFECTS (p->value))
05350 warning_init ("initialized field with side-effects overwritten");
05351 p->value = value;
05352 return;
05353 }
05354 }
05355 }
05356 else
05357 {
05358 tree bitpos;
05359
05360 bitpos = bit_position (purpose);
05361 while (*q != NULL)
05362 {
05363 p = *q;
05364 if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
05365 q = &p->left;
05366 else if (p->purpose != purpose)
05367 q = &p->right;
05368 else
05369 {
05370 if (TREE_SIDE_EFFECTS (p->value))
05371 warning_init ("initialized field with side-effects overwritten");
05372 p->value = value;
05373 return;
05374 }
05375 }
05376 }
05377
05378 r = GGC_NEW (struct init_node);
05379 r->purpose = purpose;
05380 r->value = value;
05381
05382 *q = r;
05383 r->parent = p;
05384 r->left = 0;
05385 r->right = 0;
05386 r->balance = 0;
05387
05388 while (p)
05389 {
05390 struct init_node *s;
05391
05392 if (r == p->left)
05393 {
05394 if (p->balance == 0)
05395 p->balance = -1;
05396 else if (p->balance < 0)
05397 {
05398 if (r->balance < 0)
05399 {
05400
05401 p->left = r->right;
05402 if (p->left)
05403 p->left->parent = p;
05404 r->right = p;
05405
05406 p->balance = 0;
05407 r->balance = 0;
05408
05409 s = p->parent;
05410 p->parent = r;
05411 r->parent = s;
05412 if (s)
05413 {
05414 if (s->left == p)
05415 s->left = r;
05416 else
05417 s->right = r;
05418 }
05419 else
05420 constructor_pending_elts = r;
05421 }
05422 else
05423 {
05424
05425 struct init_node *t = r->right;
05426
05427 r->right = t->left;
05428 if (r->right)
05429 r->right->parent = r;
05430 t->left = r;
05431
05432 p->left = t->right;
05433 if (p->left)
05434 p->left->parent = p;
05435 t->right = p;
05436
05437 p->balance = t->balance < 0;
05438 r->balance = -(t->balance > 0);
05439 t->balance = 0;
05440
05441 s = p->parent;
05442 p->parent = t;
05443 r->parent = t;
05444 t->parent = s;
05445 if (s)
05446 {
05447 if (s->left == p)
05448 s->left = t;
05449 else
05450 s->right = t;
05451 }
05452 else
05453 constructor_pending_elts = t;
05454 }
05455 break;
05456 }
05457 else
05458 {
05459
05460 p->balance = 0;
05461 break;
05462 }
05463 }
05464 else
05465 {
05466 if (p->balance == 0)
05467
05468 p->balance++;
05469 else if (p->balance > 0)
05470 {
05471 if (r->balance > 0)
05472 {
05473
05474 p->right = r->left;
05475 if (p->right)
05476 p->right->parent = p;
05477 r->left = p;
05478
05479 p->balance = 0;
05480 r->balance = 0;
05481
05482 s = p->parent;
05483 p->parent = r;
05484 r->parent = s;
05485 if (s)
05486 {
05487 if (s->left == p)
05488 s->left = r;
05489 else
05490 s->right = r;
05491 }
05492 else
05493 constructor_pending_elts = r;
05494 }
05495 else
05496 {
05497
05498 struct init_node *t = r->left;
05499
05500 r->left = t->right;
05501 if (r->left)
05502 r->left->parent = r;
05503 t->right = r;
05504
05505 p->right = t->left;
05506 if (p->right)
05507 p->right->parent = p;
05508 t->left = p;
05509
05510 r->balance = (t->balance < 0);
05511 p->balance = -(t->balance > 0);
05512 t->balance = 0;
05513
05514 s = p->parent;
05515 p->parent = t;
05516 r->parent = t;
05517 t->parent = s;
05518 if (s)
05519 {
05520 if (s->left == p)
05521 s->left = t;
05522 else
05523 s->right = t;
05524 }
05525 else
05526 constructor_pending_elts = t;
05527 }
05528 break;
05529 }
05530 else
05531 {
05532
05533 p->balance = 0;
05534 break;
05535 }
05536 }
05537
05538 r = p;
05539 p = p->parent;
05540 }
05541 }
05542
05543
05544
05545 static void
05546 set_nonincremental_init (void)
05547 {
05548 tree chain;
05549
05550 if (TREE_CODE (constructor_type) != RECORD_TYPE
05551 && TREE_CODE (constructor_type) != ARRAY_TYPE)
05552 return;
05553
05554 for (chain = constructor_elements; chain; chain = TREE_CHAIN (chain))
05555 add_pending_init (TREE_PURPOSE (chain), TREE_VALUE (chain));
05556 constructor_elements = 0;
05557 if (TREE_CODE (constructor_type) == RECORD_TYPE)
05558 {
05559 constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
05560
05561 while (constructor_unfilled_fields != 0
05562 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
05563 && DECL_NAME (constructor_unfilled_fields) == 0)
05564 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
05565
05566 }
05567 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05568 {
05569 if (TYPE_DOMAIN (constructor_type))
05570 constructor_unfilled_index
05571 = convert (bitsizetype,
05572 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
05573 else
05574 constructor_unfilled_index = bitsize_zero_node;
05575 }
05576 constructor_incremental = 0;
05577 }
05578
05579
05580
05581 static void
05582 set_nonincremental_init_from_string (tree str)
05583 {
05584 tree value, purpose, type;
05585 HOST_WIDE_INT val[2];
05586 const char *p, *end;
05587 int byte, wchar_bytes, charwidth, bitpos;
05588
05589 gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
05590
05591 if (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str)))
05592 == TYPE_PRECISION (char_type_node))
05593 wchar_bytes = 1;
05594 else
05595 {
05596 gcc_assert (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str)))
05597 == TYPE_PRECISION (wchar_type_node));
05598 wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
05599 }
05600 charwidth = TYPE_PRECISION (char_type_node);
05601 type = TREE_TYPE (constructor_type);
05602 p = TREE_STRING_POINTER (str);
05603 end = p + TREE_STRING_LENGTH (str);
05604
05605 for (purpose = bitsize_zero_node;
05606 p < end && !tree_int_cst_lt (constructor_max_index, purpose);
05607 purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
05608 {
05609 if (wchar_bytes == 1)
05610 {
05611 val[1] = (unsigned char) *p++;
05612 val[0] = 0;
05613 }
05614 else
05615 {
05616 val[0] = 0;
05617 val[1] = 0;
05618 for (byte = 0; byte < wchar_bytes; byte++)
05619 {
05620 if (BYTES_BIG_ENDIAN)
05621 bitpos = (wchar_bytes - byte - 1) * charwidth;
05622 else
05623 bitpos = byte * charwidth;
05624 val[bitpos < HOST_BITS_PER_WIDE_INT]
05625 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
05626 << (bitpos % HOST_BITS_PER_WIDE_INT);
05627 }
05628 }
05629
05630 if (!TYPE_UNSIGNED (type))
05631 {
05632 bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
05633 if (bitpos < HOST_BITS_PER_WIDE_INT)
05634 {
05635 if (val[1] & (((HOST_WIDE_INT) 1) << (bitpos - 1)))
05636 {
05637 val[1] |= ((HOST_WIDE_INT) -1) << bitpos;
05638 val[0] = -1;
05639 }
05640 }
05641 else if (bitpos == HOST_BITS_PER_WIDE_INT)
05642 {
05643 if (val[1] < 0)
05644 val[0] = -1;
05645 }
05646 else if (val[0] & (((HOST_WIDE_INT) 1)
05647 << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
05648 val[0] |= ((HOST_WIDE_INT) -1)
05649 << (bitpos - HOST_BITS_PER_WIDE_INT);
05650 }
05651
05652 value = build_int_cst_wide (type, val[1], val[0]);
05653 add_pending_init (purpose, value);
05654 }
05655
05656 constructor_incremental = 0;
05657 }
05658
05659
05660
05661
05662 static tree
05663 find_init_member (tree field)
05664 {
05665 struct init_node *p;
05666
05667 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05668 {
05669 if (constructor_incremental
05670 && tree_int_cst_lt (field, constructor_unfilled_index))
05671 set_nonincremental_init ();
05672
05673 p = constructor_pending_elts;
05674 while (p)
05675 {
05676 if (tree_int_cst_lt (field, p->purpose))
05677 p = p->left;
05678 else if (tree_int_cst_lt (p->purpose, field))
05679 p = p->right;
05680 else
05681 return p->value;
05682 }
05683 }
05684 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
05685 {
05686 tree bitpos = bit_position (field);
05687
05688 if (constructor_incremental
05689 && (!constructor_unfilled_fields
05690 || tree_int_cst_lt (bitpos,
05691 bit_position (constructor_unfilled_fields))))
05692 set_nonincremental_init ();
05693
05694 p = constructor_pending_elts;
05695 while (p)
05696 {
05697 if (field == p->purpose)
05698 return p->value;
05699 else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
05700 p = p->left;
05701 else
05702 p = p->right;
05703 }
05704 }
05705 else if (TREE_CODE (constructor_type) == UNION_TYPE)
05706 {
05707 if (constructor_elements
05708 && TREE_PURPOSE (constructor_elements) == field)
05709 return TREE_VALUE (constructor_elements);
05710 }
05711 return 0;
05712 }
05713
05714
05715
05716
05717
05718
05719
05720
05721
05722
05723
05724
05725
05726
05727 static void
05728 output_init_element (tree value, bool strict_string, tree type, tree field,
05729 int pending)
05730 {
05731 if (type == error_mark_node || value == error_mark_node)
05732 {
05733 constructor_erroneous = 1;
05734 return;
05735 }
05736 if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
05737 || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
05738 && !(TREE_CODE (value) == STRING_CST
05739 && TREE_CODE (type) == ARRAY_TYPE
05740 && INTEGRAL_TYPE_P (TREE_TYPE (type)))
05741 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
05742 TYPE_MAIN_VARIANT (type))))
05743 value = default_conversion (value);
05744
05745 if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
05746 && require_constant_value && !flag_isoc99 && pending)
05747 {
05748
05749
05750
05751 tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
05752 value = DECL_INITIAL (decl);
05753 }
05754
05755 if (value == error_mark_node)
05756 constructor_erroneous = 1;
05757 else if (!TREE_CONSTANT (value))
05758 constructor_constant = 0;
05759 else if (!initializer_constant_valid_p (value, TREE_TYPE (value))
05760 || ((TREE_CODE (constructor_type) == RECORD_TYPE
05761 || TREE_CODE (constructor_type) == UNION_TYPE)
05762 && DECL_C_BIT_FIELD (field)
05763 && TREE_CODE (value) != INTEGER_CST))
05764 constructor_simple = 0;
05765
05766 if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
05767 {
05768 if (require_constant_value)
05769 {
05770 error_init ("initializer element is not constant");
05771 value = error_mark_node;
05772 }
05773 else if (require_constant_elements)
05774 pedwarn ("initializer element is not computable at load time");
05775 }
05776
05777
05778
05779 if (field
05780 && (TREE_TYPE (field) == error_mark_node
05781 || (COMPLETE_TYPE_P (TREE_TYPE (field))
05782 && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
05783 && (TREE_CODE (constructor_type) == ARRAY_TYPE
05784 || TREE_CHAIN (field)))))
05785 return;
05786
05787 value = digest_init (type, value, strict_string, require_constant_value);
05788 if (value == error_mark_node)
05789 {
05790 constructor_erroneous = 1;
05791 return;
05792 }
05793
05794
05795
05796 if (TREE_CODE (constructor_type) == ARRAY_TYPE
05797 && (!constructor_incremental
05798 || !tree_int_cst_equal (field, constructor_unfilled_index)))
05799 {
05800 if (constructor_incremental
05801 && tree_int_cst_lt (field, constructor_unfilled_index))
05802 set_nonincremental_init ();
05803
05804 add_pending_init (field, value);
05805 return;
05806 }
05807 else if (TREE_CODE (constructor_type) == RECORD_TYPE
05808 && (!constructor_incremental
05809 || field != constructor_unfilled_fields))
05810 {
05811
05812
05813
05814 if (constructor_incremental)
05815 {
05816 if (!constructor_unfilled_fields)
05817 set_nonincremental_init ();
05818 else
05819 {
05820 tree bitpos, unfillpos;
05821
05822 bitpos = bit_position (field);
05823 unfillpos = bit_position (constructor_unfilled_fields);
05824
05825 if (tree_int_cst_lt (bitpos, unfillpos))
05826 set_nonincremental_init ();
05827 }
05828 }
05829
05830 add_pending_init (field, value);
05831 return;
05832 }
05833 else if (TREE_CODE (constructor_type) == UNION_TYPE
05834 && constructor_elements)
05835 {
05836 if (TREE_SIDE_EFFECTS (TREE_VALUE (constructor_elements)))
05837 warning_init ("initialized field with side-effects overwritten");
05838
05839
05840 constructor_elements = 0;
05841 }
05842
05843
05844
05845
05846 if (field && TREE_CODE (field) == INTEGER_CST)
05847 field = copy_node (field);
05848 constructor_elements
05849 = tree_cons (field, value, constructor_elements);
05850
05851
05852 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05853 constructor_unfilled_index
05854 = size_binop (PLUS_EXPR, constructor_unfilled_index,
05855 bitsize_one_node);
05856 else if (TREE_CODE (constructor_type) == RECORD_TYPE)
05857 {
05858 constructor_unfilled_fields
05859 = TREE_CHAIN (constructor_unfilled_fields);
05860
05861
05862 while (constructor_unfilled_fields != 0
05863 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
05864 && DECL_NAME (constructor_unfilled_fields) == 0)
05865 constructor_unfilled_fields =
05866 TREE_CHAIN (constructor_unfilled_fields);
05867 }
05868 else if (TREE_CODE (constructor_type) == UNION_TYPE)
05869 constructor_unfilled_fields = 0;
05870
05871
05872 if (pending)
05873 output_pending_init_elements (0);
05874 }
05875
05876
05877
05878
05879
05880
05881
05882
05883
05884
05885
05886
05887 static void
05888 output_pending_init_elements (int all)
05889 {
05890 struct init_node *elt = constructor_pending_elts;
05891 tree next;
05892
05893 retry:
05894
05895
05896
05897
05898
05899
05900 next = 0;
05901 while (elt)
05902 {
05903 if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05904 {
05905 if (tree_int_cst_equal (elt->purpose,
05906 constructor_unfilled_index))
05907 output_init_element (elt->value, true,
05908 TREE_TYPE (constructor_type),
05909 constructor_unfilled_index, 0);
05910 else if (tree_int_cst_lt (constructor_unfilled_index,
05911 elt->purpose))
05912 {
05913
05914 if (elt->left)
05915 elt = elt->left;
05916 else
05917 {
05918
05919
05920 next = elt->purpose;
05921 break;
05922 }
05923 }
05924 else
05925 {
05926
05927 if (elt->right)
05928 elt = elt->right;
05929 else
05930 {
05931
05932
05933 while (elt->parent && elt->parent->right == elt)
05934 elt = elt->parent;
05935 elt = elt->parent;
05936 if (elt && tree_int_cst_lt (constructor_unfilled_index,
05937 elt->purpose))
05938 {
05939 next = elt->purpose;
05940 break;
05941 }
05942 }
05943 }
05944 }
05945 else if (TREE_CODE (constructor_type) == RECORD_TYPE
05946 || TREE_CODE (constructor_type) == UNION_TYPE)
05947 {
05948 tree ctor_unfilled_bitpos, elt_bitpos;
05949
05950
05951 if (constructor_unfilled_fields == 0)
05952 break;
05953
05954 ctor_unfilled_bitpos = bit_position (constructor_unfilled_fields);
05955 elt_bitpos = bit_position (elt->purpose);
05956
05957
05958 if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos))
05959 {
05960 constructor_unfilled_fields = elt->purpose;
05961 output_init_element (elt->value, true, TREE_TYPE (elt->purpose),
05962 elt->purpose, 0);
05963 }
05964 else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos))
05965 {
05966
05967 if (elt->left)
05968 elt = elt->left;
05969 else
05970 {
05971
05972
05973 next = elt->purpose;
05974 break;
05975 }
05976 }
05977 else
05978 {
05979
05980 if (elt->right)
05981 elt = elt->right;
05982 else
05983 {
05984
05985
05986 while (elt->parent && elt->parent->right == elt)
05987 elt = elt->parent;
05988 elt = elt->parent;
05989 if (elt
05990 && (tree_int_cst_lt (ctor_unfilled_bitpos,
05991 bit_position (elt->purpose))))
05992 {
05993 next = elt->purpose;
05994 break;
05995 }
05996 }
05997 }
05998 }
05999 }
06000
06001
06002
06003 if (!(all && next != 0))
06004 return;
06005
06006
06007
06008 if (TREE_CODE (constructor_type) == RECORD_TYPE
06009 || TREE_CODE (constructor_type) == UNION_TYPE)
06010 constructor_unfilled_fields = next;
06011 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
06012 constructor_unfilled_index = next;
06013
06014
06015
06016 goto retry;
06017 }
06018
06019
06020
06021
06022
06023
06024
06025
06026
06027 void
06028 process_init_element (struct c_expr value)
06029 {
06030 tree orig_value = value.value;
06031 int string_flag = orig_value != 0 && TREE_CODE (orig_value) == STRING_CST;
06032 bool strict_string = value.original_code == STRING_CST;
06033
06034 designator_depth = 0;
06035 designator_errorneous = 0;
06036
06037
06038
06039 if (string_flag
06040 && constructor_type
06041 && TREE_CODE (constructor_type) == ARRAY_TYPE
06042 && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
06043 && integer_zerop (constructor_unfilled_index))
06044 {
06045 if (constructor_stack->replacement_value.value)
06046 error_init ("excess elements in char array initializer");
06047 constructor_stack->replacement_value = value;
06048 return;
06049 }
06050
06051 if (constructor_stack->replacement_value.value != 0)
06052 {
06053 error_init ("excess elements in struct initializer");
06054 return;
06055 }
06056
06057
06058
06059 if (constructor_type == 0)
06060 return;
06061
06062
06063
06064 while (constructor_stack->implicit)
06065 {
06066 if ((TREE_CODE (constructor_type) == RECORD_TYPE
06067 || TREE_CODE (constructor_type) == UNION_TYPE)
06068 && constructor_fields == 0)
06069 process_init_element (pop_init_level (1));
06070 else if (TREE_CODE (constructor_type) == ARRAY_TYPE
06071 && (constructor_max_index == 0
06072 || tree_int_cst_lt (constructor_max_index,
06073 constructor_index)))
06074 process_init_element (pop_init_level (1));
06075 else
06076 break;
06077 }
06078
06079
06080 if (constructor_range_stack)
06081 {
06082
06083
06084 if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
06085 || !require_constant_value
06086 || flag_isoc99)
06087 value.value = save_expr (value.value);
06088 }
06089
06090 while (1)
06091 {
06092 if (TREE_CODE (constructor_type) == RECORD_TYPE)
06093 {
06094 tree fieldtype;
06095 enum tree_code fieldcode;
06096
06097 if (constructor_fields == 0)
06098 {
06099 pedwarn_init ("excess elements in struct initializer");
06100 break;
06101 }
06102
06103 fieldtype = TREE_TYPE (constructor_fields);
06104 if (fieldtype != error_mark_node)
06105 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
06106 fieldcode = TREE_CODE (fieldtype);
06107
06108
06109 if (fieldcode == ARRAY_TYPE
06110 && !require_constant_value
06111 && TYPE_SIZE (fieldtype) == NULL_TREE
06112 && TREE_CHAIN (constructor_fields) == NULL_TREE)
06113 {
06114 error_init ("non-static initialization of a flexible array member");
06115 break;
06116 }
06117
06118
06119 if (value.value != 0
06120 && fieldcode == ARRAY_TYPE
06121 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
06122 && string_flag)
06123 value.value = orig_value;
06124
06125
06126 else if (value.value != 0
06127 && value.value != error_mark_node
06128 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
06129 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
06130 || fieldcode == UNION_TYPE))
06131 {
06132 push_init_level (1);
06133 continue;
06134 }
06135
06136 if (value.value)
06137 {
06138 push_member_name (constructor_fields);
06139 output_init_element (value.value, strict_string,
06140 fieldtype, constructor_fields, 1);
06141 RESTORE_SPELLING_DEPTH (constructor_depth);
06142 }
06143 else
06144
06145
06146 {
06147
06148 if (DECL_SIZE (constructor_fields))
06149 constructor_bit_index
06150 = size_binop (PLUS_EXPR,
06151 bit_position (constructor_fields),
06152 DECL_SIZE (constructor_fields));
06153
06154
06155
06156 if (constructor_unfilled_fields == constructor_fields)
06157 {
06158 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
06159
06160 while (constructor_unfilled_fields != 0
06161 && DECL_C_BIT_FIELD (constructor_unfilled_fields)
06162 && DECL_NAME (constructor_unfilled_fields) == 0)
06163 constructor_unfilled_fields =
06164 TREE_CHAIN (constructor_unfilled_fields);
06165 }
06166 }
06167
06168 constructor_fields = TREE_CHAIN (constructor_fields);
06169
06170 while (constructor_fields != 0
06171 && DECL_C_BIT_FIELD (constructor_fields)
06172 && DECL_NAME (constructor_fields) == 0)
06173 constructor_fields = TREE_CHAIN (constructor_fields);
06174 }
06175 else if (TREE_CODE (constructor_type) == UNION_TYPE)
06176 {
06177 tree fieldtype;
06178 enum tree_code fieldcode;
06179
06180 if (constructor_fields == 0)
06181 {
06182 pedwarn_init ("excess elements in union initializer");
06183 break;
06184 }
06185
06186 fieldtype = TREE_TYPE (constructor_fields);
06187 if (fieldtype != error_mark_node)
06188 fieldtype = TYPE_MAIN_VARIANT (fieldtype);
06189 fieldcode = TREE_CODE (fieldtype);
06190
06191
06192
06193
06194
06195
06196
06197
06198
06199
06200
06201 if (warn_traditional && !in_system_header && !constructor_designated
06202 && !(value.value && (integer_zerop (value.value)
06203 || real_zerop (value.value))))
06204 warning ("traditional C rejects initialization of unions");
06205
06206
06207 if (value.value != 0
06208 && fieldcode == ARRAY_TYPE
06209 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
06210 && string_flag)
06211 value.value = orig_value;
06212
06213
06214 else if (value.value != 0
06215 && value.value != error_mark_node
06216 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
06217 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
06218 || fieldcode == UNION_TYPE))
06219 {
06220 push_init_level (1);
06221 continue;
06222 }
06223
06224 if (value.value)
06225 {
06226 push_member_name (constructor_fields);
06227 output_init_element (value.value, strict_string,
06228 fieldtype, constructor_fields, 1);
06229 RESTORE_SPELLING_DEPTH (constructor_depth);
06230 }
06231 else
06232
06233
06234 {
06235 constructor_bit_index = DECL_SIZE (constructor_fields);
06236 constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
06237 }
06238
06239 constructor_fields = 0;
06240 }
06241 else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
06242 {
06243 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
06244 enum tree_code eltcode = TREE_CODE (elttype);
06245
06246
06247 if (value.value != 0
06248 && eltcode == ARRAY_TYPE
06249 && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
06250 && string_flag)
06251 value.value = orig_value;
06252
06253
06254 else if (value.value != 0
06255 && value.value != error_mark_node
06256 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != elttype
06257 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
06258 || eltcode == UNION_TYPE))
06259 {
06260 push_init_level (1);
06261 continue;
06262 }
06263
06264 if (constructor_max_index != 0
06265 && (tree_int_cst_lt (constructor_max_index, constructor_index)
06266 || integer_all_onesp (constructor_max_index)))
06267 {
06268 pedwarn_init ("excess elements in array initializer");
06269 break;
06270 }
06271
06272
06273 if (value.value)
06274 {
06275 push_array_bounds (tree_low_cst (constructor_index, 0));
06276 output_init_element (value.value, strict_string,
06277 elttype, constructor_index, 1);
06278 RESTORE_SPELLING_DEPTH (constructor_depth);
06279 }
06280
06281 constructor_index
06282 = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node);
06283
06284 if (!value.value)
06285
06286
06287
06288 constructor_unfilled_index = constructor_index;
06289 }
06290 else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
06291 {
06292 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
06293
06294
06295
06296 if (tree_int_cst_lt (constructor_max_index, constructor_index))
06297 {
06298 pedwarn_init ("excess elements in vector initializer");
06299 break;
06300 }
06301
06302
06303 if (value.value)
06304 output_init_element (value.value, strict_string,
06305 elttype, constructor_index, 1);
06306
06307 constructor_index
06308 = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node);
06309
06310 if (!value.value)
06311
06312
06313
06314 constructor_unfilled_index = constructor_index;
06315 }
06316
06317
06318
06319 else if (constructor_type != error_mark_node
06320 && constructor_fields == 0)
06321 {
06322 pedwarn_init ("excess elements in scalar initializer");
06323 break;
06324 }
06325 else
06326 {
06327 if (value.value)
06328 output_init_element (value.value, strict_string,
06329 constructor_type, NULL_TREE, 1);
06330 constructor_fields = 0;
06331 }
06332
06333
06334
06335 if (constructor_range_stack)
06336 {
06337 struct constructor_range_stack *p, *range_stack;
06338 int finish = 0;
06339
06340 range_stack = constructor_range_stack;
06341 constructor_range_stack = 0;
06342 while (constructor_stack != range_stack->stack)
06343 {
06344 gcc_assert (constructor_stack->implicit);
06345 process_init_element (pop_init_level (1));
06346 }
06347 for (p = range_stack;
06348 !p->range_end || tree_int_cst_equal (p->index, p->range_end);
06349 p = p->prev)
06350 {
06351 gcc_assert (constructor_stack->implicit);
06352 process_init_element (pop_init_level (1));
06353 }
06354
06355 p->index = size_binop (PLUS_EXPR, p->index, bitsize_one_node);
06356 if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
06357 finish = 1;
06358
06359 while (1)
06360 {
06361 constructor_index = p->index;
06362 constructor_fields = p->fields;
06363 if (finish && p->range_end && p->index == p->range_start)
06364 {
06365 finish = 0;
06366 p->prev = 0;
06367 }
06368 p = p->next;
06369 if (!p)
06370 break;
06371 push_init_level (2);
06372 p->stack = constructor_stack;
06373 if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
06374 p->index = p->range_start;
06375 }
06376
06377 if (!finish)
06378 constructor_range_stack = range_stack;
06379 continue;
06380 }
06381
06382 break;
06383 }
06384
06385 constructor_range_stack = 0;
06386 }
06387
06388
06389
06390
06391 tree
06392 build_asm_stmt (tree cv_qualifier, tree args)
06393 {
06394 if (!ASM_VOLATILE_P (args) && cv_qualifier)
06395 ASM_VOLATILE_P (args) = 1;
06396 return add_stmt (args);
06397 }
06398
06399
06400
06401
06402
06403
06404 tree
06405 build_asm_expr (tree string, tree outputs, tree inputs, tree clobbers,
06406 bool simple)
06407 {
06408 tree tail;
06409 tree args;
06410 int i;
06411 const char *constraint;
06412 const char **oconstraints;
06413 bool allows_mem, allows_reg, is_inout;
06414 int ninputs, noutputs;
06415
06416 ninputs = list_length (inputs);
06417 noutputs = list_length (outputs);
06418 oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
06419
06420 string = resolve_asm_operand_names (string, outputs, inputs);
06421
06422
06423 for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
06424 {
06425 tree output = TREE_VALUE (tail);
06426
06427
06428
06429
06430
06431
06432
06433 STRIP_NOPS (output);
06434
06435 if (!lvalue_or_else (output, lv_asm))
06436 output = error_mark_node;
06437
06438 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
06439 oconstraints[i] = constraint;
06440
06441 if (parse_output_constraint (&constraint, i, ninputs, noutputs,
06442 &allows_mem, &allows_reg, &is_inout))
06443 {
06444
06445
06446 if (!allows_reg && !c_mark_addressable (output))
06447 output = error_mark_node;
06448 }
06449 else
06450 output = error_mark_node;
06451
06452 TREE_VALUE (tail) = output;
06453 }
06454
06455
06456
06457
06458 for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
06459 {
06460 tree input;
06461
06462 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
06463 input = TREE_VALUE (tail);
06464
06465 input = default_function_array_conversion (input);
06466
06467 if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
06468 oconstraints, &allows_mem, &allows_reg))
06469 {
06470
06471
06472 if (!allows_reg && allows_mem)
06473 {
06474
06475
06476 STRIP_NOPS (input);
06477 if (!c_mark_addressable (input))
06478 input = error_mark_node;
06479 }
06480 }
06481 else
06482 input = error_mark_node;
06483
06484 TREE_VALUE (tail) = input;
06485 }
06486
06487 args = build_stmt (ASM_EXPR, string, outputs, inputs, clobbers);
06488
06489
06490 if (simple)
06491 {
06492 ASM_VOLATILE_P (args) = 1;
06493 ASM_INPUT_P (args) = 1;
06494 }
06495
06496 return args;
06497 }
06498
06499
06500
06501 tree
06502 c_finish_goto_label (tree label)
06503 {
06504 tree decl = lookup_label (label);
06505 if (!decl)
06506 return NULL_TREE;
06507
06508 if (C_DECL_UNJUMPABLE_STMT_EXPR (decl))
06509 {
06510 error ("jump into statement expression");
06511 return NULL_TREE;
06512 }
06513
06514 if (C_DECL_UNJUMPABLE_VM (decl))
06515 {
06516 error ("jump into scope of identifier with variably modified type");
06517 return NULL_TREE;
06518 }
06519
06520 if (!C_DECL_UNDEFINABLE_STMT_EXPR (decl))
06521 {
06522
06523
06524 struct c_label_list *nlist;
06525 nlist = XOBNEW (&parser_obstack, struct c_label_list);
06526 nlist->next = label_context_stack_se->labels_used;
06527 nlist->label = decl;
06528 label_context_stack_se->labels_used = nlist;
06529 }
06530
06531 if (!C_DECL_UNDEFINABLE_VM (decl))
06532 {
06533
06534
06535
06536 struct c_label_list *nlist;
06537 nlist = XOBNEW (&parser_obstack, struct c_label_list);
06538 nlist->next = label_context_stack_vm->labels_used;
06539 nlist->label = decl;
06540 label_context_stack_vm->labels_used = nlist;
06541 }
06542
06543 TREE_USED (decl) = 1;
06544 return add_stmt (build1 (GOTO_EXPR, void_type_node, decl));
06545 }
06546
06547
06548
06549 tree
06550 c_finish_goto_ptr (tree expr)
06551 {
06552 if (pedantic)
06553 pedwarn ("ISO C forbids %<goto *expr;%>");
06554 expr = convert (ptr_type_node, expr);
06555 return add_stmt (build1 (GOTO_EXPR, void_type_node, expr));
06556 }
06557
06558
06559
06560
06561 tree
06562 c_finish_return (tree retval)
06563 {
06564 tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
06565 bool no_warning = false;
06566
06567 if (TREE_THIS_VOLATILE (current_function_decl))
06568 warning ("function declared %<noreturn%> has a %<return%> statement");
06569
06570 if (!retval)
06571 {
06572 current_function_returns_null = 1;
06573 if ((warn_return_type || flag_isoc99)
06574 && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
06575 {
06576 pedwarn_c99 ("%<return%> with no value, in "
06577 "function returning non-void");
06578 no_warning = true;
06579 }
06580 }
06581 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
06582 {
06583 current_function_returns_null = 1;
06584 if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
06585 pedwarn ("%<return%> with a value, in function returning void");
06586 }
06587 else
06588 {
06589 tree t = convert_for_assignment (valtype, retval, ic_return,
06590 NULL_TREE, NULL_TREE, 0);
06591 tree res = DECL_RESULT (current_function_decl);
06592 tree inner;
06593
06594 current_function_returns_value = 1;
06595 if (t == error_mark_node)
06596 return NULL_TREE;
06597
06598 inner = t = convert (TREE_TYPE (res), t);
06599
06600
06601
06602 while (1)
06603 {
06604 switch (TREE_CODE (inner))
06605 {
06606 case NOP_EXPR: case NON_LVALUE_EXPR: case CONVERT_EXPR:
06607 case PLUS_EXPR:
06608 inner = TREE_OPERAND (inner, 0);
06609 continue;
06610
06611 case MINUS_EXPR:
06612
06613
06614
06615 {
06616 tree op1 = TREE_OPERAND (inner, 1);
06617
06618 while (!POINTER_TYPE_P (TREE_TYPE (op1))
06619 && (TREE_CODE (op1) == NOP_EXPR
06620 || TREE_CODE (op1) == NON_LVALUE_EXPR
06621 || TREE_CODE (op1) == CONVERT_EXPR))
06622 op1 = TREE_OPERAND (op1, 0);
06623
06624 if (POINTER_TYPE_P (TREE_TYPE (op1)))
06625 break;
06626
06627 inner = TREE_OPERAND (inner, 0);
06628 continue;
06629 }
06630
06631 case ADDR_EXPR:
06632 inner = TREE_OPERAND (inner, 0);
06633
06634 while (REFERENCE_CLASS_P (inner)
06635 && TREE_CODE (inner) != INDIRECT_REF)
06636 inner = TREE_OPERAND (inner, 0);
06637
06638 if (DECL_P (inner)
06639 && !DECL_EXTERNAL (inner)
06640 && !TREE_STATIC (inner)
06641 && DECL_CONTEXT (inner) == current_function_decl)
06642 warning ("function returns address of local variable");
06643 break;
06644
06645 default:
06646 break;
06647 }
06648
06649 break;
06650 }
06651
06652 retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
06653 }
06654
06655 ret_stmt = build_stmt (RETURN_EXPR, retval);
06656 TREE_NO_WARNING (ret_stmt) |= no_warning;
06657 return add_stmt (ret_stmt);
06658 }
06659
06660 struct c_switch {
06661
06662 tree switch_stmt;
06663
06664
06665
06666 tree orig_type;
06667
06668
06669
06670
06671
06672
06673 splay_tree cases;
06674
06675
06676
06677
06678 unsigned int blocked_stmt_expr;
06679
06680
06681
06682
06683 unsigned int blocked_vm;
06684
06685
06686 struct c_switch *next;
06687 };
06688
06689
06690
06691
06692
06693
06694
06695 struct c_switch *c_switch_stack;
06696
06697
06698
06699
06700 tree
06701 c_start_case (tree exp)
06702 {
06703 enum tree_code code;
06704 tree type, orig_type = error_mark_node;
06705 struct c_switch *cs;
06706
06707 if (exp != error_mark_node)
06708 {
06709 code = TREE_CODE (TREE_TYPE (exp));
06710 orig_type = TREE_TYPE (exp);
06711
06712 if (!INTEGRAL_TYPE_P (orig_type)
06713 && code != ERROR_MARK)
06714 {
06715 error ("switch quantity not an integer");
06716 exp = integer_zero_node;
06717 orig_type = error_mark_node;
06718 }
06719 else
06720 {
06721 type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
06722
06723 if (warn_traditional && !in_system_header
06724 && (type == long_integer_type_node
06725 || type == long_unsigned_type_node))
06726 warning ("%<long%> switch expression not converted to "
06727 "%<int%> in ISO C");
06728
06729 exp = default_conversion (exp);
06730 type = TREE_TYPE (exp);
06731 }
06732 }
06733
06734
06735 cs = XNEW (struct c_switch);
06736 cs->switch_stmt = build_stmt (SWITCH_STMT, exp, NULL_TREE, orig_type);
06737 cs->orig_type = orig_type;
06738 cs->cases = splay_tree_new (case_compare, NULL, NULL);
06739 cs->blocked_stmt_expr = 0;
06740 cs->blocked_vm = 0;
06741 cs->next = c_switch_stack;
06742 c_switch_stack = cs;
06743
06744 return add_stmt (cs->switch_stmt);
06745 }
06746
06747
06748
06749 tree
06750 do_case (tree low_value, tree high_value)
06751 {
06752 tree label = NULL_TREE;
06753
06754 if (c_switch_stack && !c_switch_stack->blocked_stmt_expr
06755 && !c_switch_stack->blocked_vm)
06756 {
06757 label = c_add_case_label (c_switch_stack->cases,
06758 SWITCH_STMT_COND (c_switch_stack->switch_stmt),
06759 c_switch_stack->orig_type,
06760 low_value, high_value);
06761 if (label == error_mark_node)
06762 label = NULL_TREE;
06763 }
06764 else if (c_switch_stack && c_switch_stack->blocked_stmt_expr)
06765 {
06766 if (low_value)
06767 error ("case label in statement expression not containing "
06768 "enclosing switch statement");
06769 else
06770 error ("%<default%> label in statement expression not containing "
06771 "enclosing switch statement");
06772 }
06773 else if (c_switch_stack && c_switch_stack->blocked_vm)
06774 {
06775 if (low_value)
06776 error ("case label in scope of identifier with variably modified "
06777 "type not containing enclosing switch statement");
06778 else
06779 error ("%<default%> label in scope of identifier with variably "
06780 "modified type not containing enclosing switch statement");
06781 }
06782 else if (low_value)
06783 error ("case label not within a switch statement");
06784 else
06785 error ("%<default%> label not within a switch statement");
06786
06787 return label;
06788 }
06789
06790
06791
06792 void
06793 c_finish_case (tree body)
06794 {
06795 struct c_switch *cs = c_switch_stack;
06796
06797 SWITCH_STMT_BODY (cs->switch_stmt) = body;
06798
06799
06800
06801
06802 gcc_assert (!cs->blocked_stmt_expr);
06803
06804
06805 c_do_switch_warnings (cs->cases, cs->switch_stmt);
06806
06807
06808 c_switch_stack = cs->next;
06809 splay_tree_delete (cs->cases);
06810 XDELETE (cs);
06811 }
06812
06813
06814
06815
06816
06817
06818 void
06819 c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
06820 tree else_block, bool nested_if)
06821 {
06822 tree stmt;
06823
06824
06825 if (warn_parentheses && nested_if && else_block == NULL)
06826 {
06827 tree inner_if = then_block;
06828
06829
06830
06831
06832
06833 while (1)
06834 switch (TREE_CODE (inner_if))
06835 {
06836 case COND_EXPR:
06837 goto found;
06838 case BIND_EXPR:
06839 inner_if = BIND_EXPR_BODY (inner_if);
06840 break;
06841 case STATEMENT_LIST:
06842 inner_if = expr_last (then_block);
06843 break;
06844 case TRY_FINALLY_EXPR:
06845 case TRY_CATCH_EXPR:
06846 inner_if = TREE_OPERAND (inner_if, 0);
06847 break;
06848 default:
06849 gcc_unreachable ();
06850 }
06851 found:
06852
06853 if (COND_EXPR_ELSE (inner_if))
06854 warning ("%Hsuggest explicit braces to avoid ambiguous %<else%>",
06855 &if_locus);
06856 }
06857
06858
06859 if (extra_warnings)
06860 {
06861 tree *inner_then = &then_block, *inner_else = &else_block;
06862
06863 if (TREE_CODE (*inner_then) == STATEMENT_LIST
06864 && STATEMENT_LIST_TAIL (*inner_then))
06865 inner_then = &STATEMENT_LIST_TAIL (*inner_then)->stmt;
06866 if (*inner_else && TREE_CODE (*inner_else) == STATEMENT_LIST
06867 && STATEMENT_LIST_TAIL (*inner_else))
06868 inner_else = &STATEMENT_LIST_TAIL (*inner_else)->stmt;
06869
06870 if (TREE_CODE (*inner_then) == NOP_EXPR && !TREE_TYPE (*inner_then))
06871 {
06872 if (!*inner_else)
06873 warning ("%Hempty body in an if-statement",
06874 EXPR_LOCUS (*inner_then));
06875
06876 *inner_then = alloc_stmt_list ();
06877 }
06878 if (*inner_else
06879 && TREE_CODE (*inner_else) == NOP_EXPR
06880 && !TREE_TYPE (*inner_else))
06881 {
06882 warning ("%Hempty body in an else-statement",
06883 EXPR_LOCUS (*inner_else));
06884
06885 *inner_else = alloc_stmt_list ();
06886 }
06887 }
06888
06889 stmt = build3 (COND_EXPR, NULL_TREE, cond, then_block, else_block);
06890 SET_EXPR_LOCATION (stmt, if_locus);
06891 add_stmt (stmt);
06892 }
06893
06894
06895
06896
06897
06898
06899
06900 void
06901 c_finish_loop (location_t start_locus, tree cond, tree incr, tree body,
06902 tree blab, tree clab, bool cond_is_first)
06903 {
06904 tree entry = NULL, exit = NULL, t;
06905
06906
06907 if (cond && integer_zerop (cond))
06908 {
06909 if (cond_is_first)
06910 {
06911 t = build_and_jump (&blab);
06912 SET_EXPR_LOCATION (t, start_locus);
06913 add_stmt (t);
06914 }
06915 }
06916 else
06917 {
06918 tree top = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
06919
06920
06921
06922
06923 exit = build_and_jump (&LABEL_EXPR_LABEL (top));
06924
06925 if (cond && !integer_nonzerop (cond))
06926 {
06927
06928
06929
06930 if (cond_is_first)
06931 {
06932 if (incr || !clab)
06933 {
06934 entry = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
06935 t = build_and_jump (&LABEL_EXPR_LABEL (entry));
06936 }
06937 else
06938 t = build1 (GOTO_EXPR, void_type_node, clab);
06939 SET_EXPR_LOCATION (t, start_locus);
06940 add_stmt (t);
06941 }
06942
06943 t = build_and_jump (&blab);
06944 exit = build3 (COND_EXPR, void_type_node, cond, exit, t);
06945 exit = fold (exit);
06946 if (cond_is_first)
06947 SET_EXPR_LOCATION (exit, start_locus);
06948 else
06949 SET_EXPR_LOCATION (exit, input_location);
06950 }
06951
06952 add_stmt (top);
06953 }
06954
06955 if (body)
06956 add_stmt (body);
06957 if (clab)
06958 add_stmt (build1 (LABEL_EXPR, void_type_node, clab));
06959 if (incr)
06960 add_stmt (incr);
06961 if (entry)
06962 add_stmt (entry);
06963 if (exit)
06964 add_stmt (exit);
06965 if (blab)
06966 add_stmt (build1 (LABEL_EXPR, void_type_node, blab));
06967 }
06968
06969 tree
06970 c_finish_bc_stmt (tree *label_p, bool is_break)
06971 {
06972 bool skip;
06973 tree label = *label_p;
06974
06975
06976
06977
06978
06979
06980
06981
06982 skip = !block_may_fallthru (cur_stmt_list);
06983
06984 if (!label)
06985 {
06986 if (!skip)
06987 *label_p = label = create_artificial_label ();
06988 }
06989 else if (TREE_CODE (label) != LABEL_DECL)
06990 {
06991 if (is_break)
06992 error ("break statement not within loop or switch");
06993 else
06994 error ("continue statement not within a loop");
06995 return NULL_TREE;
06996 }
06997
06998 if (skip)
06999 return NULL_TREE;
07000
07001 return add_stmt (build1 (GOTO_EXPR, void_type_node, label));
07002 }
07003
07004
07005
07006 static void
07007 emit_side_effect_warnings (tree expr)
07008 {
07009 if (expr == error_mark_node)
07010 ;
07011 else if (!TREE_SIDE_EFFECTS (expr))
07012 {
07013 if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr))
07014 warning ("%Hstatement with no effect",
07015 EXPR_HAS_LOCATION (expr) ? EXPR_LOCUS (expr) : &input_location);
07016 }
07017 else if (warn_unused_value)
07018 warn_if_unused_value (expr, input_location);
07019 }
07020
07021
07022
07023
07024 tree
07025 c_process_expr_stmt (tree expr)
07026 {
07027 if (!expr)
07028 return NULL_TREE;
07029
07030
07031
07032 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
07033 && (flag_isoc99 || lvalue_p (expr)))
07034 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
07035 expr = default_conversion (expr);
07036
07037 if (warn_sequence_point)
07038 verify_sequence_points (expr);
07039
07040 if (TREE_TYPE (expr) != error_mark_node
07041 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
07042 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
07043 error ("expression statement has incomplete type");
07044
07045
07046
07047
07048 if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
07049 && (extra_warnings || warn_unused_value))
07050 emit_side_effect_warnings (expr);
07051
07052
07053
07054 if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
07055 expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
07056
07057 if (EXPR_P (expr))
07058 SET_EXPR_LOCATION (expr, input_location);
07059
07060 return expr;
07061 }
07062
07063
07064
07065 tree
07066 c_finish_expr_stmt (tree expr)
07067 {
07068 if (expr)
07069 return add_stmt (c_process_expr_stmt (expr));
07070 else
07071 return NULL;
07072 }
07073
07074
07075
07076
07077 tree
07078 c_begin_stmt_expr (void)
07079 {
07080 tree ret;
07081 struct c_label_context_se *nstack;
07082 struct c_label_list *glist;
07083
07084
07085
07086
07087 keep_next_level ();
07088 ret = c_begin_compound_stmt (true);
07089 if (c_switch_stack)
07090 {
07091 c_switch_stack->blocked_stmt_expr++;
07092 gcc_assert (c_switch_stack->blocked_stmt_expr != 0);
07093 }
07094 for (glist = label_context_stack_se->labels_used;
07095 glist != NULL;
07096 glist = glist->next)
07097 {
07098 C_DECL_UNDEFINABLE_STMT_EXPR (glist->label) = 1;
07099 }
07100 nstack = XOBNEW (&parser_obstack, struct c_label_context_se);
07101 nstack->labels_def = NULL;
07102 nstack->labels_used = NULL;
07103 nstack->next = label_context_stack_se;
07104 label_context_stack_se = nstack;
07105
07106
07107 STATEMENT_LIST_STMT_EXPR (ret) = 1;
07108
07109 return ret;
07110 }
07111
07112 tree
07113 c_finish_stmt_expr (tree body)
07114 {
07115 tree last, type, tmp, val;
07116 tree *last_p;
07117 struct c_label_list *dlist, *glist, *glist_prev = NULL;
07118
07119 body = c_end_compound_stmt (body, true);
07120 if (c_switch_stack)
07121 {
07122 gcc_assert (c_switch_stack->blocked_stmt_expr != 0);
07123 c_switch_stack->blocked_stmt_expr--;
07124 }
07125
07126
07127 for (dlist = label_context_stack_se->labels_def;
07128 dlist != NULL;
07129 dlist = dlist->next)
07130 {
07131 C_DECL_UNJUMPABLE_STMT_EXPR (dlist->label) = 1;
07132 }
07133
07134
07135 for (glist = label_context_stack_se->next->labels_used;
07136 glist != NULL;
07137 glist = glist->next)
07138 {
07139 C_DECL_UNDEFINABLE_STMT_EXPR (glist->label) = 0;
07140 glist_prev = glist;
07141 }
07142 if (glist_prev != NULL)
07143 glist_prev->next = label_context_stack_se->labels_used;
07144 else
07145 label_context_stack_se->next->labels_used
07146 = label_context_stack_se->labels_used;
07147 label_context_stack_se = label_context_stack_se->next;
07148
07149
07150
07151 last_p = &BIND_EXPR_BODY (body);
07152 last = BIND_EXPR_BODY (body);
07153
07154 continue_searching:
07155 if (TREE_CODE (last) == STATEMENT_LIST)
07156 {
07157 tree_stmt_iterator i;
07158
07159
07160 if (!TREE_SIDE_EFFECTS (last))
07161 return body;
07162
07163
07164
07165 if (extra_warnings || warn_unused_value)
07166 {
07167 for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i))
07168 emit_side_effect_warnings (tsi_stmt (i));
07169 }
07170 else
07171 i = tsi_last (last);
07172 last_p = tsi_stmt_ptr (i);
07173 last = *last_p;
07174 }
07175
07176
07177
07178 if (TREE_CODE (last) == TRY_FINALLY_EXPR
07179 || TREE_CODE (last) == TRY_CATCH_EXPR)
07180 {
07181 last_p = &TREE_OPERAND (last, 0);
07182 last = *last_p;
07183 goto continue_searching;
07184 }
07185
07186
07187
07188 if (last == error_mark_node
07189 || (last == BIND_EXPR_BODY (body)
07190 && BIND_EXPR_VARS (body) == NULL))
07191 return last;
07192
07193
07194 type = TREE_TYPE (last);
07195
07196
07197
07198 if (!type || VOID_TYPE_P (type))
07199 return body;
07200
07201
07202
07203
07204 tmp = create_tmp_var_raw (type, NULL);
07205
07206
07207
07208 val = last;
07209 if (TREE_CODE (val) == NOP_EXPR
07210 && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
07211 val = TREE_OPERAND (val, 0);
07212
07213 *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
07214 SET_EXPR_LOCUS (*last_p, EXPR_LOCUS (last));
07215
07216 return build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
07217 }
07218
07219
07220
07221
07222
07223 void
07224 c_begin_vm_scope (unsigned int scope)
07225 {
07226 struct c_label_context_vm *nstack;
07227 struct c_label_list *glist;
07228
07229 gcc_assert (scope > 0);
07230 if (c_switch_stack && !c_switch_stack->blocked_vm)
07231 c_switch_stack->blocked_vm = scope;
07232 for (glist = label_context_stack_vm->labels_used;
07233 glist != NULL;
07234 glist = glist->next)
07235 {
07236 C_DECL_UNDEFINABLE_VM (glist->label) = 1;
07237 }
07238 nstack = XOBNEW (&parser_obstack, struct c_label_context_vm);
07239 nstack->labels_def = NULL;
07240 nstack->labels_used = NULL;
07241 nstack->scope = scope;
07242 nstack->next = label_context_stack_vm;
07243 label_context_stack_vm = nstack;
07244 }
07245
07246
07247
07248
07249 void
07250 c_end_vm_scope (unsigned int scope)
07251 {
07252 if (label_context_stack_vm == NULL)
07253 return;
07254 if (c_switch_stack && c_switch_stack->blocked_vm == scope)
07255 c_switch_stack->blocked_vm = 0;
07256
07257
07258 while (label_context_stack_vm->scope == scope)
07259 {
07260 struct c_label_list *dlist, *glist, *glist_prev = NULL;
07261
07262
07263
07264 for (dlist = label_context_stack_vm->labels_def;
07265 dlist != NULL;
07266 dlist = dlist->next)
07267 {
07268 C_DECL_UNJUMPABLE_VM (dlist->label) = 1;
07269 }
07270
07271
07272 for (glist = label_context_stack_vm->next->labels_used;
07273 glist != NULL;
07274 glist = glist->next)
07275 {
07276 C_DECL_UNDEFINABLE_VM (glist->label) = 0;
07277 glist_prev = glist;
07278 }
07279 if (glist_prev != NULL)
07280 glist_prev->next = label_context_stack_vm->labels_used;
07281 else
07282 label_context_stack_vm->next->labels_used
07283 = label_context_stack_vm->labels_used;
07284 label_context_stack_vm = label_context_stack_vm->next;
07285 }
07286 }
07287
07288
07289
07290
07291 tree
07292 c_begin_compound_stmt (bool do_scope)
07293 {
07294 tree stmt = push_stmt_list ();
07295 if (do_scope)
07296 push_scope ();
07297 return stmt;
07298 }
07299
07300 tree
07301 c_end_compound_stmt (tree stmt, bool do_scope)
07302 {
07303 tree block = NULL;
07304
07305 if (do_scope)
07306 {
07307 if (c_dialect_objc ())
07308 objc_clear_super_receiver ();
07309 block = pop_scope ();
07310 }
07311
07312 stmt = pop_stmt_list (stmt);
07313 stmt = c_build_bind_expr (block, stmt);
07314
07315
07316
07317
07318
07319
07320 if (cur_stmt_list
07321 && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
07322 && TREE_CODE (stmt) != BIND_EXPR)
07323 {
07324 stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
07325 TREE_SIDE_EFFECTS (stmt) = 1;
07326 }
07327
07328 return stmt;
07329 }
07330
07331
07332
07333
07334
07335 void
07336 push_cleanup (tree ARG_UNUSED (decl), tree cleanup, bool eh_only)
07337 {
07338 enum tree_code code;
07339 tree stmt, list;
07340 bool stmt_expr;
07341
07342 code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
07343 stmt = build_stmt (code, NULL, cleanup);
07344 add_stmt (stmt);
07345 stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
07346 list = push_stmt_list ();
07347 TREE_OPERAND (stmt, 0) = list;
07348 STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
07349 }
07350
07351
07352
07353
07354
07355
07356
07357
07358
07359
07360
07361
07362
07363
07364
07365
07366 tree
07367 build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
07368 int convert_p)
07369 {
07370 tree type0, type1;
07371 enum tree_code code0, code1;
07372 tree op0, op1;
07373
07374
07375
07376
07377 enum tree_code resultcode = code;
07378
07379
07380
07381 tree result_type = NULL;
07382
07383
07384
07385
07386 int converted = 0;
07387
07388
07389
07390 tree build_type = 0;
07391
07392
07393
07394 tree final_type = 0;
07395
07396
07397
07398
07399
07400
07401
07402 int shorten = 0;
07403
07404
07405
07406
07407 int short_compare = 0;
07408
07409
07410
07411 int short_shift = 0;
07412
07413
07414 int common = 0;
07415
07416 if (convert_p)
07417 {
07418 op0 = default_conversion (orig_op0);
07419 op1 = default_conversion (orig_op1);
07420 }
07421 else
07422 {
07423 op0 = orig_op0;
07424 op1 = orig_op1;
07425 }
07426
07427 type0 = TREE_TYPE (op0);
07428 type1 = TREE_TYPE (op1);
07429
07430
07431
07432 code0 = TREE_CODE (type0);
07433 code1 = TREE_CODE (type1);
07434
07435
07436 STRIP_TYPE_NOPS (op0);
07437 STRIP_TYPE_NOPS (op1);
07438
07439
07440
07441
07442 if (code0 == ERROR_MARK || code1 == ERROR_MARK)
07443 return error_mark_node;
07444
07445 switch (code)
07446 {
07447 case PLUS_EXPR:
07448
07449 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
07450 return pointer_int_sum (PLUS_EXPR, op0, op1);
07451 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
07452 return pointer_int_sum (PLUS_EXPR, op1, op0);
07453 else
07454 common = 1;
07455 break;
07456
07457 case MINUS_EXPR:
07458
07459
07460 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
07461 && comp_target_types (type0, type1, 1))
07462 return pointer_diff (op0, op1);
07463
07464 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
07465 return pointer_int_sum (MINUS_EXPR, op0, op1);
07466 else
07467 common = 1;
07468 break;
07469
07470 case MULT_EXPR:
07471 common = 1;
07472 break;
07473
07474 case TRUNC_DIV_EXPR:
07475 case CEIL_DIV_EXPR:
07476 case FLOOR_DIV_EXPR:
07477 case ROUND_DIV_EXPR:
07478 case EXACT_DIV_EXPR:
07479
07480
07481 if (warn_div_by_zero && skip_evaluation == 0 && integer_zerop (op1))
07482 warning ("division by zero");
07483
07484 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
07485 || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
07486 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
07487 || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
07488 {
07489 enum tree_code tcode0 = code0, tcode1 = code1;
07490
07491 if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
07492 tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
07493 if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
07494 tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
07495
07496 if (!(tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE))
07497 resultcode = RDIV_EXPR;
07498 else
07499
07500
07501
07502
07503
07504 shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0))
07505 || (TREE_CODE (op1) == INTEGER_CST
07506 && !integer_all_onesp (op1)));
07507 common = 1;
07508 }
07509 break;
07510
07511 case BIT_AND_EXPR:
07512 case BIT_IOR_EXPR:
07513 case BIT_XOR_EXPR:
07514 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
07515 shorten = -1;
07516 else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE)
07517 common = 1;
07518 break;
07519
07520 case TRUNC_MOD_EXPR:
07521 case FLOOR_MOD_EXPR:
07522 if (warn_div_by_zero && skip_evaluation == 0 && integer_zerop (op1))
07523 warning ("division by zero");
07524
07525 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
07526 {
07527
07528
07529
07530
07531 shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0))
07532 || (TREE_CODE (op1) == INTEGER_CST
07533 && !integer_all_onesp (op1)));
07534 common = 1;
07535 }
07536 break;
07537
07538 case TRUTH_ANDIF_EXPR:
07539 case TRUTH_ORIF_EXPR:
07540 case TRUTH_AND_EXPR:
07541 case TRUTH_OR_EXPR:
07542 case TRUTH_XOR_EXPR:
07543 if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
07544 || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
07545 && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
07546 || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
07547 {
07548
07549
07550
07551 result_type = integer_type_node;
07552 op0 = lang_hooks.truthvalue_conversion (op0);
07553 op1 = lang_hooks.truthvalue_conversion (op1);
07554 converted = 1;
07555 }
07556 break;
07557
07558
07559
07560
07561
07562 case RSHIFT_EXPR:
07563 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
07564 {
07565 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
07566 {
07567 if (tree_int_cst_sgn (op1) < 0)
07568 warning ("right shift count is negative");
07569 else
07570 {
07571 if (!integer_zerop (op1))
07572 short_shift = 1;
07573
07574 if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
07575 warning ("right shift count >= width of type");
07576 }
07577 }
07578
07579
07580 result_type = type0;
07581
07582
07583 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
07584 op1 = convert (integer_type_node, op1);
07585
07586 converted = 1;
07587 }
07588 break;
07589
07590 case LSHIFT_EXPR:
07591 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
07592 {
07593 if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
07594 {
07595 if (tree_int_cst_sgn (op1) < 0)
07596 warning ("left shift count is negative");
07597
07598 else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
07599 warning ("left shift count >= width of type");
07600 }
07601
07602
07603 result_type = type0;
07604
07605
07606 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
07607 op1 = convert (integer_type_node, op1);
07608
07609 converted = 1;
07610 }
07611 break;
07612
07613 case EQ_EXPR:
07614 case NE_EXPR:
07615 if (warn_float_equal && (code0 == REAL_TYPE || code1 == REAL_TYPE))
07616 warning ("comparing floating point with == or != is unsafe");
07617
07618
07619 build_type = integer_type_node;
07620 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
07621 || code0 == COMPLEX_TYPE)
07622 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
07623 || code1 == COMPLEX_TYPE))
07624 short_compare = 1;
07625 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
07626 {
07627 tree tt0 = TREE_TYPE (type0);
07628 tree tt1 = TREE_TYPE (type1);
07629
07630
07631
07632 if (comp_target_types (type0, type1, 1))
07633 result_type = common_pointer_type (type0, type1);
07634 else if (VOID_TYPE_P (tt0))
07635 {
07636
07637
07638 if (pedantic && (!integer_zerop (op0) || op0 != orig_op0)
07639 && TREE_CODE (tt1) == FUNCTION_TYPE)
07640 pedwarn ("ISO C forbids comparison of %<void *%>"
07641 " with function pointer");
07642 }
07643 else if (VOID_TYPE_P (tt1))
07644 {
07645 if (pedantic && (!integer_zerop (op1) || op1 != orig_op1)
07646 && TREE_CODE (tt0) == FUNCTION_TYPE)
07647 pedwarn ("ISO C forbids comparison of %<void *%>"
07648 " with function pointer");
07649 }
07650 else
07651 pedwarn ("comparison of distinct pointer types lacks a cast");
07652
07653 if (result_type == NULL_TREE)
07654 result_type = ptr_type_node;
07655 }
07656 else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
07657 && integer_zerop (op1))
07658 result_type = type0;
07659 else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
07660 && integer_zerop (op0))
07661 result_type = type1;
07662 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
07663 {
07664 result_type = type0;
07665 pedwarn ("comparison between pointer and integer");
07666 }
07667 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
07668 {
07669 result_type = type1;
07670 pedwarn ("comparison between pointer and integer");
07671 }
07672 break;
07673
07674 case LE_EXPR:
07675 case GE_EXPR:
07676 case LT_EXPR:
07677 case GT_EXPR:
07678 build_type = integer_type_node;
07679 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
07680 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
07681 short_compare = 1;
07682 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
07683 {
07684 if (comp_target_types (type0, type1, 1))
07685 {
07686 result_type = common_pointer_type (type0, type1);
07687 if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
07688 != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
07689 pedwarn ("comparison of complete and incomplete poi