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