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