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