Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-typeck.c @ 70:b81903832de2
merge c-decl.c
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 21 Aug 2011 09:24:16 +0900 |
parents | 1b10fe6932e1 |
children | 20c18990c3e4 |
comparison
equal
deleted
inserted
replaced
69:1b10fe6932e1 | 70:b81903832de2 |
---|---|
38 #include "intl.h" | 38 #include "intl.h" |
39 #include "target.h" | 39 #include "target.h" |
40 #include "tree-iterator.h" | 40 #include "tree-iterator.h" |
41 #include "bitmap.h" | 41 #include "bitmap.h" |
42 #include "gimple.h" | 42 #include "gimple.h" |
43 #include "tree-flow.h" | |
44 #ifndef noCbC | |
45 #include "cbc-tree.h" | |
46 #endif | |
47 #include "c-family/c-objc.h" | 43 #include "c-family/c-objc.h" |
48 | 44 |
49 /* Possible cases of implicit bad conversions. Used to select | 45 /* Possible cases of implicit bad conversions. Used to select |
50 diagnostic messages in convert_for_assignment. */ | 46 diagnostic messages in convert_for_assignment. */ |
51 enum impl_conv { | 47 enum impl_conv { |
79 static int function_types_compatible_p (const_tree, const_tree, bool *, | 75 static int function_types_compatible_p (const_tree, const_tree, bool *, |
80 bool *); | 76 bool *); |
81 static int type_lists_compatible_p (const_tree, const_tree, bool *, bool *); | 77 static int type_lists_compatible_p (const_tree, const_tree, bool *, bool *); |
82 static tree lookup_field (tree, tree); | 78 static tree lookup_field (tree, tree); |
83 static int convert_arguments (tree, VEC(tree,gc) *, VEC(tree,gc) *, tree, | 79 static int convert_arguments (tree, VEC(tree,gc) *, VEC(tree,gc) *, tree, |
84 tree); | 80 tree); |
85 static tree pointer_diff (location_t, tree, tree); | 81 static tree pointer_diff (location_t, tree, tree); |
86 static tree convert_for_assignment (location_t, tree, tree, tree, | 82 static tree convert_for_assignment (location_t, tree, tree, tree, |
87 enum impl_conv, bool, tree, tree, int); | 83 enum impl_conv, bool, tree, tree, int); |
88 static tree valid_compound_expr_initializer (tree, tree); | 84 static tree valid_compound_expr_initializer (tree, tree); |
89 static void push_string (const char *); | 85 static void push_string (const char *); |
90 static void push_member_name (tree); | 86 static void push_member_name (tree); |
91 static int spelling_length (void); | 87 static int spelling_length (void); |
92 static char *print_spelling (char *); | 88 static char *print_spelling (char *); |
113 { | 109 { |
114 /* This should really operate on c_expr structures, but they aren't | 110 /* This should really operate on c_expr structures, but they aren't |
115 yet available everywhere required. */ | 111 yet available everywhere required. */ |
116 tree type = TREE_TYPE (expr); | 112 tree type = TREE_TYPE (expr); |
117 return (TREE_CODE (expr) == INTEGER_CST | 113 return (TREE_CODE (expr) == INTEGER_CST |
118 && !TREE_OVERFLOW (expr) | 114 && !TREE_OVERFLOW (expr) |
119 && integer_zerop (expr) | 115 && integer_zerop (expr) |
120 && (INTEGRAL_TYPE_P (type) | 116 && (INTEGRAL_TYPE_P (type) |
121 || (TREE_CODE (type) == POINTER_TYPE | 117 || (TREE_CODE (type) == POINTER_TYPE |
122 && VOID_TYPE_P (TREE_TYPE (type)) | 118 && VOID_TYPE_P (TREE_TYPE (type)) |
123 && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED))); | 119 && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED))); |
124 } | 120 } |
125 | 121 |
126 /* EXPR may appear in an unevaluated part of an integer constant | 122 /* EXPR may appear in an unevaluated part of an integer constant |
127 expression, but not in an evaluated part. Wrap it in a | 123 expression, but not in an evaluated part. Wrap it in a |
128 C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an | 124 C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an |
204 /* Avoid duplicate error message. */ | 200 /* Avoid duplicate error message. */ |
205 if (TREE_CODE (type) == ERROR_MARK) | 201 if (TREE_CODE (type) == ERROR_MARK) |
206 return; | 202 return; |
207 | 203 |
208 if (value != 0 && (TREE_CODE (value) == VAR_DECL | 204 if (value != 0 && (TREE_CODE (value) == VAR_DECL |
209 || TREE_CODE (value) == PARM_DECL)) | 205 || TREE_CODE (value) == PARM_DECL)) |
210 error ("%qD has an incomplete type", value); | 206 error ("%qD has an incomplete type", value); |
211 else | 207 else |
212 { | 208 { |
213 retry: | 209 retry: |
214 /* We must print an error message. Be clever about what it says. */ | 210 /* We must print an error message. Be clever about what it says. */ |
215 | 211 |
216 switch (TREE_CODE (type)) | 212 switch (TREE_CODE (type)) |
217 { | 213 { |
218 case RECORD_TYPE: | 214 case RECORD_TYPE: |
219 type_code_string = "struct"; | 215 type_code_string = "struct"; |
220 break; | 216 break; |
221 | 217 |
222 case UNION_TYPE: | 218 case UNION_TYPE: |
223 type_code_string = "union"; | 219 type_code_string = "union"; |
224 break; | 220 break; |
225 | 221 |
226 case ENUMERAL_TYPE: | 222 case ENUMERAL_TYPE: |
227 type_code_string = "enum"; | 223 type_code_string = "enum"; |
228 break; | 224 break; |
229 | 225 |
230 case VOID_TYPE: | 226 case VOID_TYPE: |
231 error ("invalid use of void expression"); | 227 error ("invalid use of void expression"); |
232 return; | 228 return; |
233 | 229 |
234 case ARRAY_TYPE: | 230 case ARRAY_TYPE: |
235 if (TYPE_DOMAIN (type)) | 231 if (TYPE_DOMAIN (type)) |
236 { | 232 { |
237 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL) | 233 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL) |
238 { | 234 { |
239 error ("invalid use of flexible array member"); | 235 error ("invalid use of flexible array member"); |
240 return; | 236 return; |
241 } | 237 } |
242 type = TREE_TYPE (type); | 238 type = TREE_TYPE (type); |
243 goto retry; | 239 goto retry; |
244 } | 240 } |
245 error ("invalid use of array with unspecified bounds"); | 241 error ("invalid use of array with unspecified bounds"); |
246 return; | 242 return; |
247 | 243 |
248 default: | 244 default: |
249 gcc_unreachable (); | 245 gcc_unreachable (); |
250 } | 246 } |
251 | 247 |
252 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | 248 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) |
253 error ("invalid use of undefined type %<%s %E%>", | 249 error ("invalid use of undefined type %<%s %E%>", |
254 type_code_string, TYPE_NAME (type)); | 250 type_code_string, TYPE_NAME (type)); |
255 else | 251 else |
256 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ | 252 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ |
257 error ("invalid use of incomplete typedef %qD", TYPE_NAME (type)); | 253 error ("invalid use of incomplete typedef %qD", TYPE_NAME (type)); |
258 } | 254 } |
259 } | 255 } |
260 | 256 |
261 /* Given a type, apply default promotions wrt unnamed function | 257 /* Given a type, apply default promotions wrt unnamed function |
262 arguments and return the new type. */ | 258 arguments and return the new type. */ |
269 | 265 |
270 if (c_promoting_integer_type_p (type)) | 266 if (c_promoting_integer_type_p (type)) |
271 { | 267 { |
272 /* Preserve unsignedness if not really getting any wider. */ | 268 /* Preserve unsignedness if not really getting any wider. */ |
273 if (TYPE_UNSIGNED (type) | 269 if (TYPE_UNSIGNED (type) |
274 && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))) | 270 && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))) |
275 return unsigned_type_node; | 271 return unsigned_type_node; |
276 return integer_type_node; | 272 return integer_type_node; |
277 } | 273 } |
278 | 274 |
279 return type; | 275 return type; |
280 } | 276 } |
319 superset address space. If there isn't one, raise an error. */ | 315 superset address space. If there isn't one, raise an error. */ |
320 if (!addr_space_superset (as_type, as_like, &as_common)) | 316 if (!addr_space_superset (as_type, as_like, &as_common)) |
321 { | 317 { |
322 as_common = as_type; | 318 as_common = as_type; |
323 error ("%qT and %qT are in disjoint named address spaces", | 319 error ("%qT and %qT are in disjoint named address spaces", |
324 type, like); | 320 type, like); |
325 } | 321 } |
326 | 322 |
327 return c_build_qualified_type (type, | 323 return c_build_qualified_type (type, |
328 TYPE_QUALS_NO_ADDR_SPACE (type) | 324 TYPE_QUALS_NO_ADDR_SPACE (type) |
329 | TYPE_QUALS_NO_ADDR_SPACE (like) | 325 | TYPE_QUALS_NO_ADDR_SPACE (like) |
330 | ENCODE_QUAL_ADDR_SPACE (as_common)); | 326 | ENCODE_QUAL_ADDR_SPACE (as_common)); |
331 } | 327 } |
332 | 328 |
333 /* Return true iff the given tree T is a variable length array. */ | 329 /* Return true iff the given tree T is a variable length array. */ |
334 | 330 |
335 bool | 331 bool |
385 switch (code1) | 381 switch (code1) |
386 { | 382 { |
387 case POINTER_TYPE: | 383 case POINTER_TYPE: |
388 /* For two pointers, do this recursively on the target type. */ | 384 /* For two pointers, do this recursively on the target type. */ |
389 { | 385 { |
390 tree pointed_to_1 = TREE_TYPE (t1); | 386 tree pointed_to_1 = TREE_TYPE (t1); |
391 tree pointed_to_2 = TREE_TYPE (t2); | 387 tree pointed_to_2 = TREE_TYPE (t2); |
392 tree target = composite_type (pointed_to_1, pointed_to_2); | 388 tree target = composite_type (pointed_to_1, pointed_to_2); |
393 t1 = build_pointer_type (target); | 389 t1 = build_pointer_type (target); |
394 t1 = build_type_attribute_variant (t1, attributes); | 390 t1 = build_type_attribute_variant (t1, attributes); |
395 return qualify_type (t1, t2); | 391 return qualify_type (t1, t2); |
396 } | 392 } |
397 | 393 |
398 case ARRAY_TYPE: | 394 case ARRAY_TYPE: |
399 { | 395 { |
400 tree elt = composite_type (TREE_TYPE (t1), TREE_TYPE (t2)); | 396 tree elt = composite_type (TREE_TYPE (t1), TREE_TYPE (t2)); |
401 int quals; | 397 int quals; |
402 tree unqual_elt; | 398 tree unqual_elt; |
403 tree d1 = TYPE_DOMAIN (t1); | 399 tree d1 = TYPE_DOMAIN (t1); |
404 tree d2 = TYPE_DOMAIN (t2); | 400 tree d2 = TYPE_DOMAIN (t2); |
405 bool d1_variable, d2_variable; | 401 bool d1_variable, d2_variable; |
406 bool d1_zero, d2_zero; | 402 bool d1_zero, d2_zero; |
407 bool t1_complete, t2_complete; | 403 bool t1_complete, t2_complete; |
408 | 404 |
409 /* We should not have any type quals on arrays at all. */ | 405 /* We should not have any type quals on arrays at all. */ |
410 gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1) | 406 gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1) |
411 && !TYPE_QUALS_NO_ADDR_SPACE (t2)); | 407 && !TYPE_QUALS_NO_ADDR_SPACE (t2)); |
412 | 408 |
413 t1_complete = COMPLETE_TYPE_P (t1); | 409 t1_complete = COMPLETE_TYPE_P (t1); |
414 t2_complete = COMPLETE_TYPE_P (t2); | 410 t2_complete = COMPLETE_TYPE_P (t2); |
415 | 411 |
416 d1_zero = d1 == 0 || !TYPE_MAX_VALUE (d1); | 412 d1_zero = d1 == 0 || !TYPE_MAX_VALUE (d1); |
417 d2_zero = d2 == 0 || !TYPE_MAX_VALUE (d2); | 413 d2_zero = d2 == 0 || !TYPE_MAX_VALUE (d2); |
418 | 414 |
419 d1_variable = (!d1_zero | 415 d1_variable = (!d1_zero |
420 && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST | 416 && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST |
421 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST)); | 417 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST)); |
422 d2_variable = (!d2_zero | 418 d2_variable = (!d2_zero |
423 && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST | 419 && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST |
424 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)); | 420 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)); |
425 d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1)); | 421 d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1)); |
426 d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2)); | 422 d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2)); |
427 | 423 |
428 /* Save space: see if the result is identical to one of the args. */ | 424 /* Save space: see if the result is identical to one of the args. */ |
429 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1) | 425 if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1) |
430 && (d2_variable || d2_zero || !d1_variable)) | 426 && (d2_variable || d2_zero || !d1_variable)) |
431 return build_type_attribute_variant (t1, attributes); | 427 return build_type_attribute_variant (t1, attributes); |
432 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2) | 428 if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2) |
433 && (d1_variable || d1_zero || !d2_variable)) | 429 && (d1_variable || d1_zero || !d2_variable)) |
434 return build_type_attribute_variant (t2, attributes); | 430 return build_type_attribute_variant (t2, attributes); |
435 | 431 |
436 if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1)) | 432 if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1)) |
437 return build_type_attribute_variant (t1, attributes); | 433 return build_type_attribute_variant (t1, attributes); |
438 if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1)) | 434 if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1)) |
439 return build_type_attribute_variant (t2, attributes); | 435 return build_type_attribute_variant (t2, attributes); |
440 | 436 |
441 /* Merge the element types, and have a size if either arg has | 437 /* Merge the element types, and have a size if either arg has |
442 one. We may have qualifiers on the element types. To set | 438 one. We may have qualifiers on the element types. To set |
443 up TYPE_MAIN_VARIANT correctly, we need to form the | 439 up TYPE_MAIN_VARIANT correctly, we need to form the |
444 composite of the unqualified types and add the qualifiers | 440 composite of the unqualified types and add the qualifiers |
445 back at the end. */ | 441 back at the end. */ |
446 quals = TYPE_QUALS (strip_array_types (elt)); | 442 quals = TYPE_QUALS (strip_array_types (elt)); |
447 unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED); | 443 unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED); |
448 t1 = build_array_type (unqual_elt, | 444 t1 = build_array_type (unqual_elt, |
449 TYPE_DOMAIN ((TYPE_DOMAIN (t1) | 445 TYPE_DOMAIN ((TYPE_DOMAIN (t1) |
450 && (d2_variable | 446 && (d2_variable |
451 || d2_zero | 447 || d2_zero |
452 || !d1_variable)) | 448 || !d1_variable)) |
453 ? t1 | 449 ? t1 |
454 : t2)); | 450 : t2)); |
455 /* Ensure a composite type involving a zero-length array type | 451 /* Ensure a composite type involving a zero-length array type |
456 is a zero-length type not an incomplete type. */ | 452 is a zero-length type not an incomplete type. */ |
457 if (d1_zero && d2_zero | 453 if (d1_zero && d2_zero |
458 && (t1_complete || t2_complete) | 454 && (t1_complete || t2_complete) |
459 && !COMPLETE_TYPE_P (t1)) | 455 && !COMPLETE_TYPE_P (t1)) |
460 { | 456 { |
461 TYPE_SIZE (t1) = bitsize_zero_node; | 457 TYPE_SIZE (t1) = bitsize_zero_node; |
462 TYPE_SIZE_UNIT (t1) = size_zero_node; | 458 TYPE_SIZE_UNIT (t1) = size_zero_node; |
463 } | 459 } |
464 t1 = c_build_qualified_type (t1, quals); | 460 t1 = c_build_qualified_type (t1, quals); |
465 return build_type_attribute_variant (t1, attributes); | 461 return build_type_attribute_variant (t1, attributes); |
466 } | 462 } |
467 | 463 |
468 case ENUMERAL_TYPE: | 464 case ENUMERAL_TYPE: |
469 case RECORD_TYPE: | 465 case RECORD_TYPE: |
470 case UNION_TYPE: | 466 case UNION_TYPE: |
471 if (attributes != NULL) | 467 if (attributes != NULL) |
472 { | 468 { |
473 /* Try harder not to create a new aggregate type. */ | 469 /* Try harder not to create a new aggregate type. */ |
474 if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes)) | 470 if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes)) |
475 return t1; | 471 return t1; |
476 if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes)) | 472 if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes)) |
477 return t2; | 473 return t2; |
478 } | 474 } |
479 return build_type_attribute_variant (t1, attributes); | 475 return build_type_attribute_variant (t1, attributes); |
480 | 476 |
481 case FUNCTION_TYPE: | 477 case FUNCTION_TYPE: |
482 /* Function types: prefer the one that specified arg types. | 478 /* Function types: prefer the one that specified arg types. |
483 If both do, merge the arg types. Also merge the return types. */ | 479 If both do, merge the arg types. Also merge the return types. */ |
484 { | 480 { |
485 #ifndef noCbC | |
486 int is_code_segment = CbC_IS_CODE_SEGMENT(t1); | |
487 #endif | |
488 tree valtype = composite_type (TREE_TYPE (t1), TREE_TYPE (t2)); | 481 tree valtype = composite_type (TREE_TYPE (t1), TREE_TYPE (t2)); |
489 tree p1 = TYPE_ARG_TYPES (t1); | 482 tree p1 = TYPE_ARG_TYPES (t1); |
490 tree p2 = TYPE_ARG_TYPES (t2); | 483 tree p2 = TYPE_ARG_TYPES (t2); |
491 int len; | 484 int len; |
492 tree newargs, n; | 485 tree newargs, n; |
499 return build_type_attribute_variant (t2, attributes); | 492 return build_type_attribute_variant (t2, attributes); |
500 | 493 |
501 /* Simple way if one arg fails to specify argument types. */ | 494 /* Simple way if one arg fails to specify argument types. */ |
502 if (TYPE_ARG_TYPES (t1) == 0) | 495 if (TYPE_ARG_TYPES (t1) == 0) |
503 { | 496 { |
504 #ifndef noCbC | |
505 if (is_code_segment) t1 = build_code_segment_type (valtype, TYPE_ARG_TYPES (t2)); | |
506 else | |
507 #endif | |
508 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2)); | 497 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2)); |
509 t1 = build_type_attribute_variant (t1, attributes); | 498 t1 = build_type_attribute_variant (t1, attributes); |
510 return qualify_type (t1, t2); | 499 return qualify_type (t1, t2); |
511 } | 500 } |
512 if (TYPE_ARG_TYPES (t2) == 0) | 501 if (TYPE_ARG_TYPES (t2) == 0) |
513 { | 502 { |
514 #ifndef noCbC | |
515 if (is_code_segment) t1 = build_code_segment_type (valtype, TYPE_ARG_TYPES (t1)); | |
516 else | |
517 #endif | |
518 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1)); | 503 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1)); |
519 t1 = build_type_attribute_variant (t1, attributes); | 504 t1 = build_type_attribute_variant (t1, attributes); |
520 return qualify_type (t1, t2); | 505 return qualify_type (t1, t2); |
521 } | 506 } |
522 | 507 |
606 TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2)); | 591 TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2)); |
607 parm_done: ; | 592 parm_done: ; |
608 } | 593 } |
609 | 594 |
610 c_override_global_bindings_to_false = false; | 595 c_override_global_bindings_to_false = false; |
611 | |
612 #ifndef noCbC | |
613 if (is_code_segment) t1 = build_code_segment_type (valtype, newargs); | |
614 else | |
615 #endif | |
616 t1 = build_function_type (valtype, newargs); | 596 t1 = build_function_type (valtype, newargs); |
617 t1 = qualify_type (t1, t2); | 597 t1 = qualify_type (t1, t2); |
618 /* ... falls through ... */ | 598 /* ... falls through ... */ |
619 } | 599 } |
600 | |
620 default: | 601 default: |
621 return build_type_attribute_variant (t1, attributes); | 602 return build_type_attribute_variant (t1, attributes); |
622 } | 603 } |
623 | 604 |
624 } | 605 } |
649 return t2; | 630 return t2; |
650 if (t2 == error_mark_node) | 631 if (t2 == error_mark_node) |
651 return t1; | 632 return t1; |
652 | 633 |
653 gcc_assert (TREE_CODE (t1) == POINTER_TYPE | 634 gcc_assert (TREE_CODE (t1) == POINTER_TYPE |
654 && TREE_CODE (t2) == POINTER_TYPE); | 635 && TREE_CODE (t2) == POINTER_TYPE); |
655 | 636 |
656 /* Merge the attributes. */ | 637 /* Merge the attributes. */ |
657 attributes = targetm.merge_type_attributes (t1, t2); | 638 attributes = targetm.merge_type_attributes (t1, t2); |
658 | 639 |
659 /* Find the composite type of the target types, and combine the | 640 /* Find the composite type of the target types, and combine the |
730 | 711 |
731 code1 = TREE_CODE (t1); | 712 code1 = TREE_CODE (t1); |
732 code2 = TREE_CODE (t2); | 713 code2 = TREE_CODE (t2); |
733 | 714 |
734 gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE | 715 gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE |
735 || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE | 716 || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE |
736 || code1 == INTEGER_TYPE); | 717 || code1 == INTEGER_TYPE); |
737 gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE | 718 gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE |
738 || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE | 719 || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE |
739 || code2 == INTEGER_TYPE); | 720 || code2 == INTEGER_TYPE); |
740 | 721 |
741 /* When one operand is a decimal float type, the other operand cannot be | 722 /* When one operand is a decimal float type, the other operand cannot be |
742 a generic float type or a complex type. We also disallow vector types | 723 a generic float type or a complex type. We also disallow vector types |
743 here. */ | 724 here. */ |
744 if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2)) | 725 if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2)) |
745 && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2))) | 726 && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2))) |
746 { | 727 { |
747 if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE) | 728 if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE) |
748 { | 729 { |
749 error ("can%'t mix operands of decimal float and vector types"); | 730 error ("can%'t mix operands of decimal float and vector types"); |
750 return error_mark_node; | 731 return error_mark_node; |
751 } | 732 } |
752 if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE) | 733 if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE) |
753 { | 734 { |
754 error ("can%'t mix operands of decimal float and complex types"); | 735 error ("can%'t mix operands of decimal float and complex types"); |
755 return error_mark_node; | 736 return error_mark_node; |
756 } | 737 } |
757 if (code1 == REAL_TYPE && code2 == REAL_TYPE) | 738 if (code1 == REAL_TYPE && code2 == REAL_TYPE) |
758 { | 739 { |
759 error ("can%'t mix operands of decimal float and other float types"); | 740 error ("can%'t mix operands of decimal float and other float types"); |
760 return error_mark_node; | 741 return error_mark_node; |
761 } | 742 } |
762 } | 743 } |
763 | 744 |
764 /* If one type is a vector type, return that type. (How the usual | 745 /* If one type is a vector type, return that type. (How the usual |
765 arithmetic conversions apply to the vector types extension is not | 746 arithmetic conversions apply to the vector types extension is not |
766 precisely specified.) */ | 747 precisely specified.) */ |
778 tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1; | 759 tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1; |
779 tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2; | 760 tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2; |
780 tree subtype = c_common_type (subtype1, subtype2); | 761 tree subtype = c_common_type (subtype1, subtype2); |
781 | 762 |
782 if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype) | 763 if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype) |
783 return t1; | 764 return t1; |
784 else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype) | 765 else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype) |
785 return t2; | 766 return t2; |
786 else | 767 else |
787 return build_complex_type (subtype); | 768 return build_complex_type (subtype); |
788 } | 769 } |
789 | 770 |
790 /* If only one is real, use it as the result. */ | 771 /* If only one is real, use it as the result. */ |
791 | 772 |
792 if (code1 == REAL_TYPE && code2 != REAL_TYPE) | 773 if (code1 == REAL_TYPE && code2 != REAL_TYPE) |
799 the decimal floating point type with the greater precision. */ | 780 the decimal floating point type with the greater precision. */ |
800 | 781 |
801 if (code1 == REAL_TYPE && code2 == REAL_TYPE) | 782 if (code1 == REAL_TYPE && code2 == REAL_TYPE) |
802 { | 783 { |
803 if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node | 784 if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node |
804 || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node) | 785 || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node) |
805 return dfloat128_type_node; | 786 return dfloat128_type_node; |
806 else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node | 787 else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node |
807 || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node) | 788 || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node) |
808 return dfloat64_type_node; | 789 return dfloat64_type_node; |
809 else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node | 790 else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node |
810 || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node) | 791 || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node) |
811 return dfloat32_type_node; | 792 return dfloat32_type_node; |
812 } | 793 } |
813 | 794 |
814 /* Deal with fixed-point types. */ | 795 /* Deal with fixed-point types. */ |
815 if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE) | 796 if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE) |
816 { | 797 { |
821 m1 = TYPE_MODE (t1); | 802 m1 = TYPE_MODE (t1); |
822 m2 = TYPE_MODE (t2); | 803 m2 = TYPE_MODE (t2); |
823 | 804 |
824 /* If one input type is saturating, the result type is saturating. */ | 805 /* If one input type is saturating, the result type is saturating. */ |
825 if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2)) | 806 if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2)) |
826 satp = 1; | 807 satp = 1; |
827 | 808 |
828 /* If both fixed-point types are unsigned, the result type is unsigned. | 809 /* If both fixed-point types are unsigned, the result type is unsigned. |
829 When mixing fixed-point and integer types, follow the sign of the | 810 When mixing fixed-point and integer types, follow the sign of the |
830 fixed-point type. | 811 fixed-point type. |
831 Otherwise, the result type is signed. */ | 812 Otherwise, the result type is signed. */ |
832 if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2) | 813 if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2) |
833 && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE) | 814 && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE) |
834 || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE | 815 || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE |
835 && TYPE_UNSIGNED (t1)) | 816 && TYPE_UNSIGNED (t1)) |
836 || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE | 817 || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE |
837 && TYPE_UNSIGNED (t2))) | 818 && TYPE_UNSIGNED (t2))) |
838 unsignedp = 1; | 819 unsignedp = 1; |
839 | 820 |
840 /* The result type is signed. */ | 821 /* The result type is signed. */ |
841 if (unsignedp == 0) | 822 if (unsignedp == 0) |
842 { | 823 { |
843 /* If the input type is unsigned, we need to convert to the | 824 /* If the input type is unsigned, we need to convert to the |
844 signed type. */ | 825 signed type. */ |
845 if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1)) | 826 if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1)) |
846 { | 827 { |
847 enum mode_class mclass = (enum mode_class) 0; | 828 enum mode_class mclass = (enum mode_class) 0; |
848 if (GET_MODE_CLASS (m1) == MODE_UFRACT) | 829 if (GET_MODE_CLASS (m1) == MODE_UFRACT) |
849 mclass = MODE_FRACT; | 830 mclass = MODE_FRACT; |
850 else if (GET_MODE_CLASS (m1) == MODE_UACCUM) | 831 else if (GET_MODE_CLASS (m1) == MODE_UACCUM) |
851 mclass = MODE_ACCUM; | 832 mclass = MODE_ACCUM; |
852 else | 833 else |
853 gcc_unreachable (); | 834 gcc_unreachable (); |
854 m1 = mode_for_size (GET_MODE_PRECISION (m1), mclass, 0); | 835 m1 = mode_for_size (GET_MODE_PRECISION (m1), mclass, 0); |
855 } | 836 } |
856 if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2)) | 837 if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2)) |
857 { | 838 { |
858 enum mode_class mclass = (enum mode_class) 0; | 839 enum mode_class mclass = (enum mode_class) 0; |
859 if (GET_MODE_CLASS (m2) == MODE_UFRACT) | 840 if (GET_MODE_CLASS (m2) == MODE_UFRACT) |
860 mclass = MODE_FRACT; | 841 mclass = MODE_FRACT; |
861 else if (GET_MODE_CLASS (m2) == MODE_UACCUM) | 842 else if (GET_MODE_CLASS (m2) == MODE_UACCUM) |
862 mclass = MODE_ACCUM; | 843 mclass = MODE_ACCUM; |
863 else | 844 else |
864 gcc_unreachable (); | 845 gcc_unreachable (); |
865 m2 = mode_for_size (GET_MODE_PRECISION (m2), mclass, 0); | 846 m2 = mode_for_size (GET_MODE_PRECISION (m2), mclass, 0); |
866 } | 847 } |
867 } | 848 } |
868 | 849 |
869 if (code1 == FIXED_POINT_TYPE) | 850 if (code1 == FIXED_POINT_TYPE) |
870 { | 851 { |
871 fbit1 = GET_MODE_FBIT (m1); | 852 fbit1 = GET_MODE_FBIT (m1); |
872 ibit1 = GET_MODE_IBIT (m1); | 853 ibit1 = GET_MODE_IBIT (m1); |
873 } | 854 } |
874 else | 855 else |
875 { | 856 { |
876 fbit1 = 0; | 857 fbit1 = 0; |
877 /* Signed integers need to subtract one sign bit. */ | 858 /* Signed integers need to subtract one sign bit. */ |
878 ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1)); | 859 ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1)); |
879 } | 860 } |
880 | 861 |
881 if (code2 == FIXED_POINT_TYPE) | 862 if (code2 == FIXED_POINT_TYPE) |
882 { | 863 { |
883 fbit2 = GET_MODE_FBIT (m2); | 864 fbit2 = GET_MODE_FBIT (m2); |
884 ibit2 = GET_MODE_IBIT (m2); | 865 ibit2 = GET_MODE_IBIT (m2); |
885 } | 866 } |
886 else | 867 else |
887 { | 868 { |
888 fbit2 = 0; | 869 fbit2 = 0; |
889 /* Signed integers need to subtract one sign bit. */ | 870 /* Signed integers need to subtract one sign bit. */ |
890 ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2)); | 871 ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2)); |
891 } | 872 } |
892 | 873 |
893 max_ibit = ibit1 >= ibit2 ? ibit1 : ibit2; | 874 max_ibit = ibit1 >= ibit2 ? ibit1 : ibit2; |
894 max_fbit = fbit1 >= fbit2 ? fbit1 : fbit2; | 875 max_fbit = fbit1 >= fbit2 ? fbit1 : fbit2; |
895 return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp, | 876 return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp, |
896 satp); | 877 satp); |
897 } | 878 } |
898 | 879 |
899 /* Both real or both integers; use the one with greater precision. */ | 880 /* Both real or both integers; use the one with greater precision. */ |
900 | 881 |
901 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2)) | 882 if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2)) |
913 | 894 |
914 if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node | 895 if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node |
915 || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node) | 896 || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node) |
916 { | 897 { |
917 if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2)) | 898 if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2)) |
918 return long_long_unsigned_type_node; | 899 return long_long_unsigned_type_node; |
919 else | 900 else |
920 return long_long_integer_type_node; | 901 return long_long_integer_type_node; |
921 } | 902 } |
922 | 903 |
923 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node | 904 if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node |
924 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node) | 905 || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node) |
925 return long_unsigned_type_node; | 906 return long_unsigned_type_node; |
926 | 907 |
927 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node | 908 if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node |
928 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node) | 909 || TYPE_MAIN_VARIANT (t2) == long_integer_type_node) |
929 { | 910 { |
930 /* But preserve unsignedness from the other type, | 911 /* But preserve unsignedness from the other type, |
931 since long cannot hold all the values of an unsigned int. */ | 912 since long cannot hold all the values of an unsigned int. */ |
932 if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2)) | 913 if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2)) |
933 return long_unsigned_type_node; | 914 return long_unsigned_type_node; |
934 else | 915 else |
935 return long_integer_type_node; | 916 return long_integer_type_node; |
936 } | 917 } |
937 | 918 |
938 /* Likewise, prefer long double to double even if same size. */ | 919 /* Likewise, prefer long double to double even if same size. */ |
939 if (TYPE_MAIN_VARIANT (t1) == long_double_type_node | 920 if (TYPE_MAIN_VARIANT (t1) == long_double_type_node |
940 || TYPE_MAIN_VARIANT (t2) == long_double_type_node) | 921 || TYPE_MAIN_VARIANT (t2) == long_double_type_node) |
1107 switch (TREE_CODE (t1)) | 1088 switch (TREE_CODE (t1)) |
1108 { | 1089 { |
1109 case POINTER_TYPE: | 1090 case POINTER_TYPE: |
1110 /* Do not remove mode or aliasing information. */ | 1091 /* Do not remove mode or aliasing information. */ |
1111 if (TYPE_MODE (t1) != TYPE_MODE (t2) | 1092 if (TYPE_MODE (t1) != TYPE_MODE (t2) |
1112 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) | 1093 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) |
1113 break; | 1094 break; |
1114 val = (TREE_TYPE (t1) == TREE_TYPE (t2) | 1095 val = (TREE_TYPE (t1) == TREE_TYPE (t2) |
1115 ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), | 1096 ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), |
1116 enum_and_int_p, different_types_p)); | 1097 enum_and_int_p, different_types_p)); |
1117 break; | 1098 break; |
1118 | 1099 |
1234 if (val == 2) | 1215 if (val == 2) |
1235 pedwarn (location, OPT_pedantic, "types are not quite compatible"); | 1216 pedwarn (location, OPT_pedantic, "types are not quite compatible"); |
1236 | 1217 |
1237 if (val == 1 && enum_and_int_p && warn_cxx_compat) | 1218 if (val == 1 && enum_and_int_p && warn_cxx_compat) |
1238 warning_at (location, OPT_Wc___compat, | 1219 warning_at (location, OPT_Wc___compat, |
1239 "pointer target types incompatible in C++"); | 1220 "pointer target types incompatible in C++"); |
1240 | 1221 |
1241 return val; | 1222 return val; |
1242 } | 1223 } |
1243 | 1224 |
1244 /* Subroutines of `comptypes'. */ | 1225 /* Subroutines of `comptypes'. */ |
1252 { | 1233 { |
1253 while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL) | 1234 while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL) |
1254 switch (TREE_CODE_CLASS (TREE_CODE (t1))) | 1235 switch (TREE_CODE_CLASS (TREE_CODE (t1))) |
1255 { | 1236 { |
1256 case tcc_declaration: | 1237 case tcc_declaration: |
1257 t1 = DECL_CONTEXT (t1); break; | 1238 t1 = DECL_CONTEXT (t1); break; |
1258 case tcc_type: | 1239 case tcc_type: |
1259 t1 = TYPE_CONTEXT (t1); break; | 1240 t1 = TYPE_CONTEXT (t1); break; |
1260 case tcc_exceptional: | 1241 case tcc_exceptional: |
1261 t1 = BLOCK_SUPERCONTEXT (t1); break; /* assume block */ | 1242 t1 = BLOCK_SUPERCONTEXT (t1); break; /* assume block */ |
1262 default: gcc_unreachable (); | 1243 default: gcc_unreachable (); |
1263 } | 1244 } |
1264 | 1245 |
1265 while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL) | 1246 while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL) |
1266 switch (TREE_CODE_CLASS (TREE_CODE (t2))) | 1247 switch (TREE_CODE_CLASS (TREE_CODE (t2))) |
1267 { | 1248 { |
1268 case tcc_declaration: | 1249 case tcc_declaration: |
1269 t2 = DECL_CONTEXT (t2); break; | 1250 t2 = DECL_CONTEXT (t2); break; |
1270 case tcc_type: | 1251 case tcc_type: |
1271 t2 = TYPE_CONTEXT (t2); break; | 1252 t2 = TYPE_CONTEXT (t2); break; |
1272 case tcc_exceptional: | 1253 case tcc_exceptional: |
1273 t2 = BLOCK_SUPERCONTEXT (t2); break; /* assume block */ | 1254 t2 = BLOCK_SUPERCONTEXT (t2); break; /* assume block */ |
1274 default: gcc_unreachable (); | 1255 default: gcc_unreachable (); |
1275 } | 1256 } |
1276 | 1257 |
1277 return t1 == t2; | 1258 return t1 == t2; |
1278 } | 1259 } |
1312 { | 1293 { |
1313 const struct tagged_tu_seen_cache *tu = tagged_tu_seen_base; | 1294 const struct tagged_tu_seen_cache *tu = tagged_tu_seen_base; |
1314 while (tu != tu_til) | 1295 while (tu != tu_til) |
1315 { | 1296 { |
1316 const struct tagged_tu_seen_cache *const tu1 | 1297 const struct tagged_tu_seen_cache *const tu1 |
1317 = (const struct tagged_tu_seen_cache *) tu; | 1298 = (const struct tagged_tu_seen_cache *) tu; |
1318 tu = tu1->next; | 1299 tu = tu1->next; |
1319 free (CONST_CAST (struct tagged_tu_seen_cache *, tu1)); | 1300 free (CONST_CAST (struct tagged_tu_seen_cache *, tu1)); |
1320 } | 1301 } |
1321 tagged_tu_seen_base = tu_til; | 1302 tagged_tu_seen_base = tu_til; |
1322 } | 1303 } |
1340 to go look at the original type. It may even be a typedef of a | 1321 to go look at the original type. It may even be a typedef of a |
1341 typedef... | 1322 typedef... |
1342 In the case of compiler-created builtin structs the TYPE_DECL | 1323 In the case of compiler-created builtin structs the TYPE_DECL |
1343 may be a dummy, with no DECL_ORIGINAL_TYPE. Don't fault. */ | 1324 may be a dummy, with no DECL_ORIGINAL_TYPE. Don't fault. */ |
1344 while (TYPE_NAME (t1) | 1325 while (TYPE_NAME (t1) |
1345 && TREE_CODE (TYPE_NAME (t1)) == TYPE_DECL | 1326 && TREE_CODE (TYPE_NAME (t1)) == TYPE_DECL |
1346 && DECL_ORIGINAL_TYPE (TYPE_NAME (t1))) | 1327 && DECL_ORIGINAL_TYPE (TYPE_NAME (t1))) |
1347 t1 = DECL_ORIGINAL_TYPE (TYPE_NAME (t1)); | 1328 t1 = DECL_ORIGINAL_TYPE (TYPE_NAME (t1)); |
1348 | 1329 |
1349 while (TYPE_NAME (t2) | 1330 while (TYPE_NAME (t2) |
1350 && TREE_CODE (TYPE_NAME (t2)) == TYPE_DECL | 1331 && TREE_CODE (TYPE_NAME (t2)) == TYPE_DECL |
1351 && DECL_ORIGINAL_TYPE (TYPE_NAME (t2))) | 1332 && DECL_ORIGINAL_TYPE (TYPE_NAME (t2))) |
1352 t2 = DECL_ORIGINAL_TYPE (TYPE_NAME (t2)); | 1333 t2 = DECL_ORIGINAL_TYPE (TYPE_NAME (t2)); |
1353 | 1334 |
1354 /* C90 didn't have the requirement that the two tags be the same. */ | 1335 /* C90 didn't have the requirement that the two tags be the same. */ |
1355 if (flag_isoc99 && TYPE_NAME (t1) != TYPE_NAME (t2)) | 1336 if (flag_isoc99 && TYPE_NAME (t1) != TYPE_NAME (t2)) |
1356 return 0; | 1337 return 0; |
1364 | 1345 |
1365 { | 1346 { |
1366 const struct tagged_tu_seen_cache * tts_i; | 1347 const struct tagged_tu_seen_cache * tts_i; |
1367 for (tts_i = tagged_tu_seen_base; tts_i != NULL; tts_i = tts_i->next) | 1348 for (tts_i = tagged_tu_seen_base; tts_i != NULL; tts_i = tts_i->next) |
1368 if (tts_i->t1 == t1 && tts_i->t2 == t2) | 1349 if (tts_i->t1 == t1 && tts_i->t2 == t2) |
1369 return tts_i->val; | 1350 return tts_i->val; |
1370 } | 1351 } |
1371 | 1352 |
1372 switch (TREE_CODE (t1)) | 1353 switch (TREE_CODE (t1)) |
1373 { | 1354 { |
1374 case ENUMERAL_TYPE: | 1355 case ENUMERAL_TYPE: |
1375 { | 1356 { |
1376 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); | 1357 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); |
1377 /* Speed up the case where the type values are in the same order. */ | 1358 /* Speed up the case where the type values are in the same order. */ |
1378 tree tv1 = TYPE_VALUES (t1); | 1359 tree tv1 = TYPE_VALUES (t1); |
1379 tree tv2 = TYPE_VALUES (t2); | 1360 tree tv2 = TYPE_VALUES (t2); |
1380 | 1361 |
1381 if (tv1 == tv2) | 1362 if (tv1 == tv2) |
1382 { | 1363 { |
1383 return 1; | 1364 return 1; |
1384 } | 1365 } |
1385 | 1366 |
1386 for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2)) | 1367 for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2)) |
1387 { | 1368 { |
1388 if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2)) | 1369 if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2)) |
1389 break; | 1370 break; |
1390 if (simple_cst_equal (TREE_VALUE (tv1), TREE_VALUE (tv2)) != 1) | 1371 if (simple_cst_equal (TREE_VALUE (tv1), TREE_VALUE (tv2)) != 1) |
1391 { | 1372 { |
1392 tu->val = 0; | 1373 tu->val = 0; |
1393 return 0; | 1374 return 0; |
1394 } | 1375 } |
1395 } | 1376 } |
1396 | 1377 |
1397 if (tv1 == NULL_TREE && tv2 == NULL_TREE) | 1378 if (tv1 == NULL_TREE && tv2 == NULL_TREE) |
1398 { | 1379 { |
1399 return 1; | 1380 return 1; |
1400 } | 1381 } |
1401 if (tv1 == NULL_TREE || tv2 == NULL_TREE) | 1382 if (tv1 == NULL_TREE || tv2 == NULL_TREE) |
1402 { | 1383 { |
1403 tu->val = 0; | 1384 tu->val = 0; |
1404 return 0; | 1385 return 0; |
1405 } | 1386 } |
1406 | 1387 |
1407 if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2))) | 1388 if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2))) |
1408 { | 1389 { |
1409 tu->val = 0; | 1390 tu->val = 0; |
1410 return 0; | 1391 return 0; |
1411 } | 1392 } |
1412 | 1393 |
1413 for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1)) | 1394 for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1)) |
1414 { | 1395 { |
1415 s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2)); | 1396 s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2)); |
1416 if (s2 == NULL | 1397 if (s2 == NULL |
1417 || simple_cst_equal (TREE_VALUE (s1), TREE_VALUE (s2)) != 1) | 1398 || simple_cst_equal (TREE_VALUE (s1), TREE_VALUE (s2)) != 1) |
1418 { | 1399 { |
1419 tu->val = 0; | 1400 tu->val = 0; |
1420 return 0; | 1401 return 0; |
1421 } | 1402 } |
1422 } | 1403 } |
1423 return 1; | 1404 return 1; |
1424 } | 1405 } |
1425 | 1406 |
1426 case UNION_TYPE: | 1407 case UNION_TYPE: |
1427 { | 1408 { |
1428 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); | 1409 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); |
1524 enum_and_int_p, different_types_p); | 1505 enum_and_int_p, different_types_p); |
1525 if (result == 0) | 1506 if (result == 0) |
1526 break; | 1507 break; |
1527 if (result == 2) | 1508 if (result == 2) |
1528 needs_warning = true; | 1509 needs_warning = true; |
1510 | |
1529 if (TREE_CODE (s1) == FIELD_DECL | 1511 if (TREE_CODE (s1) == FIELD_DECL |
1530 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), | 1512 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), |
1531 DECL_FIELD_BIT_OFFSET (s2)) != 1) | 1513 DECL_FIELD_BIT_OFFSET (s2)) != 1) |
1532 break; | 1514 break; |
1533 } | 1515 } |
1568 the function is noreturn. */ | 1550 the function is noreturn. */ |
1569 if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2)) | 1551 if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2)) |
1570 pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>"); | 1552 pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>"); |
1571 if (TYPE_VOLATILE (ret1)) | 1553 if (TYPE_VOLATILE (ret1)) |
1572 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1), | 1554 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1), |
1573 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE); | 1555 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE); |
1574 if (TYPE_VOLATILE (ret2)) | 1556 if (TYPE_VOLATILE (ret2)) |
1575 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2), | 1557 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2), |
1576 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE); | 1558 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE); |
1577 val = comptypes_internal (ret1, ret2, enum_and_int_p, different_types_p); | 1559 val = comptypes_internal (ret1, ret2, enum_and_int_p, different_types_p); |
1578 if (val == 0) | 1560 if (val == 0) |
1589 whose argument types don't need default promotions. */ | 1571 whose argument types don't need default promotions. */ |
1590 | 1572 |
1591 if (args1 == 0) | 1573 if (args1 == 0) |
1592 { | 1574 { |
1593 if (!self_promoting_args_p (args2)) | 1575 if (!self_promoting_args_p (args2)) |
1594 return 0; | 1576 return 0; |
1595 /* If one of these types comes from a non-prototype fn definition, | 1577 /* If one of these types comes from a non-prototype fn definition, |
1596 compare that with the other type's arglist. | 1578 compare that with the other type's arglist. |
1597 If they don't match, ask for a warning (but no error). */ | 1579 If they don't match, ask for a warning (but no error). */ |
1598 if (TYPE_ACTUAL_ARG_TYPES (f1) | 1580 if (TYPE_ACTUAL_ARG_TYPES (f1) |
1599 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), | 1581 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), |
1600 enum_and_int_p, different_types_p)) | 1582 enum_and_int_p, different_types_p)) |
1601 val = 2; | 1583 val = 2; |
1602 return val; | 1584 return val; |
1603 } | 1585 } |
1604 if (args2 == 0) | 1586 if (args2 == 0) |
1605 { | 1587 { |
1606 if (!self_promoting_args_p (args1)) | 1588 if (!self_promoting_args_p (args1)) |
1607 return 0; | 1589 return 0; |
1608 if (TYPE_ACTUAL_ARG_TYPES (f2) | 1590 if (TYPE_ACTUAL_ARG_TYPES (f2) |
1609 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), | 1591 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), |
1610 enum_and_int_p, different_types_p)) | 1592 enum_and_int_p, different_types_p)) |
1611 val = 2; | 1593 val = 2; |
1612 return val; | 1594 return val; |
1633 | 1615 |
1634 while (1) | 1616 while (1) |
1635 { | 1617 { |
1636 tree a1, mv1, a2, mv2; | 1618 tree a1, mv1, a2, mv2; |
1637 if (args1 == 0 && args2 == 0) | 1619 if (args1 == 0 && args2 == 0) |
1638 return val; | 1620 return val; |
1639 /* If one list is shorter than the other, | 1621 /* If one list is shorter than the other, |
1640 they fail to match. */ | 1622 they fail to match. */ |
1641 if (args1 == 0 || args2 == 0) | 1623 if (args1 == 0 || args2 == 0) |
1642 return 0; | 1624 return 0; |
1643 mv1 = a1 = TREE_VALUE (args1); | 1625 mv1 = a1 = TREE_VALUE (args1); |
1644 mv2 = a2 = TREE_VALUE (args2); | 1626 mv2 = a2 = TREE_VALUE (args2); |
1645 if (mv1 && mv1 != error_mark_node && TREE_CODE (mv1) != ARRAY_TYPE) | 1627 if (mv1 && mv1 != error_mark_node && TREE_CODE (mv1) != ARRAY_TYPE) |
1646 mv1 = TYPE_MAIN_VARIANT (mv1); | 1628 mv1 = TYPE_MAIN_VARIANT (mv1); |
1647 if (mv2 && mv2 != error_mark_node && TREE_CODE (mv2) != ARRAY_TYPE) | 1629 if (mv2 && mv2 != error_mark_node && TREE_CODE (mv2) != ARRAY_TYPE) |
1648 mv2 = TYPE_MAIN_VARIANT (mv2); | 1630 mv2 = TYPE_MAIN_VARIANT (mv2); |
1649 /* A null pointer instead of a type | 1631 /* A null pointer instead of a type |
1650 means there is supposed to be an argument | 1632 means there is supposed to be an argument |
1651 but nothing is specified about what type it has. | 1633 but nothing is specified about what type it has. |
1652 So match anything that self-promotes. */ | 1634 So match anything that self-promotes. */ |
1653 if (different_types_p != NULL | 1635 if (different_types_p != NULL |
1654 && (a1 == 0) != (a2 == 0)) | 1636 && (a1 == 0) != (a2 == 0)) |
1655 *different_types_p = true; | 1637 *different_types_p = true; |
1656 if (a1 == 0) | 1638 if (a1 == 0) |
1657 { | 1639 { |
1658 if (c_type_promotes_to (a2) != a2) | 1640 if (c_type_promotes_to (a2) != a2) |
1659 return 0; | 1641 return 0; |
1660 } | 1642 } |
1661 else if (a2 == 0) | 1643 else if (a2 == 0) |
1662 { | 1644 { |
1663 if (c_type_promotes_to (a1) != a1) | 1645 if (c_type_promotes_to (a1) != a1) |
1664 return 0; | 1646 return 0; |
1665 } | 1647 } |
1666 /* If one of the lists has an error marker, ignore this arg. */ | 1648 /* If one of the lists has an error marker, ignore this arg. */ |
1667 else if (TREE_CODE (a1) == ERROR_MARK | 1649 else if (TREE_CODE (a1) == ERROR_MARK |
1668 || TREE_CODE (a2) == ERROR_MARK) | 1650 || TREE_CODE (a2) == ERROR_MARK) |
1669 ; | 1651 ; |
1670 else if (!(newval = comptypes_internal (mv1, mv2, enum_and_int_p, | 1652 else if (!(newval = comptypes_internal (mv1, mv2, enum_and_int_p, |
1722 return 0; | 1704 return 0; |
1723 } | 1705 } |
1724 | 1706 |
1725 /* comptypes said ok, but record if it said to warn. */ | 1707 /* comptypes said ok, but record if it said to warn. */ |
1726 if (newval > val) | 1708 if (newval > val) |
1727 val = newval; | 1709 val = newval; |
1728 | 1710 |
1729 args1 = TREE_CHAIN (args1); | 1711 args1 = TREE_CHAIN (args1); |
1730 args2 = TREE_CHAIN (args2); | 1712 args2 = TREE_CHAIN (args2); |
1731 } | 1713 } |
1732 } | 1714 } |
1747 return size_one_node; | 1729 return size_one_node; |
1748 } | 1730 } |
1749 | 1731 |
1750 /* Convert in case a char is more than one unit. */ | 1732 /* Convert in case a char is more than one unit. */ |
1751 return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type), | 1733 return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type), |
1752 size_int (TYPE_PRECISION (char_type_node) | 1734 size_int (TYPE_PRECISION (char_type_node) |
1753 / BITS_PER_UNIT)); | 1735 / BITS_PER_UNIT)); |
1754 } | 1736 } |
1755 | 1737 |
1756 /* Return either DECL or its known constant value (if it has one). */ | 1738 /* Return either DECL or its known constant value (if it has one). */ |
1757 | 1739 |
1758 tree | 1740 tree |
1759 decl_constant_value (tree decl) | 1741 decl_constant_value (tree decl) |
1760 { | 1742 { |
1761 if (/* Don't change a variable array bound or initial value to a constant | 1743 if (/* Don't change a variable array bound or initial value to a constant |
1762 in a place where a variable is invalid. Note that DECL_INITIAL | 1744 in a place where a variable is invalid. Note that DECL_INITIAL |
1763 isn't valid for a PARM_DECL. */ | 1745 isn't valid for a PARM_DECL. */ |
1764 current_function_decl != 0 | 1746 current_function_decl != 0 |
1765 && TREE_CODE (decl) != PARM_DECL | 1747 && TREE_CODE (decl) != PARM_DECL |
1766 && !TREE_THIS_VOLATILE (decl) | 1748 && !TREE_THIS_VOLATILE (decl) |
1767 && TREE_READONLY (decl) | 1749 && TREE_READONLY (decl) |
1768 && DECL_INITIAL (decl) != 0 | 1750 && DECL_INITIAL (decl) != 0 |
1769 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK | 1751 && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK |
1770 /* This is invalid if initial value is not constant. | 1752 /* This is invalid if initial value is not constant. |
1771 If it has either a function call, a memory reference, | 1753 If it has either a function call, a memory reference, |
1772 or a variable, then re-evaluating it could give different results. */ | 1754 or a variable, then re-evaluating it could give different results. */ |
1773 && TREE_CONSTANT (DECL_INITIAL (decl)) | 1755 && TREE_CONSTANT (DECL_INITIAL (decl)) |
1774 /* Check for cases where this is sub-optimal, even though valid. */ | 1756 /* Check for cases where this is sub-optimal, even though valid. */ |
1775 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR) | 1757 && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR) |
1776 return DECL_INITIAL (decl); | 1758 return DECL_INITIAL (decl); |
1777 return decl; | 1759 return decl; |
1864 | 1846 |
1865 switch (code) | 1847 switch (code) |
1866 { | 1848 { |
1867 case ARRAY_TYPE: | 1849 case ARRAY_TYPE: |
1868 { | 1850 { |
1869 bool not_lvalue = false; | 1851 bool not_lvalue = false; |
1870 bool lvalue_array_p; | 1852 bool lvalue_array_p; |
1871 | 1853 |
1872 while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR | 1854 while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR |
1873 || CONVERT_EXPR_P (exp.value)) | 1855 || CONVERT_EXPR_P (exp.value)) |
1874 && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type) | 1856 && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type) |
1875 { | 1857 { |
1876 if (TREE_CODE (exp.value) == NON_LVALUE_EXPR) | 1858 if (TREE_CODE (exp.value) == NON_LVALUE_EXPR) |
1877 not_lvalue = true; | 1859 not_lvalue = true; |
1878 exp.value = TREE_OPERAND (exp.value, 0); | 1860 exp.value = TREE_OPERAND (exp.value, 0); |
1879 } | 1861 } |
1880 | 1862 |
1881 if (TREE_NO_WARNING (orig_exp)) | 1863 if (TREE_NO_WARNING (orig_exp)) |
1882 TREE_NO_WARNING (exp.value) = 1; | 1864 TREE_NO_WARNING (exp.value) = 1; |
1883 | 1865 |
1884 lvalue_array_p = !not_lvalue && lvalue_p (exp.value); | 1866 lvalue_array_p = !not_lvalue && lvalue_p (exp.value); |
1885 if (!flag_isoc99 && !lvalue_array_p) | 1867 if (!flag_isoc99 && !lvalue_array_p) |
1886 { | 1868 { |
1887 /* Before C99, non-lvalue arrays do not decay to pointers. | 1869 /* Before C99, non-lvalue arrays do not decay to pointers. |
1888 Normally, using such an array would be invalid; but it can | 1870 Normally, using such an array would be invalid; but it can |
1889 be used correctly inside sizeof or as a statement expression. | 1871 be used correctly inside sizeof or as a statement expression. |
1890 Thus, do not give an error here; an error will result later. */ | 1872 Thus, do not give an error here; an error will result later. */ |
1891 return exp; | 1873 return exp; |
1892 } | 1874 } |
1893 | 1875 |
1894 exp.value = array_to_pointer_conversion (loc, exp.value); | 1876 exp.value = array_to_pointer_conversion (loc, exp.value); |
1895 } | 1877 } |
1896 break; | 1878 break; |
1897 case FUNCTION_TYPE: | 1879 case FUNCTION_TYPE: |
1898 exp.value = function_to_pointer_conversion (loc, exp.value); | 1880 exp.value = function_to_pointer_conversion (loc, exp.value); |
1899 break; | 1881 break; |
1925 /* Normally convert enums to int, | 1907 /* Normally convert enums to int, |
1926 but convert wide enums to something wider. */ | 1908 but convert wide enums to something wider. */ |
1927 if (code == ENUMERAL_TYPE) | 1909 if (code == ENUMERAL_TYPE) |
1928 { | 1910 { |
1929 type = c_common_type_for_size (MAX (TYPE_PRECISION (type), | 1911 type = c_common_type_for_size (MAX (TYPE_PRECISION (type), |
1930 TYPE_PRECISION (integer_type_node)), | 1912 TYPE_PRECISION (integer_type_node)), |
1931 ((TYPE_PRECISION (type) | 1913 ((TYPE_PRECISION (type) |
1932 >= TYPE_PRECISION (integer_type_node)) | 1914 >= TYPE_PRECISION (integer_type_node)) |
1933 && TYPE_UNSIGNED (type))); | 1915 && TYPE_UNSIGNED (type))); |
1934 | 1916 |
1935 return convert (type, exp); | 1917 return convert (type, exp); |
1936 } | 1918 } |
1937 | 1919 |
1938 /* ??? This should no longer be needed now bit-fields have their | 1920 /* ??? This should no longer be needed now bit-fields have their |
1939 proper types. */ | 1921 proper types. */ |
1940 if (TREE_CODE (exp) == COMPONENT_REF | 1922 if (TREE_CODE (exp) == COMPONENT_REF |
1941 && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)) | 1923 && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)) |
1942 /* If it's thinner than an int, promote it like a | 1924 /* If it's thinner than an int, promote it like a |
1943 c_promoting_integer_type_p, otherwise leave it alone. */ | 1925 c_promoting_integer_type_p, otherwise leave it alone. */ |
1944 && 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)), | 1926 && 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)), |
1945 TYPE_PRECISION (integer_type_node))) | 1927 TYPE_PRECISION (integer_type_node))) |
1946 return convert (integer_type_node, exp); | 1928 return convert (integer_type_node, exp); |
1947 | 1929 |
1948 if (c_promoting_integer_type_p (type)) | 1930 if (c_promoting_integer_type_p (type)) |
1949 { | 1931 { |
1950 /* Preserve unsignedness if not really getting any wider. */ | 1932 /* Preserve unsignedness if not really getting any wider. */ |
1951 if (TYPE_UNSIGNED (type) | 1933 if (TYPE_UNSIGNED (type) |
1952 && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) | 1934 && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) |
1953 return convert (unsigned_type_node, exp); | 1935 return convert (unsigned_type_node, exp); |
1954 | 1936 |
1955 return convert (integer_type_node, exp); | 1937 return convert (integer_type_node, exp); |
1956 } | 1938 } |
1957 | 1939 |
1958 return exp; | 1940 return exp; |
2083 else | 2065 else |
2084 top = bot + half; | 2066 top = bot + half; |
2085 } | 2067 } |
2086 | 2068 |
2087 if (DECL_NAME (field_array[bot]) == component) | 2069 if (DECL_NAME (field_array[bot]) == component) |
2088 field = field_array[bot]; | 2070 field = field_array[bot]; |
2089 else if (DECL_NAME (field) != component) | 2071 else if (DECL_NAME (field) != component) |
2090 return NULL_TREE; | 2072 return NULL_TREE; |
2091 } | 2073 } |
2092 else | 2074 else |
2093 { | 2075 { |
2094 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) | 2076 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
2095 { | 2077 { |
2116 if (DECL_NAME (field) == component) | 2098 if (DECL_NAME (field) == component) |
2117 break; | 2099 break; |
2118 } | 2100 } |
2119 | 2101 |
2120 if (field == NULL_TREE) | 2102 if (field == NULL_TREE) |
2121 return NULL_TREE; | 2103 return NULL_TREE; |
2122 } | 2104 } |
2123 | 2105 |
2124 return tree_cons (NULL_TREE, field, NULL_TREE); | 2106 return tree_cons (NULL_TREE, field, NULL_TREE); |
2125 } | 2107 } |
2126 | 2108 |
2148 /* See if there is a field or component with name COMPONENT. */ | 2130 /* See if there is a field or component with name COMPONENT. */ |
2149 | 2131 |
2150 if (code == RECORD_TYPE || code == UNION_TYPE) | 2132 if (code == RECORD_TYPE || code == UNION_TYPE) |
2151 { | 2133 { |
2152 if (!COMPLETE_TYPE_P (type)) | 2134 if (!COMPLETE_TYPE_P (type)) |
2153 { | 2135 { |
2154 c_incomplete_type_error (NULL_TREE, type); | 2136 c_incomplete_type_error (NULL_TREE, type); |
2155 return error_mark_node; | 2137 return error_mark_node; |
2156 } | 2138 } |
2157 | 2139 |
2158 field = lookup_field (type, component); | 2140 field = lookup_field (type, component); |
2159 | 2141 |
2160 if (!field) | 2142 if (!field) |
2161 { | 2143 { |
2162 error_at (loc, "%qT has no member named %qE", type, component); | 2144 error_at (loc, "%qT has no member named %qE", type, component); |
2163 return error_mark_node; | 2145 return error_mark_node; |
2164 } | 2146 } |
2165 | 2147 |
2166 /* Chain the COMPONENT_REFs if necessary down to the FIELD. | 2148 /* Chain the COMPONENT_REFs if necessary down to the FIELD. |
2167 This might be better solved in future the way the C++ front | 2149 This might be better solved in future the way the C++ front |
2168 end does it - by giving the anonymous entities each a | 2150 end does it - by giving the anonymous entities each a |
2169 separate name and type, and then have build_component_ref | 2151 separate name and type, and then have build_component_ref |
2170 recursively call itself. We can't do that here. */ | 2152 recursively call itself. We can't do that here. */ |
2171 do | 2153 do |
2172 { | 2154 { |
2173 tree subdatum = TREE_VALUE (field); | 2155 tree subdatum = TREE_VALUE (field); |
2174 int quals; | 2156 int quals; |
2175 tree subtype; | 2157 tree subtype; |
2176 bool use_datum_quals; | 2158 bool use_datum_quals; |
2177 | 2159 |
2178 if (TREE_TYPE (subdatum) == error_mark_node) | 2160 if (TREE_TYPE (subdatum) == error_mark_node) |
2179 return error_mark_node; | 2161 return error_mark_node; |
2180 | 2162 |
2181 /* If this is an rvalue, it does not have qualifiers in C | 2163 /* If this is an rvalue, it does not have qualifiers in C |
2182 standard terms and we must avoid propagating such | 2164 standard terms and we must avoid propagating such |
2183 qualifiers down to a non-lvalue array that is then | 2165 qualifiers down to a non-lvalue array that is then |
2184 converted to a pointer. */ | 2166 converted to a pointer. */ |
2185 use_datum_quals = (datum_lvalue | 2167 use_datum_quals = (datum_lvalue |
2186 || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE); | 2168 || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE); |
2187 | 2169 |
2188 quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum))); | 2170 quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum))); |
2189 if (use_datum_quals) | 2171 if (use_datum_quals) |
2190 quals |= TYPE_QUALS (TREE_TYPE (datum)); | 2172 quals |= TYPE_QUALS (TREE_TYPE (datum)); |
2191 subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals); | 2173 subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals); |
2192 | 2174 |
2193 ref = build3 (COMPONENT_REF, subtype, datum, subdatum, | 2175 ref = build3 (COMPONENT_REF, subtype, datum, subdatum, |
2194 NULL_TREE); | 2176 NULL_TREE); |
2195 SET_EXPR_LOCATION (ref, loc); | 2177 SET_EXPR_LOCATION (ref, loc); |
2196 if (TREE_READONLY (subdatum) | 2178 if (TREE_READONLY (subdatum) |
2197 || (use_datum_quals && TREE_READONLY (datum))) | 2179 || (use_datum_quals && TREE_READONLY (datum))) |
2198 TREE_READONLY (ref) = 1; | 2180 TREE_READONLY (ref) = 1; |
2199 if (TREE_THIS_VOLATILE (subdatum) | 2181 if (TREE_THIS_VOLATILE (subdatum) |
2200 || (use_datum_quals && TREE_THIS_VOLATILE (datum))) | 2182 || (use_datum_quals && TREE_THIS_VOLATILE (datum))) |
2201 TREE_THIS_VOLATILE (ref) = 1; | 2183 TREE_THIS_VOLATILE (ref) = 1; |
2202 | 2184 |
2203 if (TREE_DEPRECATED (subdatum)) | 2185 if (TREE_DEPRECATED (subdatum)) |
2204 warn_deprecated_use (subdatum, NULL_TREE); | 2186 warn_deprecated_use (subdatum, NULL_TREE); |
2205 | 2187 |
2206 datum = ref; | 2188 datum = ref; |
2207 | 2189 |
2208 field = TREE_CHAIN (field); | 2190 field = TREE_CHAIN (field); |
2209 } | 2191 } |
2210 while (field); | 2192 while (field); |
2211 | 2193 |
2212 return ref; | 2194 return ref; |
2213 } | 2195 } |
2214 else if (code != ERROR_MARK) | 2196 else if (code != ERROR_MARK) |
2215 error_at (loc, | 2197 error_at (loc, |
2216 "request for member %qE in something not a structure or union", | 2198 "request for member %qE in something not a structure or union", |
2217 component); | 2199 component); |
2218 | 2200 |
2219 return error_mark_node; | 2201 return error_mark_node; |
2220 } | 2202 } |
2221 | 2203 |
2222 /* Given an expression PTR for a pointer, return an expression | 2204 /* Given an expression PTR for a pointer, return an expression |
2234 | 2216 |
2235 if (TREE_CODE (type) == POINTER_TYPE) | 2217 if (TREE_CODE (type) == POINTER_TYPE) |
2236 { | 2218 { |
2237 if (CONVERT_EXPR_P (pointer) | 2219 if (CONVERT_EXPR_P (pointer) |
2238 || TREE_CODE (pointer) == VIEW_CONVERT_EXPR) | 2220 || TREE_CODE (pointer) == VIEW_CONVERT_EXPR) |
2239 { | 2221 { |
2240 /* If a warning is issued, mark it to avoid duplicates from | 2222 /* If a warning is issued, mark it to avoid duplicates from |
2241 the backend. This only needs to be done at | 2223 the backend. This only needs to be done at |
2242 warn_strict_aliasing > 2. */ | 2224 warn_strict_aliasing > 2. */ |
2243 if (warn_strict_aliasing > 2) | 2225 if (warn_strict_aliasing > 2) |
2244 if (strict_aliasing_warning (TREE_TYPE (TREE_OPERAND (pointer, 0)), | 2226 if (strict_aliasing_warning (TREE_TYPE (TREE_OPERAND (pointer, 0)), |
2245 type, TREE_OPERAND (pointer, 0))) | 2227 type, TREE_OPERAND (pointer, 0))) |
2246 TREE_NO_WARNING (pointer) = 1; | 2228 TREE_NO_WARNING (pointer) = 1; |
2247 } | 2229 } |
2248 | 2230 |
2249 if (TREE_CODE (pointer) == ADDR_EXPR | 2231 if (TREE_CODE (pointer) == ADDR_EXPR |
2250 && (TREE_TYPE (TREE_OPERAND (pointer, 0)) | 2232 && (TREE_TYPE (TREE_OPERAND (pointer, 0)) |
2251 == TREE_TYPE (type))) | 2233 == TREE_TYPE (type))) |
2252 { | 2234 { |
2253 ref = TREE_OPERAND (pointer, 0); | 2235 ref = TREE_OPERAND (pointer, 0); |
2254 protected_set_expr_location (ref, loc); | 2236 protected_set_expr_location (ref, loc); |
2255 return ref; | 2237 return ref; |
2256 } | 2238 } |
2257 else | 2239 else |
2258 { | 2240 { |
2259 tree t = TREE_TYPE (type); | 2241 tree t = TREE_TYPE (type); |
2260 | 2242 |
2261 ref = build1 (INDIRECT_REF, t, pointer); | 2243 ref = build1 (INDIRECT_REF, t, pointer); |
2262 | 2244 |
2263 if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE) | 2245 if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE) |
2264 { | 2246 { |
2265 error_at (loc, "dereferencing pointer to incomplete type"); | 2247 error_at (loc, "dereferencing pointer to incomplete type"); |
2266 return error_mark_node; | 2248 return error_mark_node; |
2267 } | 2249 } |
2268 if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0) | 2250 if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0) |
2269 warning_at (loc, 0, "dereferencing %<void *%> pointer"); | 2251 warning_at (loc, 0, "dereferencing %<void *%> pointer"); |
2270 | 2252 |
2271 /* We *must* set TREE_READONLY when dereferencing a pointer to const, | 2253 /* We *must* set TREE_READONLY when dereferencing a pointer to const, |
2272 so that we get the proper error message if the result is used | 2254 so that we get the proper error message if the result is used |
2273 to assign to. Also, &* is supposed to be a no-op. | 2255 to assign to. Also, &* is supposed to be a no-op. |
2274 And ANSI C seems to specify that the type of the result | 2256 And ANSI C seems to specify that the type of the result |
2275 should be the const type. */ | 2257 should be the const type. */ |
2276 /* A de-reference of a pointer to const is not a const. It is valid | 2258 /* A de-reference of a pointer to const is not a const. It is valid |
2277 to change it via some other pointer. */ | 2259 to change it via some other pointer. */ |
2278 TREE_READONLY (ref) = TYPE_READONLY (t); | 2260 TREE_READONLY (ref) = TYPE_READONLY (t); |
2279 TREE_SIDE_EFFECTS (ref) | 2261 TREE_SIDE_EFFECTS (ref) |
2280 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer); | 2262 = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer); |
2281 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t); | 2263 TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t); |
2282 protected_set_expr_location (ref, loc); | 2264 protected_set_expr_location (ref, loc); |
2283 return ref; | 2265 return ref; |
2284 } | 2266 } |
2285 } | 2267 } |
2286 else if (TREE_CODE (pointer) != ERROR_MARK) | 2268 else if (TREE_CODE (pointer) != ERROR_MARK) |
2287 invalid_indirection_error (loc, type, errstring); | 2269 invalid_indirection_error (loc, type, errstring); |
2288 | 2270 |
2289 return error_mark_node; | 2271 return error_mark_node; |
2378 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE) | 2360 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE) |
2379 { | 2361 { |
2380 tree rval, type; | 2362 tree rval, type; |
2381 | 2363 |
2382 /* An array that is indexed by a non-constant | 2364 /* An array that is indexed by a non-constant |
2383 cannot be stored in a register; we must be able to do | 2365 cannot be stored in a register; we must be able to do |
2384 address arithmetic on its address. | 2366 address arithmetic on its address. |
2385 Likewise an array of elements of variable size. */ | 2367 Likewise an array of elements of variable size. */ |
2386 if (TREE_CODE (index) != INTEGER_CST | 2368 if (TREE_CODE (index) != INTEGER_CST |
2387 || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array))) | 2369 || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array))) |
2388 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST)) | 2370 && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST)) |
2389 { | 2371 { |
2390 if (!c_mark_addressable (array)) | 2372 if (!c_mark_addressable (array)) |
2391 return error_mark_node; | 2373 return error_mark_node; |
2392 } | 2374 } |
2393 /* An array that is indexed by a constant value which is not within | 2375 /* An array that is indexed by a constant value which is not within |
2394 the array bounds cannot be stored in a register either; because we | 2376 the array bounds cannot be stored in a register either; because we |
2395 would get a crash in store_bit_field/extract_bit_field when trying | 2377 would get a crash in store_bit_field/extract_bit_field when trying |
2396 to access a non-existent part of the register. */ | 2378 to access a non-existent part of the register. */ |
2397 if (TREE_CODE (index) == INTEGER_CST | 2379 if (TREE_CODE (index) == INTEGER_CST |
2398 && TYPE_DOMAIN (TREE_TYPE (array)) | 2380 && TYPE_DOMAIN (TREE_TYPE (array)) |
2399 && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array)))) | 2381 && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array)))) |
2400 { | 2382 { |
2401 if (!c_mark_addressable (array)) | 2383 if (!c_mark_addressable (array)) |
2402 return error_mark_node; | 2384 return error_mark_node; |
2403 } | 2385 } |
2404 | 2386 |
2405 if (pedantic) | 2387 if (pedantic) |
2406 { | 2388 { |
2407 tree foo = array; | 2389 tree foo = array; |
2408 while (TREE_CODE (foo) == COMPONENT_REF) | 2390 while (TREE_CODE (foo) == COMPONENT_REF) |
2409 foo = TREE_OPERAND (foo, 0); | 2391 foo = TREE_OPERAND (foo, 0); |
2410 if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo)) | 2392 if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo)) |
2411 pedwarn (loc, OPT_pedantic, | 2393 pedwarn (loc, OPT_pedantic, |
2412 "ISO C forbids subscripting %<register%> array"); | 2394 "ISO C forbids subscripting %<register%> array"); |
2413 else if (!flag_isoc99 && !lvalue_p (foo)) | 2395 else if (!flag_isoc99 && !lvalue_p (foo)) |
2414 pedwarn (loc, OPT_pedantic, | 2396 pedwarn (loc, OPT_pedantic, |
2415 "ISO C90 forbids subscripting non-lvalue array"); | 2397 "ISO C90 forbids subscripting non-lvalue array"); |
2416 } | 2398 } |
2417 | 2399 |
2418 type = TREE_TYPE (TREE_TYPE (array)); | 2400 type = TREE_TYPE (TREE_TYPE (array)); |
2419 rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE); | 2401 rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE); |
2420 /* Array ref is const/volatile if the array elements are | 2402 /* Array ref is const/volatile if the array elements are |
2421 or if the array is. */ | 2403 or if the array is. */ |
2422 TREE_READONLY (rval) | 2404 TREE_READONLY (rval) |
2423 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array))) | 2405 |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array))) |
2424 | TREE_READONLY (array)); | 2406 | TREE_READONLY (array)); |
2425 TREE_SIDE_EFFECTS (rval) | 2407 TREE_SIDE_EFFECTS (rval) |
2426 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array))) | 2408 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array))) |
2427 | TREE_SIDE_EFFECTS (array)); | 2409 | TREE_SIDE_EFFECTS (array)); |
2428 TREE_THIS_VOLATILE (rval) | 2410 TREE_THIS_VOLATILE (rval) |
2429 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array))) | 2411 |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array))) |
2430 /* This was added by rms on 16 Nov 91. | 2412 /* This was added by rms on 16 Nov 91. |
2431 It fixes vol struct foo *a; a->elts[1] | 2413 It fixes vol struct foo *a; a->elts[1] |
2432 in an inline function. | 2414 in an inline function. |
2433 Hope it doesn't break something else. */ | 2415 Hope it doesn't break something else. */ |
2434 | TREE_THIS_VOLATILE (array)); | 2416 | TREE_THIS_VOLATILE (array)); |
2435 ret = require_complete_type (rval); | 2417 ret = require_complete_type (rval); |
2436 protected_set_expr_location (ret, loc); | 2418 protected_set_expr_location (ret, loc); |
2437 return ret; | 2419 return ret; |
2438 } | 2420 } |
2439 else | 2421 else |
2440 { | 2422 { |
2441 tree ar = default_conversion (array); | 2423 tree ar = default_conversion (array); |
2442 | 2424 |
2443 if (ar == error_mark_node) | 2425 if (ar == error_mark_node) |
2444 return ar; | 2426 return ar; |
2445 | 2427 |
2446 gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE); | 2428 gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE); |
2447 gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE); | 2429 gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE); |
2448 | 2430 |
2449 return build_indirect_ref | 2431 return build_indirect_ref |
2450 (loc, build_binary_op (loc, PLUS_EXPR, ar, index, 0), | 2432 (loc, build_binary_op (loc, PLUS_EXPR, ar, index, 0), |
2451 RO_ARRAY_INDEXING); | 2433 RO_ARRAY_INDEXING); |
2452 } | 2434 } |
2453 } | 2435 } |
2454 | 2436 |
2455 /* Build an external reference to identifier ID. FUN indicates | 2437 /* Build an external reference to identifier ID. FUN indicates |
2456 whether this will be used for a function call. LOC is the source | 2438 whether this will be used for a function call. LOC is the source |
2474 ref = decl; | 2456 ref = decl; |
2475 *type = TREE_TYPE (ref); | 2457 *type = TREE_TYPE (ref); |
2476 } | 2458 } |
2477 else if (fun) | 2459 else if (fun) |
2478 /* Implicit function declaration. */ | 2460 /* Implicit function declaration. */ |
2479 #ifndef noCbC | |
2480 ref = implicitly_declare (loc, id, fun); | |
2481 #else | |
2482 ref = implicitly_declare (loc, id); | 2461 ref = implicitly_declare (loc, id); |
2483 #endif | |
2484 else if (decl == error_mark_node) | 2462 else if (decl == error_mark_node) |
2485 /* Don't complain about something that's already been | 2463 /* Don't complain about something that's already been |
2486 complained about. */ | 2464 complained about. */ |
2487 return error_mark_node; | 2465 return error_mark_node; |
2488 else | 2466 else |
2504 } | 2482 } |
2505 | 2483 |
2506 if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof) | 2484 if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof) |
2507 { | 2485 { |
2508 if (!in_sizeof && !in_typeof) | 2486 if (!in_sizeof && !in_typeof) |
2509 C_DECL_USED (ref) = 1; | 2487 C_DECL_USED (ref) = 1; |
2510 else if (DECL_INITIAL (ref) == 0 | 2488 else if (DECL_INITIAL (ref) == 0 |
2511 && DECL_EXTERNAL (ref) | 2489 && DECL_EXTERNAL (ref) |
2512 && !TREE_PUBLIC (ref)) | 2490 && !TREE_PUBLIC (ref)) |
2513 record_maybe_used_decl (ref); | 2491 record_maybe_used_decl (ref); |
2514 } | 2492 } |
2515 | 2493 |
2516 if (TREE_CODE (ref) == CONST_DECL) | 2494 if (TREE_CODE (ref) == CONST_DECL) |
2517 { | 2495 { |
2518 used_types_insert (TREE_TYPE (ref)); | 2496 used_types_insert (TREE_TYPE (ref)); |
2519 | 2497 |
2520 if (warn_cxx_compat | 2498 if (warn_cxx_compat |
2521 && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE | 2499 && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE |
2522 && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref))) | 2500 && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref))) |
2523 { | 2501 { |
2524 warning_at (loc, OPT_Wc___compat, | 2502 warning_at (loc, OPT_Wc___compat, |
2525 ("enum constant defined in struct or union " | 2503 ("enum constant defined in struct or union " |
2526 "is not visible in C++")); | 2504 "is not visible in C++")); |
2527 inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here"); | 2505 inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here"); |
2528 } | 2506 } |
2529 | 2507 |
2530 ref = DECL_INITIAL (ref); | 2508 ref = DECL_INITIAL (ref); |
2531 TREE_CONSTANT (ref) = 1; | 2509 TREE_CONSTANT (ref) = 1; |
2532 } | 2510 } |
2533 else if (current_function_decl != 0 | 2511 else if (current_function_decl != 0 |
2534 && !DECL_FILE_SCOPE_P (current_function_decl) | 2512 && !DECL_FILE_SCOPE_P (current_function_decl) |
2535 && (TREE_CODE (ref) == VAR_DECL | 2513 && (TREE_CODE (ref) == VAR_DECL |
2536 || TREE_CODE (ref) == PARM_DECL | 2514 || TREE_CODE (ref) == PARM_DECL |
2537 || TREE_CODE (ref) == FUNCTION_DECL)) | 2515 || TREE_CODE (ref) == FUNCTION_DECL)) |
2538 { | 2516 { |
2539 tree context = decl_function_context (ref); | 2517 tree context = decl_function_context (ref); |
2540 | 2518 |
2541 if (context != 0 && context != current_function_decl) | 2519 if (context != 0 && context != current_function_decl) |
2542 DECL_NONLOCAL (ref) = 1; | 2520 DECL_NONLOCAL (ref) = 1; |
2543 } | 2521 } |
2544 /* C99 6.7.4p3: An inline definition of a function with external | 2522 /* C99 6.7.4p3: An inline definition of a function with external |
2545 linkage ... shall not contain a reference to an identifier with | 2523 linkage ... shall not contain a reference to an identifier with |
2546 internal linkage. */ | 2524 internal linkage. */ |
2547 else if (current_function_decl != 0 | 2525 else if (current_function_decl != 0 |
2548 && DECL_DECLARED_INLINE_P (current_function_decl) | 2526 && DECL_DECLARED_INLINE_P (current_function_decl) |
2549 && DECL_EXTERNAL (current_function_decl) | 2527 && DECL_EXTERNAL (current_function_decl) |
2550 && VAR_OR_FUNCTION_DECL_P (ref) | 2528 && VAR_OR_FUNCTION_DECL_P (ref) |
2551 && (TREE_CODE (ref) != VAR_DECL || TREE_STATIC (ref)) | 2529 && (TREE_CODE (ref) != VAR_DECL || TREE_STATIC (ref)) |
2552 && ! TREE_PUBLIC (ref) | 2530 && ! TREE_PUBLIC (ref) |
2553 && DECL_CONTEXT (ref) != current_function_decl) | 2531 && DECL_CONTEXT (ref) != current_function_decl) |
2554 record_inline_static (loc, current_function_decl, ref, | 2532 record_inline_static (loc, current_function_decl, ref, |
2555 csi_internal); | 2533 csi_internal); |
2556 | 2534 |
2557 return ref; | 2535 return ref; |
2558 } | 2536 } |
2559 | 2537 |
2560 /* Record details of decls possibly used inside sizeof or typeof. */ | 2538 /* Record details of decls possibly used inside sizeof or typeof. */ |
2596 struct maybe_used_decl *p = maybe_used_decls; | 2574 struct maybe_used_decl *p = maybe_used_decls; |
2597 int cur_level = in_sizeof + in_typeof; | 2575 int cur_level = in_sizeof + in_typeof; |
2598 while (p && p->level > cur_level) | 2576 while (p && p->level > cur_level) |
2599 { | 2577 { |
2600 if (used) | 2578 if (used) |
2601 { | 2579 { |
2602 if (cur_level == 0) | 2580 if (cur_level == 0) |
2603 C_DECL_USED (p->decl) = 1; | 2581 C_DECL_USED (p->decl) = 1; |
2604 else | 2582 else |
2605 p->level = cur_level; | 2583 p->level = cur_level; |
2606 } | 2584 } |
2607 p = p->next; | 2585 p = p->next; |
2608 } | 2586 } |
2609 if (!used || cur_level == 0) | 2587 if (!used || cur_level == 0) |
2610 maybe_used_decls = p; | 2588 maybe_used_decls = p; |
2611 } | 2589 } |
2625 } | 2603 } |
2626 else | 2604 else |
2627 { | 2605 { |
2628 bool expr_const_operands = true; | 2606 bool expr_const_operands = true; |
2629 tree folded_expr = c_fully_fold (expr.value, require_constant_value, | 2607 tree folded_expr = c_fully_fold (expr.value, require_constant_value, |
2630 &expr_const_operands); | 2608 &expr_const_operands); |
2631 ret.value = c_sizeof (loc, TREE_TYPE (folded_expr)); | 2609 ret.value = c_sizeof (loc, TREE_TYPE (folded_expr)); |
2632 ret.original_code = ERROR_MARK; | 2610 ret.original_code = ERROR_MARK; |
2633 ret.original_type = NULL; | 2611 ret.original_type = NULL; |
2634 if (c_vla_type_p (TREE_TYPE (folded_expr))) | 2612 if (c_vla_type_p (TREE_TYPE (folded_expr))) |
2635 { | 2613 { |
2636 /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */ | 2614 /* sizeof is evaluated when given a vla (C99 6.5.3.4p2). */ |
2637 ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value), | 2615 ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value), |
2638 folded_expr, ret.value); | 2616 folded_expr, ret.value); |
2639 C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands; | 2617 C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands; |
2640 SET_EXPR_LOCATION (ret.value, loc); | 2618 SET_EXPR_LOCATION (ret.value, loc); |
2641 } | 2619 } |
2642 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr))); | 2620 pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr))); |
2643 } | 2621 } |
2644 return ret; | 2622 return ret; |
2645 } | 2623 } |
2646 | 2624 |
2661 ret.original_type = NULL; | 2639 ret.original_type = NULL; |
2662 if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST) | 2640 if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST) |
2663 && c_vla_type_p (type)) | 2641 && c_vla_type_p (type)) |
2664 { | 2642 { |
2665 /* If the type is a [*] array, it is a VLA but is represented as | 2643 /* If the type is a [*] array, it is a VLA but is represented as |
2666 having a size of zero. In such a case we must ensure that | 2644 having a size of zero. In such a case we must ensure that |
2667 the result of sizeof does not get folded to a constant by | 2645 the result of sizeof does not get folded to a constant by |
2668 c_fully_fold, because if the size is evaluated the result is | 2646 c_fully_fold, because if the size is evaluated the result is |
2669 not constant and so constraints on zero or negative size | 2647 not constant and so constraints on zero or negative size |
2670 arrays must not be applied when this sizeof call is inside | 2648 arrays must not be applied when this sizeof call is inside |
2671 another array declarator. */ | 2649 another array declarator. */ |
2672 if (!type_expr) | 2650 if (!type_expr) |
2673 type_expr = integer_zero_node; | 2651 type_expr = integer_zero_node; |
2674 ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value), | 2652 ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value), |
2675 type_expr, ret.value); | 2653 type_expr, ret.value); |
2676 C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const; | 2654 C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const; |
2677 } | 2655 } |
2678 pop_maybe_used (type != error_mark_node | 2656 pop_maybe_used (type != error_mark_node |
2679 ? C_TYPE_VARIABLE_SIZE (type) : false); | 2657 ? C_TYPE_VARIABLE_SIZE (type) : false); |
2680 return ret; | 2658 return ret; |
2681 } | 2659 } |
2682 | 2660 |
2683 /* Build a function call to function FUNCTION with parameters PARAMS. | 2661 /* Build a function call to function FUNCTION with parameters PARAMS. |
2684 The function call is at LOC. | 2662 The function call is at LOC. |
2708 or pointer-to-function. This function changes the elements of | 2686 or pointer-to-function. This function changes the elements of |
2709 PARAMS. */ | 2687 PARAMS. */ |
2710 | 2688 |
2711 tree | 2689 tree |
2712 build_function_call_vec (location_t loc, tree function, VEC(tree,gc) *params, | 2690 build_function_call_vec (location_t loc, tree function, VEC(tree,gc) *params, |
2713 VEC(tree,gc) *origtypes) | 2691 VEC(tree,gc) *origtypes) |
2714 { | 2692 { |
2715 tree fntype, fundecl = 0; | 2693 tree fntype, fundecl = 0; |
2716 tree name = NULL_TREE, result; | 2694 tree name = NULL_TREE, result; |
2717 tree tem; | 2695 tree tem; |
2718 int nargs; | 2696 int nargs; |
2724 | 2702 |
2725 /* Convert anything with function type to a pointer-to-function. */ | 2703 /* Convert anything with function type to a pointer-to-function. */ |
2726 if (TREE_CODE (function) == FUNCTION_DECL) | 2704 if (TREE_CODE (function) == FUNCTION_DECL) |
2727 { | 2705 { |
2728 /* Implement type-directed function overloading for builtins. | 2706 /* Implement type-directed function overloading for builtins. |
2729 resolve_overloaded_builtin and targetm.resolve_overloaded_builtin | 2707 resolve_overloaded_builtin and targetm.resolve_overloaded_builtin |
2730 handle all the type checking. The result is a complete expression | 2708 handle all the type checking. The result is a complete expression |
2731 that implements this function call. */ | 2709 that implements this function call. */ |
2732 tem = resolve_overloaded_builtin (loc, function, params); | 2710 tem = resolve_overloaded_builtin (loc, function, params); |
2733 if (tem) | 2711 if (tem) |
2734 return tem; | 2712 return tem; |
2735 | 2713 |
2736 name = DECL_NAME (function); | 2714 name = DECL_NAME (function); |
2737 fundecl = function; | 2715 fundecl = function; |
2738 } | 2716 } |
2739 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE) | 2717 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE) |
2741 | 2719 |
2742 /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF | 2720 /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF |
2743 expressions, like those used for ObjC messenger dispatches. */ | 2721 expressions, like those used for ObjC messenger dispatches. */ |
2744 if (!VEC_empty (tree, params)) | 2722 if (!VEC_empty (tree, params)) |
2745 function = objc_rewrite_function_call (function, | 2723 function = objc_rewrite_function_call (function, |
2746 VEC_index (tree, params, 0)); | 2724 VEC_index (tree, params, 0)); |
2747 | 2725 |
2748 function = c_fully_fold (function, false, NULL); | 2726 function = c_fully_fold (function, false, NULL); |
2749 | 2727 |
2750 fntype = TREE_TYPE (function); | 2728 fntype = TREE_TYPE (function); |
2751 | 2729 |
2752 if (TREE_CODE (fntype) == ERROR_MARK) | 2730 if (TREE_CODE (fntype) == ERROR_MARK) |
2753 return error_mark_node; | 2731 return error_mark_node; |
2754 | 2732 |
2755 if (!(TREE_CODE (fntype) == POINTER_TYPE | 2733 if (!(TREE_CODE (fntype) == POINTER_TYPE |
2756 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)) | 2734 && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)) |
2757 { | 2735 { |
2758 error_at (loc, "called object %qE is not a function", function); | 2736 error_at (loc, "called object %qE is not a function", function); |
2759 return error_mark_node; | 2737 return error_mark_node; |
2760 } | 2738 } |
2761 | 2739 |
2767 | 2745 |
2768 /* Convert the parameters to the types declared in the | 2746 /* Convert the parameters to the types declared in the |
2769 function prototype, or apply default promotions. */ | 2747 function prototype, or apply default promotions. */ |
2770 | 2748 |
2771 nargs = convert_arguments (TYPE_ARG_TYPES (fntype), params, origtypes, | 2749 nargs = convert_arguments (TYPE_ARG_TYPES (fntype), params, origtypes, |
2772 function, fundecl); | 2750 function, fundecl); |
2773 if (nargs < 0) | 2751 if (nargs < 0) |
2774 return error_mark_node; | 2752 return error_mark_node; |
2775 | 2753 |
2776 /* Check that the function is called through a compatible prototype. | 2754 /* Check that the function is called through a compatible prototype. |
2777 If it is not, replace the call by a trap, wrapped up in a compound | 2755 If it is not, replace the call by a trap, wrapped up in a compound |
2783 && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL | 2761 && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL |
2784 && !comptypes (fntype, TREE_TYPE (tem))) | 2762 && !comptypes (fntype, TREE_TYPE (tem))) |
2785 { | 2763 { |
2786 tree return_type = TREE_TYPE (fntype); | 2764 tree return_type = TREE_TYPE (fntype); |
2787 tree trap = build_function_call (loc, built_in_decls[BUILT_IN_TRAP], | 2765 tree trap = build_function_call (loc, built_in_decls[BUILT_IN_TRAP], |
2788 NULL_TREE); | 2766 NULL_TREE); |
2789 int i; | 2767 int i; |
2790 | 2768 |
2791 /* This situation leads to run-time undefined behavior. We can't, | 2769 /* This situation leads to run-time undefined behavior. We can't, |
2792 therefore, simply error unless we can prove that all possible | 2770 therefore, simply error unless we can prove that all possible |
2793 executions of the program must execute the code. */ | 2771 executions of the program must execute the code. */ |
2794 if (warning_at (loc, 0, "function called through a non-compatible type")) | 2772 if (warning_at (loc, 0, "function called through a non-compatible type")) |
2795 /* We can, however, treat "undefined" any way we please. | 2773 /* We can, however, treat "undefined" any way we please. |
2796 Call abort to encourage the user to fix the program. */ | 2774 Call abort to encourage the user to fix the program. */ |
2797 inform (loc, "if this code is reached, the program will abort"); | 2775 inform (loc, "if this code is reached, the program will abort"); |
2798 /* Before the abort, allow the function arguments to exit or | 2776 /* Before the abort, allow the function arguments to exit or |
2799 call longjmp. */ | 2777 call longjmp. */ |
2800 for (i = 0; i < nargs; i++) | 2778 for (i = 0; i < nargs; i++) |
2801 trap = build2 (COMPOUND_EXPR, void_type_node, | 2779 trap = build2 (COMPOUND_EXPR, void_type_node, |
2802 VEC_index (tree, params, i), trap); | 2780 VEC_index (tree, params, i), trap); |
2803 | 2781 |
2804 if (VOID_TYPE_P (return_type)) | 2782 if (VOID_TYPE_P (return_type)) |
2805 { | 2783 { |
2806 if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED) | 2784 if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED) |
2807 pedwarn (loc, 0, | 2785 pedwarn (loc, 0, |
2808 "function with qualified void return type called"); | 2786 "function with qualified void return type called"); |
2809 return trap; | 2787 return trap; |
2810 } | 2788 } |
2811 else | 2789 else |
2812 { | 2790 { |
2813 tree rhs; | 2791 tree rhs; |
2814 | 2792 |
2815 if (AGGREGATE_TYPE_P (return_type)) | 2793 if (AGGREGATE_TYPE_P (return_type)) |
2833 && !check_builtin_function_arguments (fundecl, nargs, argarray)) | 2811 && !check_builtin_function_arguments (fundecl, nargs, argarray)) |
2834 return error_mark_node; | 2812 return error_mark_node; |
2835 | 2813 |
2836 /* Check that the arguments to the function are valid. */ | 2814 /* Check that the arguments to the function are valid. */ |
2837 check_function_arguments (TYPE_ATTRIBUTES (fntype), nargs, argarray, | 2815 check_function_arguments (TYPE_ATTRIBUTES (fntype), nargs, argarray, |
2838 TYPE_ARG_TYPES (fntype)); | 2816 TYPE_ARG_TYPES (fntype)); |
2839 | 2817 |
2840 if (name != NULL_TREE | 2818 if (name != NULL_TREE |
2841 && !strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10)) | 2819 && !strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10)) |
2842 { | 2820 { |
2843 if (require_constant_value) | 2821 if (require_constant_value) |
2844 result = | 2822 result = |
2845 fold_build_call_array_initializer_loc (loc, TREE_TYPE (fntype), | 2823 fold_build_call_array_initializer_loc (loc, TREE_TYPE (fntype), |
2846 function, nargs, argarray); | 2824 function, nargs, argarray); |
2847 else | 2825 else |
2848 result = fold_build_call_array_loc (loc, TREE_TYPE (fntype), | 2826 result = fold_build_call_array_loc (loc, TREE_TYPE (fntype), |
2849 function, nargs, argarray); | 2827 function, nargs, argarray); |
2850 if (TREE_CODE (result) == NOP_EXPR | 2828 if (TREE_CODE (result) == NOP_EXPR |
2851 && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST) | 2829 && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST) |
2852 STRIP_TYPE_NOPS (result); | 2830 STRIP_TYPE_NOPS (result); |
2853 } | 2831 } |
2854 else | 2832 else |
2855 result = build_call_array_loc (loc, TREE_TYPE (fntype), | 2833 result = build_call_array_loc (loc, TREE_TYPE (fntype), |
2856 function, nargs, argarray); | 2834 function, nargs, argarray); |
2857 | 2835 |
2858 if (VOID_TYPE_P (TREE_TYPE (result))) | 2836 if (VOID_TYPE_P (TREE_TYPE (result))) |
2859 { | 2837 { |
2860 if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED) | 2838 if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED) |
2861 pedwarn (loc, 0, | 2839 pedwarn (loc, 0, |
2862 "function with qualified void return type called"); | 2840 "function with qualified void return type called"); |
2863 return result; | 2841 return result; |
2864 } | 2842 } |
2865 return require_complete_type (result); | 2843 return require_complete_type (result); |
2866 } | 2844 } |
2867 | 2845 |
2884 than the length of VALUES in some error situations), or -1 on | 2862 than the length of VALUES in some error situations), or -1 on |
2885 failure. */ | 2863 failure. */ |
2886 | 2864 |
2887 static int | 2865 static int |
2888 convert_arguments (tree typelist, VEC(tree,gc) *values, | 2866 convert_arguments (tree typelist, VEC(tree,gc) *values, |
2889 VEC(tree,gc) *origtypes, tree function, tree fundecl) | 2867 VEC(tree,gc) *origtypes, tree function, tree fundecl) |
2890 { | 2868 { |
2891 tree typetail, val; | 2869 tree typetail, val; |
2892 unsigned int parmnum; | 2870 unsigned int parmnum; |
2893 bool error_args = false; | 2871 bool error_args = false; |
2894 const bool type_generic = fundecl | 2872 const bool type_generic = fundecl |
2911 if (type_generic | 2889 if (type_generic |
2912 && DECL_BUILT_IN (fundecl) | 2890 && DECL_BUILT_IN (fundecl) |
2913 && DECL_BUILT_IN_CLASS (fundecl) == BUILT_IN_NORMAL) | 2891 && DECL_BUILT_IN_CLASS (fundecl) == BUILT_IN_NORMAL) |
2914 { | 2892 { |
2915 switch (DECL_FUNCTION_CODE (fundecl)) | 2893 switch (DECL_FUNCTION_CODE (fundecl)) |
2916 { | 2894 { |
2917 case BUILT_IN_ISFINITE: | 2895 case BUILT_IN_ISFINITE: |
2918 case BUILT_IN_ISINF: | 2896 case BUILT_IN_ISINF: |
2919 case BUILT_IN_ISINF_SIGN: | 2897 case BUILT_IN_ISINF_SIGN: |
2920 case BUILT_IN_ISNAN: | 2898 case BUILT_IN_ISNAN: |
2921 case BUILT_IN_ISNORMAL: | 2899 case BUILT_IN_ISNORMAL: |
2922 case BUILT_IN_FPCLASSIFY: | 2900 case BUILT_IN_FPCLASSIFY: |
2923 type_generic_remove_excess_precision = true; | 2901 type_generic_remove_excess_precision = true; |
2924 break; | 2902 break; |
2925 | 2903 |
2926 default: | 2904 default: |
2927 type_generic_remove_excess_precision = false; | 2905 type_generic_remove_excess_precision = false; |
2928 break; | 2906 break; |
2929 } | 2907 } |
2930 } | 2908 } |
2931 | 2909 |
2932 /* Scan the given expressions and types, producing individual | 2910 /* Scan the given expressions and types, producing individual |
2933 converted arguments. */ | 2911 converted arguments. */ |
2934 | 2912 |
2958 inform (DECL_SOURCE_LOCATION (fundecl), "declared here"); | 2936 inform (DECL_SOURCE_LOCATION (fundecl), "declared here"); |
2959 return parmnum; | 2937 return parmnum; |
2960 } | 2938 } |
2961 | 2939 |
2962 if (selector && argnum > 2) | 2940 if (selector && argnum > 2) |
2963 { | 2941 { |
2964 rname = selector; | 2942 rname = selector; |
2965 argnum -= 2; | 2943 argnum -= 2; |
2966 } | 2944 } |
2967 | 2945 |
2968 npc = null_pointer_constant_p (val); | 2946 npc = null_pointer_constant_p (val); |
2969 | 2947 |
2970 /* If there is excess precision and a prototype, convert once to | 2948 /* If there is excess precision and a prototype, convert once to |
2971 the required type rather than converting via the semantic | 2949 the required type rather than converting via the semantic |
2972 type. Likewise without a prototype a float value represented | 2950 type. Likewise without a prototype a float value represented |
2973 as long double should be converted once to double. But for | 2951 as long double should be converted once to double. But for |
2974 type-generic classification functions excess precision must | 2952 type-generic classification functions excess precision must |
2975 be removed here. */ | 2953 be removed here. */ |
2976 if (TREE_CODE (val) == EXCESS_PRECISION_EXPR | 2954 if (TREE_CODE (val) == EXCESS_PRECISION_EXPR |
2977 && (type || !type_generic || !type_generic_remove_excess_precision)) | 2955 && (type || !type_generic || !type_generic_remove_excess_precision)) |
2978 { | 2956 { |
2979 val = TREE_OPERAND (val, 0); | 2957 val = TREE_OPERAND (val, 0); |
2980 excess_precision = true; | 2958 excess_precision = true; |
2981 } | 2959 } |
2982 val = c_fully_fold (val, false, NULL); | 2960 val = c_fully_fold (val, false, NULL); |
2983 STRIP_TYPE_NOPS (val); | 2961 STRIP_TYPE_NOPS (val); |
2984 | 2962 |
2985 val = require_complete_type (val); | 2963 val = require_complete_type (val); |
2986 | 2964 |
2987 if (type != 0) | 2965 if (type != 0) |
2988 { | 2966 { |
2989 /* Formal parm type is specified by a function prototype. */ | 2967 /* Formal parm type is specified by a function prototype. */ |
2990 | 2968 |
2991 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) | 2969 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) |
2992 { | 2970 { |
2993 error ("type of formal parameter %d is incomplete", parmnum + 1); | 2971 error ("type of formal parameter %d is incomplete", parmnum + 1); |
2994 parmval = val; | 2972 parmval = val; |
2995 } | 2973 } |
2996 else | 2974 else |
2997 { | 2975 { |
2998 tree origtype; | 2976 tree origtype; |
2999 | 2977 |
3000 /* Optionally warn about conversions that | 2978 /* Optionally warn about conversions that |
3001 differ from the default conversions. */ | 2979 differ from the default conversions. */ |
3002 if (warn_traditional_conversion || warn_traditional) | 2980 if (warn_traditional_conversion || warn_traditional) |
3003 { | 2981 { |
3004 unsigned int formal_prec = TYPE_PRECISION (type); | 2982 unsigned int formal_prec = TYPE_PRECISION (type); |
3005 | 2983 |
3006 if (INTEGRAL_TYPE_P (type) | 2984 if (INTEGRAL_TYPE_P (type) |
3007 && TREE_CODE (valtype) == REAL_TYPE) | 2985 && TREE_CODE (valtype) == REAL_TYPE) |
3008 warning (0, "passing argument %d of %qE as integer " | 2986 warning (0, "passing argument %d of %qE as integer " |
3009 "rather than floating due to prototype", | 2987 "rather than floating due to prototype", |
3010 argnum, rname); | 2988 argnum, rname); |
3011 if (INTEGRAL_TYPE_P (type) | 2989 if (INTEGRAL_TYPE_P (type) |
3012 && TREE_CODE (valtype) == COMPLEX_TYPE) | 2990 && TREE_CODE (valtype) == COMPLEX_TYPE) |
3013 warning (0, "passing argument %d of %qE as integer " | 2991 warning (0, "passing argument %d of %qE as integer " |
3014 "rather than complex due to prototype", | 2992 "rather than complex due to prototype", |
3015 argnum, rname); | 2993 argnum, rname); |
3016 else if (TREE_CODE (type) == COMPLEX_TYPE | 2994 else if (TREE_CODE (type) == COMPLEX_TYPE |
3017 && TREE_CODE (valtype) == REAL_TYPE) | 2995 && TREE_CODE (valtype) == REAL_TYPE) |
3018 warning (0, "passing argument %d of %qE as complex " | 2996 warning (0, "passing argument %d of %qE as complex " |
3019 "rather than floating due to prototype", | 2997 "rather than floating due to prototype", |
3020 argnum, rname); | 2998 argnum, rname); |
3021 else if (TREE_CODE (type) == REAL_TYPE | 2999 else if (TREE_CODE (type) == REAL_TYPE |
3022 && INTEGRAL_TYPE_P (valtype)) | 3000 && INTEGRAL_TYPE_P (valtype)) |
3023 warning (0, "passing argument %d of %qE as floating " | 3001 warning (0, "passing argument %d of %qE as floating " |
3024 "rather than integer due to prototype", | 3002 "rather than integer due to prototype", |
3025 argnum, rname); | 3003 argnum, rname); |
3026 else if (TREE_CODE (type) == COMPLEX_TYPE | 3004 else if (TREE_CODE (type) == COMPLEX_TYPE |
3027 && INTEGRAL_TYPE_P (valtype)) | 3005 && INTEGRAL_TYPE_P (valtype)) |
3028 warning (0, "passing argument %d of %qE as complex " | 3006 warning (0, "passing argument %d of %qE as complex " |
3029 "rather than integer due to prototype", | 3007 "rather than integer due to prototype", |
3030 argnum, rname); | 3008 argnum, rname); |
3031 else if (TREE_CODE (type) == REAL_TYPE | 3009 else if (TREE_CODE (type) == REAL_TYPE |
3032 && TREE_CODE (valtype) == COMPLEX_TYPE) | 3010 && TREE_CODE (valtype) == COMPLEX_TYPE) |
3033 warning (0, "passing argument %d of %qE as floating " | 3011 warning (0, "passing argument %d of %qE as floating " |
3034 "rather than complex due to prototype", | 3012 "rather than complex due to prototype", |
3035 argnum, rname); | 3013 argnum, rname); |
3036 /* ??? At some point, messages should be written about | 3014 /* ??? At some point, messages should be written about |
3037 conversions between complex types, but that's too messy | 3015 conversions between complex types, but that's too messy |
3038 to do now. */ | 3016 to do now. */ |
3039 else if (TREE_CODE (type) == REAL_TYPE | 3017 else if (TREE_CODE (type) == REAL_TYPE |
3040 && TREE_CODE (valtype) == REAL_TYPE) | 3018 && TREE_CODE (valtype) == REAL_TYPE) |
3041 { | 3019 { |
3042 /* Warn if any argument is passed as `float', | 3020 /* Warn if any argument is passed as `float', |
3043 since without a prototype it would be `double'. */ | 3021 since without a prototype it would be `double'. */ |
3044 if (formal_prec == TYPE_PRECISION (float_type_node) | 3022 if (formal_prec == TYPE_PRECISION (float_type_node) |
3045 && type != dfloat32_type_node) | 3023 && type != dfloat32_type_node) |
3046 warning (0, "passing argument %d of %qE as %<float%> " | 3024 warning (0, "passing argument %d of %qE as %<float%> " |
3047 "rather than %<double%> due to prototype", | 3025 "rather than %<double%> due to prototype", |
3048 argnum, rname); | 3026 argnum, rname); |
3049 | 3027 |
3050 /* Warn if mismatch between argument and prototype | 3028 /* Warn if mismatch between argument and prototype |
3051 for decimal float types. Warn of conversions with | 3029 for decimal float types. Warn of conversions with |
3052 binary float types and of precision narrowing due to | 3030 binary float types and of precision narrowing due to |
3053 prototype. */ | 3031 prototype. */ |
3054 else if (type != valtype | 3032 else if (type != valtype |
3055 && (type == dfloat32_type_node | 3033 && (type == dfloat32_type_node |
3056 || type == dfloat64_type_node | 3034 || type == dfloat64_type_node |
3057 || type == dfloat128_type_node | 3035 || type == dfloat128_type_node |
3058 || valtype == dfloat32_type_node | 3036 || valtype == dfloat32_type_node |
3059 || valtype == dfloat64_type_node | 3037 || valtype == dfloat64_type_node |
3060 || valtype == dfloat128_type_node) | 3038 || valtype == dfloat128_type_node) |
3061 && (formal_prec | 3039 && (formal_prec |
3062 <= TYPE_PRECISION (valtype) | 3040 <= TYPE_PRECISION (valtype) |
3063 || (type == dfloat128_type_node | 3041 || (type == dfloat128_type_node |
3064 && (valtype | 3042 && (valtype |
3065 != dfloat64_type_node | 3043 != dfloat64_type_node |
3066 && (valtype | 3044 && (valtype |
3067 != dfloat32_type_node))) | 3045 != dfloat32_type_node))) |
3068 || (type == dfloat64_type_node | 3046 || (type == dfloat64_type_node |
3069 && (valtype | 3047 && (valtype |
3070 != dfloat32_type_node)))) | 3048 != dfloat32_type_node)))) |
3071 warning (0, "passing argument %d of %qE as %qT " | 3049 warning (0, "passing argument %d of %qE as %qT " |
3072 "rather than %qT due to prototype", | 3050 "rather than %qT due to prototype", |
3073 argnum, rname, type, valtype); | 3051 argnum, rname, type, valtype); |
3074 | 3052 |
3075 } | 3053 } |
3076 /* Detect integer changing in width or signedness. | 3054 /* Detect integer changing in width or signedness. |
3077 These warnings are only activated with | 3055 These warnings are only activated with |
3078 -Wtraditional-conversion, not with -Wtraditional. */ | 3056 -Wtraditional-conversion, not with -Wtraditional. */ |
3079 else if (warn_traditional_conversion && INTEGRAL_TYPE_P (type) | 3057 else if (warn_traditional_conversion && INTEGRAL_TYPE_P (type) |
3080 && INTEGRAL_TYPE_P (valtype)) | 3058 && INTEGRAL_TYPE_P (valtype)) |
3081 { | 3059 { |
3082 tree would_have_been = default_conversion (val); | 3060 tree would_have_been = default_conversion (val); |
3083 tree type1 = TREE_TYPE (would_have_been); | 3061 tree type1 = TREE_TYPE (would_have_been); |
3084 | 3062 |
3085 if (TREE_CODE (type) == ENUMERAL_TYPE | 3063 if (TREE_CODE (type) == ENUMERAL_TYPE |
3086 && (TYPE_MAIN_VARIANT (type) | 3064 && (TYPE_MAIN_VARIANT (type) |
3087 == TYPE_MAIN_VARIANT (valtype))) | 3065 == TYPE_MAIN_VARIANT (valtype))) |
3088 /* No warning if function asks for enum | 3066 /* No warning if function asks for enum |
3089 and the actual arg is that enum type. */ | 3067 and the actual arg is that enum type. */ |
3090 ; | 3068 ; |
3091 else if (formal_prec != TYPE_PRECISION (type1)) | 3069 else if (formal_prec != TYPE_PRECISION (type1)) |
3092 warning (OPT_Wtraditional_conversion, | 3070 warning (OPT_Wtraditional_conversion, |
3093 "passing argument %d of %qE " | 3071 "passing argument %d of %qE " |
3094 "with different width due to prototype", | 3072 "with different width due to prototype", |
3095 argnum, rname); | 3073 argnum, rname); |
3096 else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1)) | 3074 else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1)) |
3097 ; | 3075 ; |
3098 /* Don't complain if the formal parameter type | 3076 /* Don't complain if the formal parameter type |
3099 is an enum, because we can't tell now whether | 3077 is an enum, because we can't tell now whether |
3100 the value was an enum--even the same enum. */ | 3078 the value was an enum--even the same enum. */ |
3101 else if (TREE_CODE (type) == ENUMERAL_TYPE) | 3079 else if (TREE_CODE (type) == ENUMERAL_TYPE) |
3102 ; | 3080 ; |
3103 else if (TREE_CODE (val) == INTEGER_CST | 3081 else if (TREE_CODE (val) == INTEGER_CST |
3104 && int_fits_type_p (val, type)) | 3082 && int_fits_type_p (val, type)) |
3105 /* Change in signedness doesn't matter | 3083 /* Change in signedness doesn't matter |
3106 if a constant value is unaffected. */ | 3084 if a constant value is unaffected. */ |
3107 ; | 3085 ; |
3108 /* If the value is extended from a narrower | 3086 /* If the value is extended from a narrower |
3109 unsigned type, it doesn't matter whether we | 3087 unsigned type, it doesn't matter whether we |
3110 pass it as signed or unsigned; the value | 3088 pass it as signed or unsigned; the value |
3111 certainly is the same either way. */ | 3089 certainly is the same either way. */ |
3112 else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type) | 3090 else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type) |
3113 && TYPE_UNSIGNED (valtype)) | 3091 && TYPE_UNSIGNED (valtype)) |
3114 ; | 3092 ; |
3115 else if (TYPE_UNSIGNED (type)) | 3093 else if (TYPE_UNSIGNED (type)) |
3116 warning (OPT_Wtraditional_conversion, | 3094 warning (OPT_Wtraditional_conversion, |
3117 "passing argument %d of %qE " | 3095 "passing argument %d of %qE " |
3118 "as unsigned due to prototype", | 3096 "as unsigned due to prototype", |
3119 argnum, rname); | 3097 argnum, rname); |
3120 else | 3098 else |
3121 warning (OPT_Wtraditional_conversion, | 3099 warning (OPT_Wtraditional_conversion, |
3122 "passing argument %d of %qE " | 3100 "passing argument %d of %qE " |
3123 "as signed due to prototype", argnum, rname); | 3101 "as signed due to prototype", argnum, rname); |
3124 } | 3102 } |
3125 } | 3103 } |
3126 | 3104 |
3127 /* Possibly restore an EXCESS_PRECISION_EXPR for the | 3105 /* Possibly restore an EXCESS_PRECISION_EXPR for the |
3128 sake of better warnings from convert_and_check. */ | 3106 sake of better warnings from convert_and_check. */ |
3129 if (excess_precision) | 3107 if (excess_precision) |
3130 val = build1 (EXCESS_PRECISION_EXPR, valtype, val); | 3108 val = build1 (EXCESS_PRECISION_EXPR, valtype, val); |
3131 origtype = (origtypes == NULL | 3109 origtype = (origtypes == NULL |
3132 ? NULL_TREE | 3110 ? NULL_TREE |
3133 : VEC_index (tree, origtypes, parmnum)); | 3111 : VEC_index (tree, origtypes, parmnum)); |
3134 parmval = convert_for_assignment (input_location, type, val, | 3112 parmval = convert_for_assignment (input_location, type, val, |
3135 origtype, ic_argpass, npc, | 3113 origtype, ic_argpass, npc, |
3136 fundecl, function, | 3114 fundecl, function, |
3137 parmnum + 1); | 3115 parmnum + 1); |
3138 | 3116 |
3139 if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0) | 3117 if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0) |
3140 && INTEGRAL_TYPE_P (type) | 3118 && INTEGRAL_TYPE_P (type) |
3141 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) | 3119 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) |
3142 parmval = default_conversion (parmval); | 3120 parmval = default_conversion (parmval); |
3143 } | 3121 } |
3144 } | 3122 } |
3145 else if (TREE_CODE (valtype) == REAL_TYPE | 3123 else if (TREE_CODE (valtype) == REAL_TYPE |
3146 && (TYPE_PRECISION (valtype) | 3124 && (TYPE_PRECISION (valtype) |
3147 < TYPE_PRECISION (double_type_node)) | 3125 < TYPE_PRECISION (double_type_node)) |
3148 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype))) | 3126 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype))) |
3149 { | 3127 { |
3159 valtype, double_type_node); | 3137 valtype, double_type_node); |
3160 parmval = convert (double_type_node, val); | 3138 parmval = convert (double_type_node, val); |
3161 } | 3139 } |
3162 } | 3140 } |
3163 else if (excess_precision && !type_generic) | 3141 else if (excess_precision && !type_generic) |
3164 /* A "double" argument with excess precision being passed | 3142 /* A "double" argument with excess precision being passed |
3165 without a prototype or in variable arguments. */ | 3143 without a prototype or in variable arguments. */ |
3166 parmval = convert (valtype, val); | 3144 parmval = convert (valtype, val); |
3167 else if ((invalid_func_diag = | 3145 else if ((invalid_func_diag = |
3168 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val))) | 3146 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val))) |
3169 { | 3147 { |
3170 error (invalid_func_diag); | 3148 error (invalid_func_diag); |
3171 return -1; | 3149 return -1; |
3172 } | 3150 } |
3173 else | 3151 else |
3174 /* Convert `short' and `char' to full-size `int'. */ | 3152 /* Convert `short' and `char' to full-size `int'. */ |
3175 parmval = default_conversion (val); | 3153 parmval = default_conversion (val); |
3176 | 3154 |
3177 VEC_replace (tree, values, parmnum, parmval); | 3155 VEC_replace (tree, values, parmnum, parmval); |
3178 if (parmval == error_mark_node) | 3156 if (parmval == error_mark_node) |
3179 error_args = true; | 3157 error_args = true; |
3180 | 3158 |
3181 if (typetail) | 3159 if (typetail) |
3182 typetail = TREE_CHAIN (typetail); | 3160 typetail = TREE_CHAIN (typetail); |
3183 } | 3161 } |
3184 | 3162 |
3185 gcc_assert (parmnum == VEC_length (tree, values)); | 3163 gcc_assert (parmnum == VEC_length (tree, values)); |
3186 | 3164 |
3187 #ifndef noCbC | |
3188 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node | |
3189 //&& !CbC_IS_CODE_SEGMENT(TREE_TYPE(fundecl)) ) | |
3190 && !(fundecl&&CbC_IS_CODE_SEGMENT(fundecl)) ) | |
3191 #else | |
3192 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node) | 3165 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node) |
3193 #endif | |
3194 { | 3166 { |
3195 error_at (input_location, | 3167 error_at (input_location, |
3196 "too few arguments to function %qE", function); | 3168 "too few arguments to function %qE", function); |
3197 if (fundecl && !DECL_BUILT_IN (fundecl)) | 3169 if (fundecl && !DECL_BUILT_IN (fundecl)) |
3198 inform (DECL_SOURCE_LOCATION (fundecl), "declared here"); | 3170 inform (DECL_SOURCE_LOCATION (fundecl), "declared here"); |
3233 | 3205 |
3234 LOCATION is the location of the binary operator. */ | 3206 LOCATION is the location of the binary operator. */ |
3235 | 3207 |
3236 struct c_expr | 3208 struct c_expr |
3237 parser_build_binary_op (location_t location, enum tree_code code, | 3209 parser_build_binary_op (location_t location, enum tree_code code, |
3238 struct c_expr arg1, struct c_expr arg2) | 3210 struct c_expr arg1, struct c_expr arg2) |
3239 { | 3211 { |
3240 struct c_expr result; | 3212 struct c_expr result; |
3241 | 3213 |
3242 enum tree_code code1 = arg1.original_code; | 3214 enum tree_code code1 = arg1.original_code; |
3243 enum tree_code code2 = arg2.original_code; | 3215 enum tree_code code2 = arg2.original_code; |
3247 tree type2 = (arg2.original_type | 3219 tree type2 = (arg2.original_type |
3248 ? arg2.original_type | 3220 ? arg2.original_type |
3249 : TREE_TYPE (arg2.value)); | 3221 : TREE_TYPE (arg2.value)); |
3250 | 3222 |
3251 result.value = build_binary_op (location, code, | 3223 result.value = build_binary_op (location, code, |
3252 arg1.value, arg2.value, 1); | 3224 arg1.value, arg2.value, 1); |
3253 result.original_code = code; | 3225 result.original_code = code; |
3254 result.original_type = NULL; | 3226 result.original_type = NULL; |
3255 | 3227 |
3256 if (TREE_CODE (result.value) == ERROR_MARK) | 3228 if (TREE_CODE (result.value) == ERROR_MARK) |
3257 return result; | 3229 return result; |
3264 if (warn_parentheses) | 3236 if (warn_parentheses) |
3265 warn_about_parentheses (code, code1, arg1.value, code2, arg2.value); | 3237 warn_about_parentheses (code, code1, arg1.value, code2, arg2.value); |
3266 | 3238 |
3267 if (warn_logical_op) | 3239 if (warn_logical_op) |
3268 warn_logical_operator (input_location, code, TREE_TYPE (result.value), | 3240 warn_logical_operator (input_location, code, TREE_TYPE (result.value), |
3269 code1, arg1.value, code2, arg2.value); | 3241 code1, arg1.value, code2, arg2.value); |
3270 | 3242 |
3271 /* Warn about comparisons against string literals, with the exception | 3243 /* Warn about comparisons against string literals, with the exception |
3272 of testing for equality or inequality of a string literal with NULL. */ | 3244 of testing for equality or inequality of a string literal with NULL. */ |
3273 if (code == EQ_EXPR || code == NE_EXPR) | 3245 if (code == EQ_EXPR || code == NE_EXPR) |
3274 { | 3246 { |
3275 if ((code1 == STRING_CST && !integer_zerop (arg2.value)) | 3247 if ((code1 == STRING_CST && !integer_zerop (arg2.value)) |
3276 || (code2 == STRING_CST && !integer_zerop (arg1.value))) | 3248 || (code2 == STRING_CST && !integer_zerop (arg1.value))) |
3249 warning_at (location, OPT_Waddress, | |
3250 "comparison with string literal results in unspecified behavior"); | |
3251 } | |
3252 else if (TREE_CODE_CLASS (code) == tcc_comparison | |
3253 && (code1 == STRING_CST || code2 == STRING_CST)) | |
3277 warning_at (location, OPT_Waddress, | 3254 warning_at (location, OPT_Waddress, |
3278 "comparison with string literal results in unspecified behavior"); | 3255 "comparison with string literal results in unspecified behavior"); |
3279 } | |
3280 else if (TREE_CODE_CLASS (code) == tcc_comparison | |
3281 && (code1 == STRING_CST || code2 == STRING_CST)) | |
3282 warning_at (location, OPT_Waddress, | |
3283 "comparison with string literal results in unspecified behavior"); | |
3284 | 3256 |
3285 if (TREE_OVERFLOW_P (result.value) | 3257 if (TREE_OVERFLOW_P (result.value) |
3286 && !TREE_OVERFLOW_P (arg1.value) | 3258 && !TREE_OVERFLOW_P (arg1.value) |
3287 && !TREE_OVERFLOW_P (arg2.value)) | 3259 && !TREE_OVERFLOW_P (arg2.value)) |
3288 overflow_warning (location, result.value); | 3260 overflow_warning (location, result.value); |
3292 && TREE_CODE_CLASS (code) == tcc_comparison | 3264 && TREE_CODE_CLASS (code) == tcc_comparison |
3293 && TREE_CODE (type1) == ENUMERAL_TYPE | 3265 && TREE_CODE (type1) == ENUMERAL_TYPE |
3294 && TREE_CODE (type2) == ENUMERAL_TYPE | 3266 && TREE_CODE (type2) == ENUMERAL_TYPE |
3295 && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2)) | 3267 && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2)) |
3296 warning_at (location, OPT_Wenum_compare, | 3268 warning_at (location, OPT_Wenum_compare, |
3297 "comparison between %qT and %qT", | 3269 "comparison between %qT and %qT", |
3298 type1, type2); | 3270 type1, type2); |
3299 | 3271 |
3300 return result; | 3272 return result; |
3301 } | 3273 } |
3302 | 3274 |
3303 /* Return a tree for the difference of pointers OP0 and OP1. | 3275 /* Return a tree for the difference of pointers OP0 and OP1. |
3322 { | 3294 { |
3323 addr_space_t as_common; | 3295 addr_space_t as_common; |
3324 tree common_type; | 3296 tree common_type; |
3325 | 3297 |
3326 /* Determine the common superset address space. This is guaranteed | 3298 /* Determine the common superset address space. This is guaranteed |
3327 to exist because the caller verified that comp_target_types | 3299 to exist because the caller verified that comp_target_types |
3328 returned non-zero. */ | 3300 returned non-zero. */ |
3329 if (!addr_space_superset (as0, as1, &as_common)) | 3301 if (!addr_space_superset (as0, as1, &as_common)) |
3330 gcc_unreachable (); | 3302 gcc_unreachable (); |
3331 | 3303 |
3332 common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1)); | 3304 common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1)); |
3333 op0 = convert (common_type, op0); | 3305 op0 = convert (common_type, op0); |
3334 op1 = convert (common_type, op1); | 3306 op1 = convert (common_type, op1); |
3335 } | 3307 } |
3337 /* Determine integer type to perform computations in. This will usually | 3309 /* Determine integer type to perform computations in. This will usually |
3338 be the same as the result type (ptrdiff_t), but may need to be a wider | 3310 be the same as the result type (ptrdiff_t), but may need to be a wider |
3339 type if pointers for the address space are wider than ptrdiff_t. */ | 3311 type if pointers for the address space are wider than ptrdiff_t. */ |
3340 if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0))) | 3312 if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0))) |
3341 inttype = lang_hooks.types.type_for_size | 3313 inttype = lang_hooks.types.type_for_size |
3342 (TYPE_PRECISION (TREE_TYPE (op0)), 0); | 3314 (TYPE_PRECISION (TREE_TYPE (op0)), 0); |
3343 else | 3315 else |
3344 inttype = restype; | 3316 inttype = restype; |
3345 | 3317 |
3346 | 3318 |
3347 if (TREE_CODE (target_type) == VOID_TYPE) | 3319 if (TREE_CODE (target_type) == VOID_TYPE) |
3348 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith, | 3320 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith, |
3349 "pointer of type %<void *%> used in subtraction"); | 3321 "pointer of type %<void *%> used in subtraction"); |
3350 if (TREE_CODE (target_type) == FUNCTION_TYPE) | 3322 if (TREE_CODE (target_type) == FUNCTION_TYPE) |
3351 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith, | 3323 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith, |
3352 "pointer to a function used in subtraction"); | 3324 "pointer to a function used in subtraction"); |
3353 | 3325 |
3354 /* If the conversion to ptrdiff_type does anything like widening or | 3326 /* If the conversion to ptrdiff_type does anything like widening or |
3355 converting a partial to an integral mode, we get a convert_expression | 3327 converting a partial to an integral mode, we get a convert_expression |
3356 that is in the way to do any simplifications. | 3328 that is in the way to do any simplifications. |
3357 (fold-const.c doesn't know that the extra bits won't be needed. | 3329 (fold-const.c doesn't know that the extra bits won't be needed. |
3359 different mode in place.) | 3331 different mode in place.) |
3360 So first try to find a common term here 'by hand'; we want to cover | 3332 So first try to find a common term here 'by hand'; we want to cover |
3361 at least the cases that occur in legal static initializers. */ | 3333 at least the cases that occur in legal static initializers. */ |
3362 if (CONVERT_EXPR_P (op0) | 3334 if (CONVERT_EXPR_P (op0) |
3363 && (TYPE_PRECISION (TREE_TYPE (op0)) | 3335 && (TYPE_PRECISION (TREE_TYPE (op0)) |
3364 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0))))) | 3336 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0))))) |
3365 con0 = TREE_OPERAND (op0, 0); | 3337 con0 = TREE_OPERAND (op0, 0); |
3366 else | 3338 else |
3367 con0 = op0; | 3339 con0 = op0; |
3368 if (CONVERT_EXPR_P (op1) | 3340 if (CONVERT_EXPR_P (op1) |
3369 && (TYPE_PRECISION (TREE_TYPE (op1)) | 3341 && (TYPE_PRECISION (TREE_TYPE (op1)) |
3370 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0))))) | 3342 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0))))) |
3371 con1 = TREE_OPERAND (op1, 0); | 3343 con1 = TREE_OPERAND (op1, 0); |
3372 else | 3344 else |
3373 con1 = op1; | 3345 con1 = op1; |
3374 | 3346 |
3375 if (TREE_CODE (con0) == PLUS_EXPR) | 3347 if (TREE_CODE (con0) == PLUS_EXPR) |
3399 then drop through to build the divide operator. | 3371 then drop through to build the divide operator. |
3400 Do not do default conversions on the minus operator | 3372 Do not do default conversions on the minus operator |
3401 in case restype is a short type. */ | 3373 in case restype is a short type. */ |
3402 | 3374 |
3403 op0 = build_binary_op (loc, | 3375 op0 = build_binary_op (loc, |
3404 MINUS_EXPR, convert (inttype, op0), | 3376 MINUS_EXPR, convert (inttype, op0), |
3405 convert (inttype, op1), 0); | 3377 convert (inttype, op1), 0); |
3406 /* This generates an error if op1 is pointer to incomplete type. */ | 3378 /* This generates an error if op1 is pointer to incomplete type. */ |
3407 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1)))) | 3379 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1)))) |
3408 error_at (loc, "arithmetic on pointer to an incomplete type"); | 3380 error_at (loc, "arithmetic on pointer to an incomplete type"); |
3409 | 3381 |
3410 /* This generates an error if op0 is pointer to incomplete type. */ | 3382 /* This generates an error if op0 is pointer to incomplete type. */ |
3411 op1 = c_size_in_bytes (target_type); | 3383 op1 = c_size_in_bytes (target_type); |
3412 | 3384 |
3413 /* Divide by the size, in easiest possible way. */ | 3385 /* Divide by the size, in easiest possible way. */ |
3414 result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype, | 3386 result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype, |
3415 op0, convert (inttype, op1)); | 3387 op0, convert (inttype, op1)); |
3416 | 3388 |
3417 /* Convert to final result type if necessary. */ | 3389 /* Convert to final result type if necessary. */ |
3418 return convert (restype, result); | 3390 return convert (restype, result); |
3419 } | 3391 } |
3420 | 3392 |
3429 | 3401 |
3430 LOCATION is the location of the operator. */ | 3402 LOCATION is the location of the operator. */ |
3431 | 3403 |
3432 tree | 3404 tree |
3433 build_unary_op (location_t location, | 3405 build_unary_op (location_t location, |
3434 enum tree_code code, tree xarg, int flag) | 3406 enum tree_code code, tree xarg, int flag) |
3435 { | 3407 { |
3436 /* No default_conversion here. It causes trouble for ADDR_EXPR. */ | 3408 /* No default_conversion here. It causes trouble for ADDR_EXPR. */ |
3437 tree arg = xarg; | 3409 tree arg = xarg; |
3438 tree argtype = 0; | 3410 tree argtype = 0; |
3439 enum tree_code typecode; | 3411 enum tree_code typecode; |
3472 | 3444 |
3473 switch (code) | 3445 switch (code) |
3474 { | 3446 { |
3475 case CONVERT_EXPR: | 3447 case CONVERT_EXPR: |
3476 /* This is used for unary plus, because a CONVERT_EXPR | 3448 /* This is used for unary plus, because a CONVERT_EXPR |
3477 is enough to prevent anybody from looking inside for | 3449 is enough to prevent anybody from looking inside for |
3478 associativity, but won't generate any code. */ | 3450 associativity, but won't generate any code. */ |
3479 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE | 3451 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE |
3480 || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE | 3452 || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE |
3481 || typecode == VECTOR_TYPE)) | 3453 || typecode == VECTOR_TYPE)) |
3482 { | 3454 { |
3483 error_at (location, "wrong type argument to unary plus"); | 3455 error_at (location, "wrong type argument to unary plus"); |
3484 return error_mark_node; | 3456 return error_mark_node; |
3485 } | 3457 } |
3486 else if (!noconvert) | 3458 else if (!noconvert) |
3487 arg = default_conversion (arg); | 3459 arg = default_conversion (arg); |
3488 arg = non_lvalue_loc (location, arg); | 3460 arg = non_lvalue_loc (location, arg); |
3489 break; | 3461 break; |
3490 | 3462 |
3491 case NEGATE_EXPR: | 3463 case NEGATE_EXPR: |
3492 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE | 3464 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE |
3493 || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE | 3465 || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE |
3494 || typecode == VECTOR_TYPE)) | 3466 || typecode == VECTOR_TYPE)) |
3495 { | 3467 { |
3496 error_at (location, "wrong type argument to unary minus"); | 3468 error_at (location, "wrong type argument to unary minus"); |
3497 return error_mark_node; | 3469 return error_mark_node; |
3498 } | 3470 } |
3499 else if (!noconvert) | 3471 else if (!noconvert) |
3500 arg = default_conversion (arg); | 3472 arg = default_conversion (arg); |
3501 break; | 3473 break; |
3502 | 3474 |
3503 case BIT_NOT_EXPR: | 3475 case BIT_NOT_EXPR: |
3504 /* ~ works on integer types and non float vectors. */ | 3476 /* ~ works on integer types and non float vectors. */ |
3505 if (typecode == INTEGER_TYPE | 3477 if (typecode == INTEGER_TYPE |
3506 || (typecode == VECTOR_TYPE | 3478 || (typecode == VECTOR_TYPE |
3507 && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg)))) | 3479 && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg)))) |
3508 { | 3480 { |
3509 if (!noconvert) | 3481 if (!noconvert) |
3510 arg = default_conversion (arg); | 3482 arg = default_conversion (arg); |
3511 } | 3483 } |
3512 else if (typecode == COMPLEX_TYPE) | 3484 else if (typecode == COMPLEX_TYPE) |
3513 { | 3485 { |
3514 code = CONJ_EXPR; | 3486 code = CONJ_EXPR; |
3515 pedwarn (location, OPT_pedantic, | 3487 pedwarn (location, OPT_pedantic, |
3516 "ISO C does not support %<~%> for complex conjugation"); | 3488 "ISO C does not support %<~%> for complex conjugation"); |
3517 if (!noconvert) | 3489 if (!noconvert) |
3518 arg = default_conversion (arg); | 3490 arg = default_conversion (arg); |
3519 } | 3491 } |
3520 else | 3492 else |
3521 { | 3493 { |
3522 error_at (location, "wrong type argument to bit-complement"); | 3494 error_at (location, "wrong type argument to bit-complement"); |
3523 return error_mark_node; | 3495 return error_mark_node; |
3524 } | 3496 } |
3525 break; | 3497 break; |
3526 | 3498 |
3527 case ABS_EXPR: | 3499 case ABS_EXPR: |
3528 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE)) | 3500 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE)) |
3529 { | 3501 { |
3530 error_at (location, "wrong type argument to abs"); | 3502 error_at (location, "wrong type argument to abs"); |
3531 return error_mark_node; | 3503 return error_mark_node; |
3532 } | 3504 } |
3533 else if (!noconvert) | 3505 else if (!noconvert) |
3534 arg = default_conversion (arg); | 3506 arg = default_conversion (arg); |
3535 break; | 3507 break; |
3536 | 3508 |
3537 case CONJ_EXPR: | 3509 case CONJ_EXPR: |
3538 /* Conjugating a real value is a no-op, but allow it anyway. */ | 3510 /* Conjugating a real value is a no-op, but allow it anyway. */ |
3539 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE | 3511 if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE |
3540 || typecode == COMPLEX_TYPE)) | 3512 || typecode == COMPLEX_TYPE)) |
3541 { | 3513 { |
3542 error_at (location, "wrong type argument to conjugation"); | 3514 error_at (location, "wrong type argument to conjugation"); |
3543 return error_mark_node; | 3515 return error_mark_node; |
3544 } | 3516 } |
3545 else if (!noconvert) | 3517 else if (!noconvert) |
3546 arg = default_conversion (arg); | 3518 arg = default_conversion (arg); |
3547 break; | 3519 break; |
3548 | 3520 |
3549 case TRUTH_NOT_EXPR: | 3521 case TRUTH_NOT_EXPR: |
3550 if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE | 3522 if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE |
3551 && typecode != REAL_TYPE && typecode != POINTER_TYPE | 3523 && typecode != REAL_TYPE && typecode != POINTER_TYPE |
3552 && typecode != COMPLEX_TYPE) | 3524 && typecode != COMPLEX_TYPE) |
3553 { | 3525 { |
3554 error_at (location, | 3526 error_at (location, |
3555 "wrong type argument to unary exclamation mark"); | 3527 "wrong type argument to unary exclamation mark"); |
3556 return error_mark_node; | 3528 return error_mark_node; |
3557 } | 3529 } |
3558 arg = c_objc_common_truthvalue_conversion (location, arg); | 3530 arg = c_objc_common_truthvalue_conversion (location, arg); |
3559 ret = invert_truthvalue_loc (location, arg); | 3531 ret = invert_truthvalue_loc (location, arg); |
3560 /* If the TRUTH_NOT_EXPR has been folded, reset the location. */ | 3532 /* If the TRUTH_NOT_EXPR has been folded, reset the location. */ |
3561 if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret)) | 3533 if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret)) |
3562 location = EXPR_LOCATION (ret); | 3534 location = EXPR_LOCATION (ret); |
3563 goto return_build_unary_op; | 3535 goto return_build_unary_op; |
3564 | 3536 |
3565 case REALPART_EXPR: | 3537 case REALPART_EXPR: |
3566 case IMAGPART_EXPR: | 3538 case IMAGPART_EXPR: |
3567 ret = build_real_imag_expr (location, code, arg); | 3539 ret = build_real_imag_expr (location, code, arg); |
3568 if (ret == error_mark_node) | 3540 if (ret == error_mark_node) |
3569 return error_mark_node; | 3541 return error_mark_node; |
3570 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE) | 3542 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE) |
3571 eptype = TREE_TYPE (eptype); | 3543 eptype = TREE_TYPE (eptype); |
3572 goto return_build_unary_op; | 3544 goto return_build_unary_op; |
3573 | 3545 |
3574 case PREINCREMENT_EXPR: | 3546 case PREINCREMENT_EXPR: |
3575 case POSTINCREMENT_EXPR: | 3547 case POSTINCREMENT_EXPR: |
3576 case PREDECREMENT_EXPR: | 3548 case PREDECREMENT_EXPR: |
3577 case POSTDECREMENT_EXPR: | 3549 case POSTDECREMENT_EXPR: |
3578 | 3550 |
3579 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR) | 3551 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR) |
3580 { | 3552 { |
3581 tree inner = build_unary_op (location, code, | 3553 tree inner = build_unary_op (location, code, |
3582 C_MAYBE_CONST_EXPR_EXPR (arg), flag); | 3554 C_MAYBE_CONST_EXPR_EXPR (arg), flag); |
3583 if (inner == error_mark_node) | 3555 if (inner == error_mark_node) |
3584 return error_mark_node; | 3556 return error_mark_node; |
3585 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner), | 3557 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner), |
3586 C_MAYBE_CONST_EXPR_PRE (arg), inner); | 3558 C_MAYBE_CONST_EXPR_PRE (arg), inner); |
3587 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg)); | 3559 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg)); |
3588 C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1; | 3560 C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1; |
3589 goto return_build_unary_op; | 3561 goto return_build_unary_op; |
3590 } | 3562 } |
3591 | 3563 |
3592 /* Complain about anything that is not a true lvalue. In | 3564 /* Complain about anything that is not a true lvalue. In |
3593 Objective-C, skip this check for property_refs. */ | 3565 Objective-C, skip this check for property_refs. */ |
3594 if (!objc_is_property_ref (arg) | 3566 if (!objc_is_property_ref (arg) |
3595 && !lvalue_or_else (location, | 3567 && !lvalue_or_else (location, |
3598 ? lv_increment | 3570 ? lv_increment |
3599 : lv_decrement))) | 3571 : lv_decrement))) |
3600 return error_mark_node; | 3572 return error_mark_node; |
3601 | 3573 |
3602 if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE) | 3574 if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE) |
3603 { | 3575 { |
3604 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) | 3576 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) |
3605 warning_at (location, OPT_Wc___compat, | 3577 warning_at (location, OPT_Wc___compat, |
3606 "increment of enumeration value is invalid in C++"); | 3578 "increment of enumeration value is invalid in C++"); |
3607 else | 3579 else |
3608 warning_at (location, OPT_Wc___compat, | 3580 warning_at (location, OPT_Wc___compat, |
3609 "decrement of enumeration value is invalid in C++"); | 3581 "decrement of enumeration value is invalid in C++"); |
3610 } | 3582 } |
3611 | 3583 |
3612 /* Ensure the argument is fully folded inside any SAVE_EXPR. */ | 3584 /* Ensure the argument is fully folded inside any SAVE_EXPR. */ |
3613 arg = c_fully_fold (arg, false, NULL); | 3585 arg = c_fully_fold (arg, false, NULL); |
3614 | 3586 |
3615 /* Increment or decrement the real part of the value, | 3587 /* Increment or decrement the real part of the value, |
3616 and don't change the imaginary part. */ | 3588 and don't change the imaginary part. */ |
3617 if (typecode == COMPLEX_TYPE) | 3589 if (typecode == COMPLEX_TYPE) |
3618 { | 3590 { |
3619 tree real, imag; | 3591 tree real, imag; |
3620 | 3592 |
3621 pedwarn (location, OPT_pedantic, | 3593 pedwarn (location, OPT_pedantic, |
3622 "ISO C does not support %<++%> and %<--%> on complex types"); | 3594 "ISO C does not support %<++%> and %<--%> on complex types"); |
3623 | 3595 |
3624 arg = stabilize_reference (arg); | 3596 arg = stabilize_reference (arg); |
3625 real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg, 1); | 3597 real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg, 1); |
3626 imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg, 1); | 3598 imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg, 1); |
3627 real = build_unary_op (EXPR_LOCATION (arg), code, real, 1); | 3599 real = build_unary_op (EXPR_LOCATION (arg), code, real, 1); |
3628 if (real == error_mark_node || imag == error_mark_node) | 3600 if (real == error_mark_node || imag == error_mark_node) |
3629 return error_mark_node; | 3601 return error_mark_node; |
3630 ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg), | 3602 ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg), |
3631 real, imag); | 3603 real, imag); |
3632 goto return_build_unary_op; | 3604 goto return_build_unary_op; |
3633 } | 3605 } |
3634 | 3606 |
3635 /* Report invalid types. */ | 3607 /* Report invalid types. */ |
3636 | 3608 |
3637 if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE | 3609 if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE |
3638 && typecode != INTEGER_TYPE && typecode != REAL_TYPE) | 3610 && typecode != INTEGER_TYPE && typecode != REAL_TYPE) |
3639 { | 3611 { |
3640 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) | 3612 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) |
3641 error_at (location, "wrong type argument to increment"); | 3613 error_at (location, "wrong type argument to increment"); |
3642 else | 3614 else |
3643 error_at (location, "wrong type argument to decrement"); | 3615 error_at (location, "wrong type argument to decrement"); |
3644 | 3616 |
3645 return error_mark_node; | 3617 return error_mark_node; |
3646 } | 3618 } |
3647 | 3619 |
3648 { | 3620 { |
3649 tree inc; | 3621 tree inc; |
3650 | 3622 |
3651 argtype = TREE_TYPE (arg); | 3623 argtype = TREE_TYPE (arg); |
3739 | 3711 |
3740 case ADDR_EXPR: | 3712 case ADDR_EXPR: |
3741 /* Note that this operation never does default_conversion. */ | 3713 /* Note that this operation never does default_conversion. */ |
3742 | 3714 |
3743 /* The operand of unary '&' must be an lvalue (which excludes | 3715 /* The operand of unary '&' must be an lvalue (which excludes |
3744 expressions of type void), or, in C99, the result of a [] or | 3716 expressions of type void), or, in C99, the result of a [] or |
3745 unary '*' operator. */ | 3717 unary '*' operator. */ |
3746 if (VOID_TYPE_P (TREE_TYPE (arg)) | 3718 if (VOID_TYPE_P (TREE_TYPE (arg)) |
3747 && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED | 3719 && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED |
3748 && (TREE_CODE (arg) != INDIRECT_REF | 3720 && (TREE_CODE (arg) != INDIRECT_REF |
3749 || !flag_isoc99)) | 3721 || !flag_isoc99)) |
3750 pedwarn (location, 0, "taking address of expression of type %<void%>"); | 3722 pedwarn (location, 0, "taking address of expression of type %<void%>"); |
3751 | 3723 |
3752 /* Let &* cancel out to simplify resulting code. */ | 3724 /* Let &* cancel out to simplify resulting code. */ |
3753 if (TREE_CODE (arg) == INDIRECT_REF) | 3725 if (TREE_CODE (arg) == INDIRECT_REF) |
3754 { | 3726 { |
3755 /* Don't let this be an lvalue. */ | 3727 /* Don't let this be an lvalue. */ |
3756 if (lvalue_p (TREE_OPERAND (arg, 0))) | 3728 if (lvalue_p (TREE_OPERAND (arg, 0))) |
3757 return non_lvalue_loc (location, TREE_OPERAND (arg, 0)); | 3729 return non_lvalue_loc (location, TREE_OPERAND (arg, 0)); |
3758 ret = TREE_OPERAND (arg, 0); | 3730 ret = TREE_OPERAND (arg, 0); |
3759 goto return_build_unary_op; | 3731 goto return_build_unary_op; |
3760 } | 3732 } |
3761 | 3733 |
3762 /* For &x[y], return x+y */ | 3734 /* For &x[y], return x+y */ |
3763 if (TREE_CODE (arg) == ARRAY_REF) | 3735 if (TREE_CODE (arg) == ARRAY_REF) |
3764 { | 3736 { |
3765 tree op0 = TREE_OPERAND (arg, 0); | 3737 tree op0 = TREE_OPERAND (arg, 0); |
3766 if (!c_mark_addressable (op0)) | 3738 if (!c_mark_addressable (op0)) |
3767 return error_mark_node; | 3739 return error_mark_node; |
3768 return build_binary_op (location, PLUS_EXPR, | 3740 return build_binary_op (location, PLUS_EXPR, |
3769 (TREE_CODE (TREE_TYPE (op0)) == ARRAY_TYPE | 3741 (TREE_CODE (TREE_TYPE (op0)) == ARRAY_TYPE |
3770 ? array_to_pointer_conversion (location, | 3742 ? array_to_pointer_conversion (location, |
3771 op0) | 3743 op0) |
3772 : op0), | 3744 : op0), |
3773 TREE_OPERAND (arg, 1), 1); | 3745 TREE_OPERAND (arg, 1), 1); |
3774 } | 3746 } |
3775 | 3747 |
3776 /* Anything not already handled and not a true memory reference | 3748 /* Anything not already handled and not a true memory reference |
3777 or a non-lvalue array is an error. */ | 3749 or a non-lvalue array is an error. */ |
3778 else if (typecode != FUNCTION_TYPE && !flag | 3750 else if (typecode != FUNCTION_TYPE && !flag |
3779 && !lvalue_or_else (location, arg, lv_addressof)) | 3751 && !lvalue_or_else (location, arg, lv_addressof)) |
3780 return error_mark_node; | 3752 return error_mark_node; |
3781 | 3753 |
3782 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify | 3754 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify |
3783 folding later. */ | 3755 folding later. */ |
3784 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR) | 3756 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR) |
3785 { | 3757 { |
3786 tree inner = build_unary_op (location, code, | 3758 tree inner = build_unary_op (location, code, |
3787 C_MAYBE_CONST_EXPR_EXPR (arg), flag); | 3759 C_MAYBE_CONST_EXPR_EXPR (arg), flag); |
3788 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner), | 3760 ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner), |
3789 C_MAYBE_CONST_EXPR_PRE (arg), inner); | 3761 C_MAYBE_CONST_EXPR_PRE (arg), inner); |
3790 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg)); | 3762 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg)); |
3791 C_MAYBE_CONST_EXPR_NON_CONST (ret) | 3763 C_MAYBE_CONST_EXPR_NON_CONST (ret) |
3792 = C_MAYBE_CONST_EXPR_NON_CONST (arg); | 3764 = C_MAYBE_CONST_EXPR_NON_CONST (arg); |
3793 goto return_build_unary_op; | 3765 goto return_build_unary_op; |
3794 } | 3766 } |
3795 | 3767 |
3796 /* Ordinary case; arg is a COMPONENT_REF or a decl. */ | 3768 /* Ordinary case; arg is a COMPONENT_REF or a decl. */ |
3797 argtype = TREE_TYPE (arg); | 3769 argtype = TREE_TYPE (arg); |
3798 | 3770 |
3799 /* If the lvalue is const or volatile, merge that into the type | 3771 /* If the lvalue is const or volatile, merge that into the type |
3815 | 3787 |
3816 argtype = c_build_qualified_type (argtype, quals); | 3788 argtype = c_build_qualified_type (argtype, quals); |
3817 } | 3789 } |
3818 | 3790 |
3819 if (!c_mark_addressable (arg)) | 3791 if (!c_mark_addressable (arg)) |
3820 return error_mark_node; | 3792 return error_mark_node; |
3821 | 3793 |
3822 gcc_assert (TREE_CODE (arg) != COMPONENT_REF | 3794 gcc_assert (TREE_CODE (arg) != COMPONENT_REF |
3823 || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1))); | 3795 || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1))); |
3824 | 3796 |
3825 argtype = build_pointer_type (argtype); | 3797 argtype = build_pointer_type (argtype); |
3826 | 3798 |
3827 /* ??? Cope with user tricks that amount to offsetof. Delete this | 3799 /* ??? Cope with user tricks that amount to offsetof. Delete this |
3828 when we have proper support for integer constant expressions. */ | 3800 when we have proper support for integer constant expressions. */ |
3829 val = get_base_address (arg); | 3801 val = get_base_address (arg); |
3830 if (val && TREE_CODE (val) == INDIRECT_REF | 3802 if (val && TREE_CODE (val) == INDIRECT_REF |
3831 && TREE_CONSTANT (TREE_OPERAND (val, 0))) | 3803 && TREE_CONSTANT (TREE_OPERAND (val, 0))) |
3832 { | 3804 { |
3833 tree op0 = fold_convert_loc (location, sizetype, | 3805 tree op0 = fold_convert_loc (location, sizetype, |
3834 fold_offsetof (arg, val)), op1; | 3806 fold_offsetof (arg, val)), op1; |
3835 | 3807 |
3836 op1 = fold_convert_loc (location, argtype, TREE_OPERAND (val, 0)); | 3808 op1 = fold_convert_loc (location, argtype, TREE_OPERAND (val, 0)); |
3837 ret = fold_build2_loc (location, POINTER_PLUS_EXPR, argtype, op1, op0); | 3809 ret = fold_build2_loc (location, POINTER_PLUS_EXPR, argtype, op1, op0); |
3838 goto return_build_unary_op; | 3810 goto return_build_unary_op; |
3839 } | 3811 } |
3840 | 3812 |
3841 val = build1 (ADDR_EXPR, argtype, arg); | 3813 val = build1 (ADDR_EXPR, argtype, arg); |
3842 | 3814 |
3843 ret = val; | 3815 ret = val; |
3844 goto return_build_unary_op; | 3816 goto return_build_unary_op; |
3849 | 3821 |
3850 if (argtype == 0) | 3822 if (argtype == 0) |
3851 argtype = TREE_TYPE (arg); | 3823 argtype = TREE_TYPE (arg); |
3852 if (TREE_CODE (arg) == INTEGER_CST) | 3824 if (TREE_CODE (arg) == INTEGER_CST) |
3853 ret = (require_constant_value | 3825 ret = (require_constant_value |
3854 ? fold_build1_initializer_loc (location, code, argtype, arg) | 3826 ? fold_build1_initializer_loc (location, code, argtype, arg) |
3855 : fold_build1_loc (location, code, argtype, arg)); | 3827 : fold_build1_loc (location, code, argtype, arg)); |
3856 else | 3828 else |
3857 ret = build1 (code, argtype, arg); | 3829 ret = build1 (code, argtype, arg); |
3858 return_build_unary_op: | 3830 return_build_unary_op: |
3859 gcc_assert (ret != error_mark_node); | 3831 gcc_assert (ret != error_mark_node); |
3860 if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) | 3832 if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) |
3896 case VAR_DECL: | 3868 case VAR_DECL: |
3897 case PARM_DECL: | 3869 case PARM_DECL: |
3898 case RESULT_DECL: | 3870 case RESULT_DECL: |
3899 case ERROR_MARK: | 3871 case ERROR_MARK: |
3900 return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE | 3872 return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE |
3901 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE); | 3873 && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE); |
3902 | 3874 |
3903 case BIND_EXPR: | 3875 case BIND_EXPR: |
3904 return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE; | 3876 return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE; |
3905 | 3877 |
3906 default: | 3878 default: |
3907 return 0; | 3879 return 0; |
3908 } | 3880 } |
3909 } | 3881 } |
3910 | 3882 |
3911 /* Give a warning for storing in something that is read-only in GCC | 3883 /* Give a warning for storing in something that is read-only in GCC |
3912 terms but not const in ISO C terms. */ | 3884 terms but not const in ISO C terms. */ |
3913 | 3885 |
3914 static void | 3886 static void |
3915 readonly_warning (tree arg, enum lvalue_use use) | 3887 readonly_warning (tree arg, enum lvalue_use use) |
3959 | 3931 |
3960 while (1) | 3932 while (1) |
3961 switch (TREE_CODE (x)) | 3933 switch (TREE_CODE (x)) |
3962 { | 3934 { |
3963 case COMPONENT_REF: | 3935 case COMPONENT_REF: |
3964 if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1))) | 3936 if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1))) |
3965 { | 3937 { |
3966 error | 3938 error |
3967 ("cannot take address of bit-field %qD", TREE_OPERAND (x, 1)); | 3939 ("cannot take address of bit-field %qD", TREE_OPERAND (x, 1)); |
3968 return false; | 3940 return false; |
3969 } | 3941 } |
3970 | 3942 |
3971 /* ... fall through ... */ | 3943 /* ... fall through ... */ |
3972 | 3944 |
3973 case ADDR_EXPR: | 3945 case ADDR_EXPR: |
3974 case ARRAY_REF: | 3946 case ARRAY_REF: |
3975 case REALPART_EXPR: | 3947 case REALPART_EXPR: |
3976 case IMAGPART_EXPR: | 3948 case IMAGPART_EXPR: |
3977 x = TREE_OPERAND (x, 0); | 3949 x = TREE_OPERAND (x, 0); |
3978 break; | 3950 break; |
3979 | 3951 |
3980 case COMPOUND_LITERAL_EXPR: | 3952 case COMPOUND_LITERAL_EXPR: |
3981 case CONSTRUCTOR: | 3953 case CONSTRUCTOR: |
3982 TREE_ADDRESSABLE (x) = 1; | 3954 TREE_ADDRESSABLE (x) = 1; |
3983 return true; | 3955 return true; |
3984 | 3956 |
3985 case VAR_DECL: | 3957 case VAR_DECL: |
3986 case CONST_DECL: | 3958 case CONST_DECL: |
3987 case PARM_DECL: | 3959 case PARM_DECL: |
3988 case RESULT_DECL: | 3960 case RESULT_DECL: |
3989 if (C_DECL_REGISTER (x) | 3961 if (C_DECL_REGISTER (x) |
3990 && DECL_NONLOCAL (x)) | 3962 && DECL_NONLOCAL (x)) |
3991 { | 3963 { |
3992 if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x)) | 3964 if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x)) |
3993 { | 3965 { |
3994 error | 3966 error |
3995 ("global register variable %qD used in nested function", x); | 3967 ("global register variable %qD used in nested function", x); |
3996 return false; | 3968 return false; |
3997 } | 3969 } |
3998 pedwarn (input_location, 0, "register variable %qD used in nested function", x); | 3970 pedwarn (input_location, 0, "register variable %qD used in nested function", x); |
3999 } | 3971 } |
4000 else if (C_DECL_REGISTER (x)) | 3972 else if (C_DECL_REGISTER (x)) |
4001 { | 3973 { |
4002 if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x)) | 3974 if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x)) |
4003 error ("address of global register variable %qD requested", x); | 3975 error ("address of global register variable %qD requested", x); |
4004 else | 3976 else |
4005 error ("address of register variable %qD requested", x); | 3977 error ("address of register variable %qD requested", x); |
4006 return false; | 3978 return false; |
4007 } | 3979 } |
4008 | 3980 |
4009 /* drops in */ | 3981 /* drops in */ |
4010 case FUNCTION_DECL: | 3982 case FUNCTION_DECL: |
4011 TREE_ADDRESSABLE (x) = 1; | 3983 TREE_ADDRESSABLE (x) = 1; |
4012 /* drops out */ | 3984 /* drops out */ |
4013 default: | 3985 default: |
4014 return true; | 3986 return true; |
4015 } | 3987 } |
4016 } | 3988 } |
4017 | 3989 |
4018 /* Convert EXPR to TYPE, warning about conversion problems with | 3990 /* Convert EXPR to TYPE, warning about conversion problems with |
4019 constants. SEMANTIC_TYPE is the type this conversion would use | 3991 constants. SEMANTIC_TYPE is the type this conversion would use |
4049 contain arbitrary operations not normally permitted in constant | 4021 contain arbitrary operations not normally permitted in constant |
4050 expressions. Set the location of the expression to LOC. */ | 4022 expressions. Set the location of the expression to LOC. */ |
4051 | 4023 |
4052 tree | 4024 tree |
4053 build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, | 4025 build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, |
4054 tree op1, tree op1_original_type, tree op2, | 4026 tree op1, tree op1_original_type, tree op2, |
4055 tree op2_original_type) | 4027 tree op2_original_type) |
4056 { | 4028 { |
4057 tree type1; | 4029 tree type1; |
4058 tree type2; | 4030 tree type2; |
4059 enum tree_code code1; | 4031 enum tree_code code1; |
4060 enum tree_code code2; | 4032 enum tree_code code2; |
4101 } | 4073 } |
4102 | 4074 |
4103 if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR | 4075 if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR |
4104 || TREE_CODE (op2) == EXCESS_PRECISION_EXPR) | 4076 || TREE_CODE (op2) == EXCESS_PRECISION_EXPR) |
4105 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE | 4077 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE |
4106 || code1 == COMPLEX_TYPE) | 4078 || code1 == COMPLEX_TYPE) |
4107 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE | 4079 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE |
4108 || code2 == COMPLEX_TYPE)) | 4080 || code2 == COMPLEX_TYPE)) |
4109 { | 4081 { |
4110 semantic_result_type = c_common_type (type1, type2); | 4082 semantic_result_type = c_common_type (type1, type2); |
4111 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR) | 4083 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR) |
4112 { | 4084 { |
4113 op1 = TREE_OPERAND (op1, 0); | 4085 op1 = TREE_OPERAND (op1, 0); |
4114 type1 = TREE_TYPE (op1); | 4086 type1 = TREE_TYPE (op1); |
4115 gcc_assert (TREE_CODE (type1) == code1); | 4087 gcc_assert (TREE_CODE (type1) == code1); |
4116 } | 4088 } |
4117 if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR) | 4089 if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR) |
4118 { | 4090 { |
4119 op2 = TREE_OPERAND (op2, 0); | 4091 op2 = TREE_OPERAND (op2, 0); |
4120 type2 = TREE_TYPE (op2); | 4092 type2 = TREE_TYPE (op2); |
4121 gcc_assert (TREE_CODE (type2) == code2); | 4093 gcc_assert (TREE_CODE (type2) == code2); |
4122 } | 4094 } |
4123 } | 4095 } |
4124 | 4096 |
4125 if (warn_cxx_compat) | 4097 if (warn_cxx_compat) |
4126 { | 4098 { |
4127 tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1); | 4099 tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1); |
4128 tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2); | 4100 tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2); |
4129 | 4101 |
4130 if (TREE_CODE (t1) == ENUMERAL_TYPE | 4102 if (TREE_CODE (t1) == ENUMERAL_TYPE |
4131 && TREE_CODE (t2) == ENUMERAL_TYPE | 4103 && TREE_CODE (t2) == ENUMERAL_TYPE |
4132 && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2)) | 4104 && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2)) |
4133 warning_at (colon_loc, OPT_Wc___compat, | 4105 warning_at (colon_loc, OPT_Wc___compat, |
4134 ("different enum types in conditional is " | 4106 ("different enum types in conditional is " |
4135 "invalid in C++: %qT vs %qT"), | 4107 "invalid in C++: %qT vs %qT"), |
4136 t1, t2); | 4108 t1, t2); |
4137 } | 4109 } |
4138 | 4110 |
4139 /* Quickly detect the usual case where op1 and op2 have the same type | 4111 /* Quickly detect the usual case where op1 and op2 have the same type |
4140 after promotion. */ | 4112 after promotion. */ |
4141 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)) | 4113 if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)) |
4142 { | 4114 { |
4143 if (type1 == type2) | 4115 if (type1 == type2) |
4144 result_type = type1; | 4116 result_type = type1; |
4145 else | 4117 else |
4146 result_type = TYPE_MAIN_VARIANT (type1); | 4118 result_type = TYPE_MAIN_VARIANT (type1); |
4147 } | 4119 } |
4148 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE | 4120 else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE |
4149 || code1 == COMPLEX_TYPE) | 4121 || code1 == COMPLEX_TYPE) |
4150 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE | 4122 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE |
4151 || code2 == COMPLEX_TYPE)) | 4123 || code2 == COMPLEX_TYPE)) |
4152 { | 4124 { |
4153 result_type = c_common_type (type1, type2); | 4125 result_type = c_common_type (type1, type2); |
4154 do_warn_double_promotion (result_type, type1, type2, | 4126 do_warn_double_promotion (result_type, type1, type2, |
4155 "implicit conversion from %qT to %qT to " | 4127 "implicit conversion from %qT to %qT to " |
4156 "match other result of conditional", | 4128 "match other result of conditional", |
4157 colon_loc); | 4129 colon_loc); |
4158 | 4130 |
4159 /* If -Wsign-compare, warn here if type1 and type2 have | 4131 /* If -Wsign-compare, warn here if type1 and type2 have |
4160 different signedness. We'll promote the signed to unsigned | 4132 different signedness. We'll promote the signed to unsigned |
4161 and later code won't know it used to be different. | 4133 and later code won't know it used to be different. |
4162 Do this check on the original types, so that explicit casts | 4134 Do this check on the original types, so that explicit casts |
4163 will be considered, but default promotions won't. */ | 4135 will be considered, but default promotions won't. */ |
4164 if (c_inhibit_evaluation_warnings == 0) | 4136 if (c_inhibit_evaluation_warnings == 0) |
4165 { | 4137 { |
4166 int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1)); | 4138 int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1)); |
4167 int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2)); | 4139 int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2)); |
4168 | 4140 |
4169 if (unsigned_op1 ^ unsigned_op2) | 4141 if (unsigned_op1 ^ unsigned_op2) |
4170 { | 4142 { |
4171 bool ovf; | 4143 bool ovf; |
4172 | 4144 |
4173 /* Do not warn if the result type is signed, since the | 4145 /* Do not warn if the result type is signed, since the |
4174 signed type will only be chosen if it can represent | 4146 signed type will only be chosen if it can represent |
4175 all the values of the unsigned type. */ | 4147 all the values of the unsigned type. */ |
4176 if (!TYPE_UNSIGNED (result_type)) | 4148 if (!TYPE_UNSIGNED (result_type)) |
4177 /* OK */; | 4149 /* OK */; |
4178 else | 4150 else |
4179 { | 4151 { |
4180 bool op1_maybe_const = true; | 4152 bool op1_maybe_const = true; |
4181 bool op2_maybe_const = true; | 4153 bool op2_maybe_const = true; |
4182 | 4154 |
4183 /* Do not warn if the signed quantity is an | 4155 /* Do not warn if the signed quantity is an |
4184 unsuffixed integer literal (or some static | 4156 unsuffixed integer literal (or some static |
4185 constant expression involving such literals) and | 4157 constant expression involving such literals) and |
4186 it is non-negative. This warning requires the | 4158 it is non-negative. This warning requires the |
4187 operands to be folded for best results, so do | 4159 operands to be folded for best results, so do |
4188 that folding in this case even without | 4160 that folding in this case even without |
4189 warn_sign_compare to avoid warning options | 4161 warn_sign_compare to avoid warning options |
4190 possibly affecting code generation. */ | 4162 possibly affecting code generation. */ |
4191 c_inhibit_evaluation_warnings | 4163 c_inhibit_evaluation_warnings |
4192 += (ifexp == truthvalue_false_node); | 4164 += (ifexp == truthvalue_false_node); |
4193 op1 = c_fully_fold (op1, require_constant_value, | 4165 op1 = c_fully_fold (op1, require_constant_value, |
4194 &op1_maybe_const); | 4166 &op1_maybe_const); |
4195 c_inhibit_evaluation_warnings | 4167 c_inhibit_evaluation_warnings |
4196 -= (ifexp == truthvalue_false_node); | 4168 -= (ifexp == truthvalue_false_node); |
4197 | 4169 |
4198 c_inhibit_evaluation_warnings | 4170 c_inhibit_evaluation_warnings |
4199 += (ifexp == truthvalue_true_node); | 4171 += (ifexp == truthvalue_true_node); |
4200 op2 = c_fully_fold (op2, require_constant_value, | 4172 op2 = c_fully_fold (op2, require_constant_value, |
4201 &op2_maybe_const); | 4173 &op2_maybe_const); |
4202 c_inhibit_evaluation_warnings | 4174 c_inhibit_evaluation_warnings |
4203 -= (ifexp == truthvalue_true_node); | 4175 -= (ifexp == truthvalue_true_node); |
4204 | 4176 |
4205 if (warn_sign_compare) | 4177 if (warn_sign_compare) |
4206 { | 4178 { |
4207 if ((unsigned_op2 | 4179 if ((unsigned_op2 |
4208 && tree_expr_nonnegative_warnv_p (op1, &ovf)) | 4180 && tree_expr_nonnegative_warnv_p (op1, &ovf)) |
4209 || (unsigned_op1 | 4181 || (unsigned_op1 |
4210 && tree_expr_nonnegative_warnv_p (op2, &ovf))) | 4182 && tree_expr_nonnegative_warnv_p (op2, &ovf))) |
4211 /* OK */; | 4183 /* OK */; |
4212 else | 4184 else |
4213 warning_at (colon_loc, OPT_Wsign_compare, | 4185 warning_at (colon_loc, OPT_Wsign_compare, |
4214 ("signed and unsigned type in " | 4186 ("signed and unsigned type in " |
4215 "conditional expression")); | 4187 "conditional expression")); |
4216 } | 4188 } |
4217 if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST) | 4189 if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST) |
4218 op1 = c_wrap_maybe_const (op1, !op1_maybe_const); | 4190 op1 = c_wrap_maybe_const (op1, !op1_maybe_const); |
4219 if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST) | 4191 if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST) |
4220 op2 = c_wrap_maybe_const (op2, !op2_maybe_const); | 4192 op2 = c_wrap_maybe_const (op2, !op2_maybe_const); |
4221 } | 4193 } |
4222 } | 4194 } |
4223 } | 4195 } |
4224 } | 4196 } |
4225 else if (code1 == VOID_TYPE || code2 == VOID_TYPE) | 4197 else if (code1 == VOID_TYPE || code2 == VOID_TYPE) |
4226 { | 4198 { |
4227 if (code1 != VOID_TYPE || code2 != VOID_TYPE) | 4199 if (code1 != VOID_TYPE || code2 != VOID_TYPE) |
4228 pedwarn (colon_loc, OPT_pedantic, | 4200 pedwarn (colon_loc, OPT_pedantic, |
4229 "ISO C forbids conditional expr with only one void side"); | 4201 "ISO C forbids conditional expr with only one void side"); |
4230 result_type = void_type_node; | 4202 result_type = void_type_node; |
4231 } | 4203 } |
4232 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE) | 4204 else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE) |
4233 { | 4205 { |
4234 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1)); | 4206 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1)); |
4235 addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2)); | 4207 addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2)); |
4236 addr_space_t as_common; | 4208 addr_space_t as_common; |
4237 | 4209 |
4238 if (comp_target_types (colon_loc, type1, type2)) | 4210 if (comp_target_types (colon_loc, type1, type2)) |
4239 result_type = common_pointer_type (type1, type2); | 4211 result_type = common_pointer_type (type1, type2); |
4240 else if (null_pointer_constant_p (orig_op1)) | 4212 else if (null_pointer_constant_p (orig_op1)) |
4241 result_type = type2; | 4213 result_type = type2; |
4242 else if (null_pointer_constant_p (orig_op2)) | 4214 else if (null_pointer_constant_p (orig_op2)) |
4243 result_type = type1; | 4215 result_type = type1; |
4244 else if (!addr_space_superset (as1, as2, &as_common)) | 4216 else if (!addr_space_superset (as1, as2, &as_common)) |
4245 { | 4217 { |
4246 error_at (colon_loc, "pointers to disjoint address spaces " | 4218 error_at (colon_loc, "pointers to disjoint address spaces " |
4247 "used in conditional expression"); | 4219 "used in conditional expression"); |
4248 return error_mark_node; | 4220 return error_mark_node; |
4249 } | 4221 } |
4250 else if (VOID_TYPE_P (TREE_TYPE (type1))) | 4222 else if (VOID_TYPE_P (TREE_TYPE (type1))) |
4251 { | 4223 { |
4252 if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE) | 4224 if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE) |
4253 pedwarn (colon_loc, OPT_pedantic, | 4225 pedwarn (colon_loc, OPT_pedantic, |
4254 "ISO C forbids conditional expr between " | 4226 "ISO C forbids conditional expr between " |
4255 "%<void *%> and function pointer"); | 4227 "%<void *%> and function pointer"); |
4256 result_type = build_pointer_type (qualify_type (TREE_TYPE (type1), | 4228 result_type = build_pointer_type (qualify_type (TREE_TYPE (type1), |
4257 TREE_TYPE (type2))); | 4229 TREE_TYPE (type2))); |
4258 } | 4230 } |
4259 else if (VOID_TYPE_P (TREE_TYPE (type2))) | 4231 else if (VOID_TYPE_P (TREE_TYPE (type2))) |
4260 { | 4232 { |
4261 if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE) | 4233 if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE) |
4262 pedwarn (colon_loc, OPT_pedantic, | 4234 pedwarn (colon_loc, OPT_pedantic, |
4263 "ISO C forbids conditional expr between " | 4235 "ISO C forbids conditional expr between " |
4279 } | 4251 } |
4280 } | 4252 } |
4281 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE) | 4253 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE) |
4282 { | 4254 { |
4283 if (!null_pointer_constant_p (orig_op2)) | 4255 if (!null_pointer_constant_p (orig_op2)) |
4284 pedwarn (colon_loc, 0, | 4256 pedwarn (colon_loc, 0, |
4285 "pointer/integer type mismatch in conditional expression"); | 4257 "pointer/integer type mismatch in conditional expression"); |
4286 else | 4258 else |
4287 { | 4259 { |
4288 op2 = null_pointer_node; | 4260 op2 = null_pointer_node; |
4289 } | 4261 } |
4290 result_type = type1; | 4262 result_type = type1; |
4291 } | 4263 } |
4292 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE) | 4264 else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE) |
4293 { | 4265 { |
4294 if (!null_pointer_constant_p (orig_op1)) | 4266 if (!null_pointer_constant_p (orig_op1)) |
4295 pedwarn (colon_loc, 0, | 4267 pedwarn (colon_loc, 0, |
4296 "pointer/integer type mismatch in conditional expression"); | 4268 "pointer/integer type mismatch in conditional expression"); |
4297 else | 4269 else |
4298 { | 4270 { |
4299 op1 = null_pointer_node; | 4271 op1 = null_pointer_node; |
4300 } | 4272 } |
4301 result_type = type2; | 4273 result_type = type2; |
4302 } | 4274 } |
4303 | 4275 |
4304 if (!result_type) | 4276 if (!result_type) |
4305 { | 4277 { |
4306 if (flag_cond_mismatch) | 4278 if (flag_cond_mismatch) |
4307 result_type = void_type_node; | 4279 result_type = void_type_node; |
4308 else | 4280 else |
4309 { | 4281 { |
4310 error_at (colon_loc, "type mismatch in conditional expression"); | 4282 error_at (colon_loc, "type mismatch in conditional expression"); |
4311 return error_mark_node; | 4283 return error_mark_node; |
4312 } | 4284 } |
4313 } | 4285 } |
4314 | 4286 |
4315 /* Merge const and volatile flags of the incoming types. */ | 4287 /* Merge const and volatile flags of the incoming types. */ |
4316 result_type | 4288 result_type |
4317 = build_type_variant (result_type, | 4289 = build_type_variant (result_type, |
4318 TYPE_READONLY (type1) || TYPE_READONLY (type2), | 4290 TYPE_READONLY (type1) || TYPE_READONLY (type2), |
4319 TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2)); | 4291 TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2)); |
4320 | 4292 |
4321 op1 = ep_convert_and_check (result_type, op1, semantic_result_type); | 4293 op1 = ep_convert_and_check (result_type, op1, semantic_result_type); |
4322 op2 = ep_convert_and_check (result_type, op2, semantic_result_type); | 4294 op2 = ep_convert_and_check (result_type, op2, semantic_result_type); |
4323 | 4295 |
4324 if (ifexp_bcp && ifexp == truthvalue_true_node) | 4296 if (ifexp_bcp && ifexp == truthvalue_true_node) |
4330 { | 4302 { |
4331 op1_int_operands = true; | 4303 op1_int_operands = true; |
4332 op2 = c_fully_fold (op2, require_constant_value, NULL); | 4304 op2 = c_fully_fold (op2, require_constant_value, NULL); |
4333 } | 4305 } |
4334 int_const = int_operands = (ifexp_int_operands | 4306 int_const = int_operands = (ifexp_int_operands |
4335 && op1_int_operands | 4307 && op1_int_operands |
4336 && op2_int_operands); | 4308 && op2_int_operands); |
4337 if (int_operands) | 4309 if (int_operands) |
4338 { | 4310 { |
4339 int_const = ((ifexp == truthvalue_true_node | 4311 int_const = ((ifexp == truthvalue_true_node |
4340 && TREE_CODE (orig_op1) == INTEGER_CST | 4312 && TREE_CODE (orig_op1) == INTEGER_CST |
4341 && !TREE_OVERFLOW (orig_op1)) | 4313 && !TREE_OVERFLOW (orig_op1)) |
4342 || (ifexp == truthvalue_false_node | 4314 || (ifexp == truthvalue_false_node |
4343 && TREE_CODE (orig_op2) == INTEGER_CST | 4315 && TREE_CODE (orig_op2) == INTEGER_CST |
4344 && !TREE_OVERFLOW (orig_op2))); | 4316 && !TREE_OVERFLOW (orig_op2))); |
4345 } | 4317 } |
4346 if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST)) | 4318 if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST)) |
4347 ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2); | 4319 ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2); |
4348 else | 4320 else |
4349 { | 4321 { |
4350 ret = build3 (COND_EXPR, result_type, ifexp, op1, op2); | 4322 ret = build3 (COND_EXPR, result_type, ifexp, op1, op2); |
4351 if (int_operands) | 4323 if (int_operands) |
4352 ret = note_integer_operands (ret); | 4324 ret = note_integer_operands (ret); |
4353 } | 4325 } |
4354 if (semantic_result_type) | 4326 if (semantic_result_type) |
4355 ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret); | 4327 ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret); |
4356 | 4328 |
4357 protected_set_expr_location (ret, colon_loc); | 4329 protected_set_expr_location (ret, colon_loc); |
4386 } | 4358 } |
4387 | 4359 |
4388 if (!TREE_SIDE_EFFECTS (expr1)) | 4360 if (!TREE_SIDE_EFFECTS (expr1)) |
4389 { | 4361 { |
4390 /* The left-hand operand of a comma expression is like an expression | 4362 /* The left-hand operand of a comma expression is like an expression |
4391 statement: with -Wunused, we should warn if it doesn't have | 4363 statement: with -Wunused, we should warn if it doesn't have |
4392 any side-effects, unless it was explicitly cast to (void). */ | 4364 any side-effects, unless it was explicitly cast to (void). */ |
4393 if (warn_unused_value) | 4365 if (warn_unused_value) |
4394 { | 4366 { |
4395 if (VOID_TYPE_P (TREE_TYPE (expr1)) | 4367 if (VOID_TYPE_P (TREE_TYPE (expr1)) |
4396 && CONVERT_EXPR_P (expr1)) | 4368 && CONVERT_EXPR_P (expr1)) |
4397 ; /* (void) a, b */ | 4369 ; /* (void) a, b */ |
4398 else if (VOID_TYPE_P (TREE_TYPE (expr1)) | 4370 else if (VOID_TYPE_P (TREE_TYPE (expr1)) |
4399 && TREE_CODE (expr1) == COMPOUND_EXPR | 4371 && TREE_CODE (expr1) == COMPOUND_EXPR |
4400 && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1))) | 4372 && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1))) |
4401 ; /* (void) a, (void) b, c */ | 4373 ; /* (void) a, (void) b, c */ |
4402 else | 4374 else |
4403 warning_at (loc, OPT_Wunused_value, | 4375 warning_at (loc, OPT_Wunused_value, |
4404 "left-hand operand of comma expression has no effect"); | 4376 "left-hand operand of comma expression has no effect"); |
4405 } | 4377 } |
4406 } | 4378 } |
4407 | 4379 |
4408 /* With -Wunused, we should also warn if the left-hand operand does have | 4380 /* With -Wunused, we should also warn if the left-hand operand does have |
4409 side-effects, but computes a value which is not used. For example, in | 4381 side-effects, but computes a value which is not used. For example, in |
4410 `foo() + bar(), baz()' the result of the `+' operator is not used, | 4382 `foo() + bar(), baz()' the result of the `+' operator is not used, |
4453 { | 4425 { |
4454 in_otype = TREE_TYPE (in_otype); | 4426 in_otype = TREE_TYPE (in_otype); |
4455 in_type = TREE_TYPE (in_type); | 4427 in_type = TREE_TYPE (in_type); |
4456 | 4428 |
4457 /* GNU C allows cv-qualified function types. 'const' means the | 4429 /* GNU C allows cv-qualified function types. 'const' means the |
4458 function is very pure, 'volatile' means it can't return. We | 4430 function is very pure, 'volatile' means it can't return. We |
4459 need to warn when such qualifiers are added, not when they're | 4431 need to warn when such qualifiers are added, not when they're |
4460 taken away. */ | 4432 taken away. */ |
4461 if (TREE_CODE (in_otype) == FUNCTION_TYPE | 4433 if (TREE_CODE (in_otype) == FUNCTION_TYPE |
4462 && TREE_CODE (in_type) == FUNCTION_TYPE) | 4434 && TREE_CODE (in_type) == FUNCTION_TYPE) |
4463 added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type) | 4435 added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type) |
4464 & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype)); | 4436 & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype)); |
4465 else | 4437 else |
4466 discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype) | 4438 discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype) |
4467 & ~TYPE_QUALS_NO_ADDR_SPACE (in_type)); | 4439 & ~TYPE_QUALS_NO_ADDR_SPACE (in_type)); |
4468 } | 4440 } |
4469 while (TREE_CODE (in_type) == POINTER_TYPE | 4441 while (TREE_CODE (in_type) == POINTER_TYPE |
4470 && TREE_CODE (in_otype) == POINTER_TYPE); | 4442 && TREE_CODE (in_otype) == POINTER_TYPE); |
4471 | 4443 |
4472 if (added) | 4444 if (added) |
4473 warning_at (loc, OPT_Wcast_qual, | 4445 warning_at (loc, OPT_Wcast_qual, |
4474 "cast adds %q#v qualifier to function type", added); | 4446 "cast adds %q#v qualifier to function type", added); |
4475 | 4447 |
4516 "%qT to %qT must be %<const%> qualified", | 4488 "%qT to %qT must be %<const%> qualified", |
4517 otype, type); | 4489 otype, type); |
4518 break; | 4490 break; |
4519 } | 4491 } |
4520 if (is_const) | 4492 if (is_const) |
4521 is_const = TYPE_READONLY (in_type); | 4493 is_const = TYPE_READONLY (in_type); |
4522 } | 4494 } |
4523 while (TREE_CODE (in_type) == POINTER_TYPE); | 4495 while (TREE_CODE (in_type) == POINTER_TYPE); |
4524 } | 4496 } |
4525 | 4497 |
4526 /* Build an expression representing a cast to type TYPE of expression EXPR. | 4498 /* Build an expression representing a cast to type TYPE of expression EXPR. |
4561 | 4533 |
4562 if (!VOID_TYPE_P (type)) | 4534 if (!VOID_TYPE_P (type)) |
4563 { | 4535 { |
4564 value = require_complete_type (value); | 4536 value = require_complete_type (value); |
4565 if (value == error_mark_node) | 4537 if (value == error_mark_node) |
4566 return error_mark_node; | 4538 return error_mark_node; |
4567 } | 4539 } |
4568 | 4540 |
4569 if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value))) | 4541 if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value))) |
4570 { | 4542 { |
4571 if (TREE_CODE (type) == RECORD_TYPE | 4543 if (TREE_CODE (type) == RECORD_TYPE |
4572 || TREE_CODE (type) == UNION_TYPE) | 4544 || TREE_CODE (type) == UNION_TYPE) |
4573 pedwarn (loc, OPT_pedantic, | 4545 pedwarn (loc, OPT_pedantic, |
4574 "ISO C forbids casting nonscalar to the same type"); | 4546 "ISO C forbids casting nonscalar to the same type"); |
4575 } | 4547 } |
4576 else if (TREE_CODE (type) == UNION_TYPE) | 4548 else if (TREE_CODE (type) == UNION_TYPE) |
4577 { | 4549 { |
4578 tree field; | 4550 tree field; |
4579 | 4551 |
4604 else | 4576 else |
4605 { | 4577 { |
4606 tree otype, ovalue; | 4578 tree otype, ovalue; |
4607 | 4579 |
4608 if (type == void_type_node) | 4580 if (type == void_type_node) |
4609 { | 4581 { |
4610 tree t = build1 (CONVERT_EXPR, type, value); | 4582 tree t = build1 (CONVERT_EXPR, type, value); |
4611 SET_EXPR_LOCATION (t, loc); | 4583 SET_EXPR_LOCATION (t, loc); |
4612 return t; | 4584 return t; |
4613 } | 4585 } |
4614 | 4586 |
4615 otype = TREE_TYPE (value); | 4587 otype = TREE_TYPE (value); |
4616 | 4588 |
4617 /* Optionally warn about potentially worrisome casts. */ | 4589 /* Optionally warn about potentially worrisome casts. */ |
4618 if (warn_cast_qual | 4590 if (warn_cast_qual |
4619 && TREE_CODE (type) == POINTER_TYPE | 4591 && TREE_CODE (type) == POINTER_TYPE |
4620 && TREE_CODE (otype) == POINTER_TYPE) | 4592 && TREE_CODE (otype) == POINTER_TYPE) |
4621 handle_warn_cast_qual (loc, type, otype); | 4593 handle_warn_cast_qual (loc, type, otype); |
4622 | 4594 |
4623 /* Warn about conversions between pointers to disjoint | 4595 /* Warn about conversions between pointers to disjoint |
4624 address spaces. */ | 4596 address spaces. */ |
4625 if (TREE_CODE (type) == POINTER_TYPE | 4597 if (TREE_CODE (type) == POINTER_TYPE |
4626 && TREE_CODE (otype) == POINTER_TYPE | 4598 && TREE_CODE (otype) == POINTER_TYPE |
4627 && !null_pointer_constant_p (value)) | 4599 && !null_pointer_constant_p (value)) |
4628 { | 4600 { |
4629 addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type)); | 4601 addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type)); |
4630 addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype)); | 4602 addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype)); |
4631 addr_space_t as_common; | 4603 addr_space_t as_common; |
4632 | 4604 |
4633 if (!addr_space_superset (as_to, as_from, &as_common)) | 4605 if (!addr_space_superset (as_to, as_from, &as_common)) |
4634 { | 4606 { |
4635 if (ADDR_SPACE_GENERIC_P (as_from)) | 4607 if (ADDR_SPACE_GENERIC_P (as_from)) |
4636 warning_at (loc, 0, "cast to %s address space pointer " | 4608 warning_at (loc, 0, "cast to %s address space pointer " |
4637 "from disjoint generic address space pointer", | 4609 "from disjoint generic address space pointer", |
4638 c_addr_space_name (as_to)); | 4610 c_addr_space_name (as_to)); |
4639 | 4611 |
4640 else if (ADDR_SPACE_GENERIC_P (as_to)) | 4612 else if (ADDR_SPACE_GENERIC_P (as_to)) |
4641 warning_at (loc, 0, "cast to generic address space pointer " | 4613 warning_at (loc, 0, "cast to generic address space pointer " |
4642 "from disjoint %s address space pointer", | 4614 "from disjoint %s address space pointer", |
4643 c_addr_space_name (as_from)); | 4615 c_addr_space_name (as_from)); |
4644 | 4616 |
4645 else | 4617 else |
4646 warning_at (loc, 0, "cast to %s address space pointer " | 4618 warning_at (loc, 0, "cast to %s address space pointer " |
4647 "from disjoint %s address space pointer", | 4619 "from disjoint %s address space pointer", |
4648 c_addr_space_name (as_to), | 4620 c_addr_space_name (as_to), |
4649 c_addr_space_name (as_from)); | 4621 c_addr_space_name (as_from)); |
4650 } | 4622 } |
4651 } | 4623 } |
4652 | 4624 |
4653 /* Warn about possible alignment problems. */ | 4625 /* Warn about possible alignment problems. */ |
4654 if (STRICT_ALIGNMENT | 4626 if (STRICT_ALIGNMENT |
4655 && TREE_CODE (type) == POINTER_TYPE | 4627 && TREE_CODE (type) == POINTER_TYPE |
4656 && TREE_CODE (otype) == POINTER_TYPE | 4628 && TREE_CODE (otype) == POINTER_TYPE |
4657 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE | 4629 && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE |
4658 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE | 4630 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE |
4659 /* Don't warn about opaque types, where the actual alignment | 4631 /* Don't warn about opaque types, where the actual alignment |
4660 restriction is unknown. */ | 4632 restriction is unknown. */ |
4661 && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE | 4633 && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE |
4662 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE) | 4634 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE) |
4663 && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode) | 4635 && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode) |
4664 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype))) | 4636 && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype))) |
4665 warning_at (loc, OPT_Wcast_align, | 4637 warning_at (loc, OPT_Wcast_align, |
4666 "cast increases required alignment of target type"); | 4638 "cast increases required alignment of target type"); |
4667 | 4639 |
4668 if (TREE_CODE (type) == INTEGER_TYPE | 4640 if (TREE_CODE (type) == INTEGER_TYPE |
4669 && TREE_CODE (otype) == POINTER_TYPE | 4641 && TREE_CODE (otype) == POINTER_TYPE |
4670 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)) | 4642 && TYPE_PRECISION (type) != TYPE_PRECISION (otype)) |
4671 /* Unlike conversion of integers to pointers, where the | 4643 /* Unlike conversion of integers to pointers, where the |
4672 warning is disabled for converting constants because | 4644 warning is disabled for converting constants because |
4673 of cases such as SIG_*, warn about converting constant | 4645 of cases such as SIG_*, warn about converting constant |
4674 pointers to integers. In some cases it may cause unwanted | 4646 pointers to integers. In some cases it may cause unwanted |
4675 sign extension, and a warning is appropriate. */ | 4647 sign extension, and a warning is appropriate. */ |
4676 warning_at (loc, OPT_Wpointer_to_int_cast, | 4648 warning_at (loc, OPT_Wpointer_to_int_cast, |
4677 "cast from pointer to integer of different size"); | 4649 "cast from pointer to integer of different size"); |
4678 | 4650 |
4679 if (TREE_CODE (value) == CALL_EXPR | 4651 if (TREE_CODE (value) == CALL_EXPR |
4680 && TREE_CODE (type) != TREE_CODE (otype)) | 4652 && TREE_CODE (type) != TREE_CODE (otype)) |
4681 warning_at (loc, OPT_Wbad_function_cast, | 4653 warning_at (loc, OPT_Wbad_function_cast, |
4682 "cast from function call of type %qT " | 4654 "cast from function call of type %qT " |
4683 "to non-matching type %qT", otype, type); | 4655 "to non-matching type %qT", otype, type); |
4684 | 4656 |
4685 if (TREE_CODE (type) == POINTER_TYPE | 4657 if (TREE_CODE (type) == POINTER_TYPE |
4686 && TREE_CODE (otype) == INTEGER_TYPE | 4658 && TREE_CODE (otype) == INTEGER_TYPE |
4687 && TYPE_PRECISION (type) != TYPE_PRECISION (otype) | 4659 && TYPE_PRECISION (type) != TYPE_PRECISION (otype) |
4688 /* Don't warn about converting any constant. */ | 4660 /* Don't warn about converting any constant. */ |
4689 && !TREE_CONSTANT (value)) | 4661 && !TREE_CONSTANT (value)) |
4690 warning_at (loc, | 4662 warning_at (loc, |
4691 OPT_Wint_to_pointer_cast, "cast to pointer from integer " | 4663 OPT_Wint_to_pointer_cast, "cast to pointer from integer " |
4692 "of different size"); | 4664 "of different size"); |
4693 | 4665 |
4694 if (warn_strict_aliasing <= 2) | 4666 if (warn_strict_aliasing <= 2) |
4695 strict_aliasing_warning (otype, type, expr); | 4667 strict_aliasing_warning (otype, type, expr); |
4696 | 4668 |
4697 /* If pedantic, warn for conversions between function and object | 4669 /* If pedantic, warn for conversions between function and object |
4698 pointer types, except for converting a null pointer constant | 4670 pointer types, except for converting a null pointer constant |
4699 to function pointer type. */ | 4671 to function pointer type. */ |
4700 if (pedantic | 4672 if (pedantic |
4701 && TREE_CODE (type) == POINTER_TYPE | 4673 && TREE_CODE (type) == POINTER_TYPE |
4702 && TREE_CODE (otype) == POINTER_TYPE | 4674 && TREE_CODE (otype) == POINTER_TYPE |
4703 && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE | 4675 && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE |
4704 && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE) | 4676 && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE) |
4705 pedwarn (loc, OPT_pedantic, "ISO C forbids " | 4677 pedwarn (loc, OPT_pedantic, "ISO C forbids " |
4706 "conversion of function pointer to object pointer type"); | 4678 "conversion of function pointer to object pointer type"); |
4707 | 4679 |
4708 if (pedantic | 4680 if (pedantic |
4709 && TREE_CODE (type) == POINTER_TYPE | 4681 && TREE_CODE (type) == POINTER_TYPE |
4710 && TREE_CODE (otype) == POINTER_TYPE | 4682 && TREE_CODE (otype) == POINTER_TYPE |
4711 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE | 4683 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE |
4712 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE | 4684 && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE |
4713 && !null_pointer_constant_p (value)) | 4685 && !null_pointer_constant_p (value)) |
4714 pedwarn (loc, OPT_pedantic, "ISO C forbids " | 4686 pedwarn (loc, OPT_pedantic, "ISO C forbids " |
4715 "conversion of object pointer to function pointer type"); | 4687 "conversion of object pointer to function pointer type"); |
4716 | 4688 |
4717 ovalue = value; | 4689 ovalue = value; |
4718 value = convert (type, value); | 4690 value = convert (type, value); |
4719 | 4691 |
4720 /* Ignore any integer overflow caused by the cast. */ | 4692 /* Ignore any integer overflow caused by the cast. */ |
4721 if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype)) | 4693 if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype)) |
4722 { | 4694 { |
4723 if (CONSTANT_CLASS_P (ovalue) && TREE_OVERFLOW (ovalue)) | 4695 if (CONSTANT_CLASS_P (ovalue) && TREE_OVERFLOW (ovalue)) |
4724 { | 4696 { |
4725 if (!TREE_OVERFLOW (value)) | 4697 if (!TREE_OVERFLOW (value)) |
4726 { | 4698 { |
4727 /* Avoid clobbering a shared constant. */ | 4699 /* Avoid clobbering a shared constant. */ |
4728 value = copy_node (value); | 4700 value = copy_node (value); |
4729 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue); | 4701 TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue); |
4730 } | 4702 } |
4731 } | 4703 } |
4732 else if (TREE_OVERFLOW (value)) | 4704 else if (TREE_OVERFLOW (value)) |
4733 /* Reset VALUE's overflow flags, ensuring constant sharing. */ | 4705 /* Reset VALUE's overflow flags, ensuring constant sharing. */ |
4734 value = build_int_cst_wide (TREE_TYPE (value), | 4706 value = build_int_cst_wide (TREE_TYPE (value), |
4735 TREE_INT_CST_LOW (value), | 4707 TREE_INT_CST_LOW (value), |
4736 TREE_INT_CST_HIGH (value)); | 4708 TREE_INT_CST_HIGH (value)); |
4737 } | 4709 } |
4738 } | 4710 } |
4739 | 4711 |
4740 /* Don't let a cast be an lvalue. */ | 4712 /* Don't let a cast be an lvalue. */ |
4741 if (value == expr) | 4713 if (value == expr) |
4742 value = non_lvalue_loc (loc, value); | 4714 value = non_lvalue_loc (loc, value); |
4747 and integer-to-pointer be confused with integer constant | 4719 and integer-to-pointer be confused with integer constant |
4748 expressions and null pointer constants. */ | 4720 expressions and null pointer constants. */ |
4749 if (TREE_CODE (value) == REAL_CST | 4721 if (TREE_CODE (value) == REAL_CST |
4750 || TREE_CODE (value) == COMPLEX_CST | 4722 || TREE_CODE (value) == COMPLEX_CST |
4751 || (TREE_CODE (value) == INTEGER_CST | 4723 || (TREE_CODE (value) == INTEGER_CST |
4752 && !((TREE_CODE (expr) == INTEGER_CST | 4724 && !((TREE_CODE (expr) == INTEGER_CST |
4753 && INTEGRAL_TYPE_P (TREE_TYPE (expr))) | 4725 && INTEGRAL_TYPE_P (TREE_TYPE (expr))) |
4754 || TREE_CODE (expr) == REAL_CST | 4726 || TREE_CODE (expr) == REAL_CST |
4755 || TREE_CODE (expr) == COMPLEX_CST))) | 4727 || TREE_CODE (expr) == COMPLEX_CST))) |
4756 value = build1 (NOP_EXPR, type, value); | 4728 value = build1 (NOP_EXPR, type, value); |
4757 | 4729 |
4758 if (CAN_HAVE_LOCATION_P (value)) | 4730 if (CAN_HAVE_LOCATION_P (value)) |
4759 SET_EXPR_LOCATION (value, loc); | 4731 SET_EXPR_LOCATION (value, loc); |
4760 return value; | 4732 return value; |
4792 | 4764 |
4793 /* C++ does not permits types to be defined in a cast, but it | 4765 /* C++ does not permits types to be defined in a cast, but it |
4794 allows references to incomplete types. */ | 4766 allows references to incomplete types. */ |
4795 if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef) | 4767 if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef) |
4796 warning_at (loc, OPT_Wc___compat, | 4768 warning_at (loc, OPT_Wc___compat, |
4797 "defining a type in a cast is invalid in C++"); | 4769 "defining a type in a cast is invalid in C++"); |
4798 | 4770 |
4799 return ret; | 4771 return ret; |
4800 } | 4772 } |
4801 | 4773 |
4802 /* Build an assignment expression of lvalue LHS from value RHS. | 4774 /* Build an assignment expression of lvalue LHS from value RHS. |
4811 LOCATION is the location of the MODIFYCODE operator. | 4783 LOCATION is the location of the MODIFYCODE operator. |
4812 RHS_LOC is the location of the RHS. */ | 4784 RHS_LOC is the location of the RHS. */ |
4813 | 4785 |
4814 tree | 4786 tree |
4815 build_modify_expr (location_t location, tree lhs, tree lhs_origtype, | 4787 build_modify_expr (location_t location, tree lhs, tree lhs_origtype, |
4816 enum tree_code modifycode, | 4788 enum tree_code modifycode, |
4817 location_t rhs_loc, tree rhs, tree rhs_origtype) | 4789 location_t rhs_loc, tree rhs, tree rhs_origtype) |
4818 { | 4790 { |
4819 tree result; | 4791 tree result; |
4820 tree newrhs; | 4792 tree newrhs; |
4821 tree rhs_semantic_type = NULL_TREE; | 4793 tree rhs_semantic_type = NULL_TREE; |
4822 tree lhstype = TREE_TYPE (lhs); | 4794 tree lhstype = TREE_TYPE (lhs); |
4843 newrhs = rhs; | 4815 newrhs = rhs; |
4844 | 4816 |
4845 if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR) | 4817 if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR) |
4846 { | 4818 { |
4847 tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs), | 4819 tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs), |
4848 lhs_origtype, modifycode, rhs_loc, rhs, | 4820 lhs_origtype, modifycode, rhs_loc, rhs, |
4849 rhs_origtype); | 4821 rhs_origtype); |
4850 if (inner == error_mark_node) | 4822 if (inner == error_mark_node) |
4851 return error_mark_node; | 4823 return error_mark_node; |
4852 result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner), | 4824 result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner), |
4853 C_MAYBE_CONST_EXPR_PRE (lhs), inner); | 4825 C_MAYBE_CONST_EXPR_PRE (lhs), inner); |
4854 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs)); | 4826 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs)); |
4855 C_MAYBE_CONST_EXPR_NON_CONST (result) = 1; | 4827 C_MAYBE_CONST_EXPR_NON_CONST (result) = 1; |
4856 protected_set_expr_location (result, location); | 4828 protected_set_expr_location (result, location); |
4857 return result; | 4829 return result; |
4858 } | 4830 } |
4863 if (modifycode != NOP_EXPR) | 4835 if (modifycode != NOP_EXPR) |
4864 { | 4836 { |
4865 lhs = c_fully_fold (lhs, false, NULL); | 4837 lhs = c_fully_fold (lhs, false, NULL); |
4866 lhs = stabilize_reference (lhs); | 4838 lhs = stabilize_reference (lhs); |
4867 newrhs = build_binary_op (location, | 4839 newrhs = build_binary_op (location, |
4868 modifycode, lhs, rhs, 1); | 4840 modifycode, lhs, rhs, 1); |
4869 | 4841 |
4870 /* The original type of the right hand side is no longer | 4842 /* The original type of the right hand side is no longer |
4871 meaningful. */ | 4843 meaningful. */ |
4872 rhs_origtype = NULL_TREE; | 4844 rhs_origtype = NULL_TREE; |
4873 } | 4845 } |
4874 | 4846 |
4875 if (c_dialect_objc ()) | 4847 if (c_dialect_objc ()) |
4876 { | 4848 { |
4887 | 4859 |
4888 /* Give an error for storing in something that is 'const'. */ | 4860 /* Give an error for storing in something that is 'const'. */ |
4889 | 4861 |
4890 if (TYPE_READONLY (lhstype) | 4862 if (TYPE_READONLY (lhstype) |
4891 || ((TREE_CODE (lhstype) == RECORD_TYPE | 4863 || ((TREE_CODE (lhstype) == RECORD_TYPE |
4892 || TREE_CODE (lhstype) == UNION_TYPE) | 4864 || TREE_CODE (lhstype) == UNION_TYPE) |
4893 && C_TYPE_FIELDS_READONLY (lhstype))) | 4865 && C_TYPE_FIELDS_READONLY (lhstype))) |
4894 { | 4866 { |
4895 readonly_error (lhs, lv_assign); | 4867 readonly_error (lhs, lv_assign); |
4896 return error_mark_node; | 4868 return error_mark_node; |
4897 } | 4869 } |
4898 else if (TREE_READONLY (lhs)) | 4870 else if (TREE_READONLY (lhs)) |
4903 Compute the type that would go with | 4875 Compute the type that would go with |
4904 the actual amount of storage the member occupies. */ | 4876 the actual amount of storage the member occupies. */ |
4905 | 4877 |
4906 if (TREE_CODE (lhs) == COMPONENT_REF | 4878 if (TREE_CODE (lhs) == COMPONENT_REF |
4907 && (TREE_CODE (lhstype) == INTEGER_TYPE | 4879 && (TREE_CODE (lhstype) == INTEGER_TYPE |
4908 || TREE_CODE (lhstype) == BOOLEAN_TYPE | 4880 || TREE_CODE (lhstype) == BOOLEAN_TYPE |
4909 || TREE_CODE (lhstype) == REAL_TYPE | 4881 || TREE_CODE (lhstype) == REAL_TYPE |
4910 || TREE_CODE (lhstype) == ENUMERAL_TYPE)) | 4882 || TREE_CODE (lhstype) == ENUMERAL_TYPE)) |
4911 lhstype = TREE_TYPE (get_unwidened (lhs, 0)); | 4883 lhstype = TREE_TYPE (get_unwidened (lhs, 0)); |
4912 | 4884 |
4913 /* If storing in a field that is in actuality a short or narrower than one, | 4885 /* If storing in a field that is in actuality a short or narrower than one, |
4914 we must store in the field in its actual type. */ | 4886 we must store in the field in its actual type. */ |
4915 | 4887 |
4926 && lhs_origtype != NULL_TREE | 4898 && lhs_origtype != NULL_TREE |
4927 && lhs_origtype != lhstype | 4899 && lhs_origtype != lhstype |
4928 && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE) | 4900 && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE) |
4929 { | 4901 { |
4930 tree checktype = (rhs_origtype != NULL_TREE | 4902 tree checktype = (rhs_origtype != NULL_TREE |
4931 ? rhs_origtype | 4903 ? rhs_origtype |
4932 : TREE_TYPE (rhs)); | 4904 : TREE_TYPE (rhs)); |
4933 if (checktype != error_mark_node | 4905 if (checktype != error_mark_node |
4934 && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)) | 4906 && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)) |
4935 warning_at (location, OPT_Wc___compat, | 4907 warning_at (location, OPT_Wc___compat, |
4936 "enum conversion in assignment is invalid in C++"); | 4908 "enum conversion in assignment is invalid in C++"); |
4937 } | 4909 } |
4938 | 4910 |
4939 /* Convert new value to destination type. Fold it first, then | 4911 /* Convert new value to destination type. Fold it first, then |
4940 restore any excess precision information, for the sake of | 4912 restore any excess precision information, for the sake of |
4941 conversion warnings. */ | 4913 conversion warnings. */ |
4943 npc = null_pointer_constant_p (newrhs); | 4915 npc = null_pointer_constant_p (newrhs); |
4944 newrhs = c_fully_fold (newrhs, false, NULL); | 4916 newrhs = c_fully_fold (newrhs, false, NULL); |
4945 if (rhs_semantic_type) | 4917 if (rhs_semantic_type) |
4946 newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs); | 4918 newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs); |
4947 newrhs = convert_for_assignment (location, lhstype, newrhs, rhs_origtype, | 4919 newrhs = convert_for_assignment (location, lhstype, newrhs, rhs_origtype, |
4948 ic_assign, npc, NULL_TREE, NULL_TREE, 0); | 4920 ic_assign, npc, NULL_TREE, NULL_TREE, 0); |
4949 if (TREE_CODE (newrhs) == ERROR_MARK) | 4921 if (TREE_CODE (newrhs) == ERROR_MARK) |
4950 return error_mark_node; | 4922 return error_mark_node; |
4951 | 4923 |
4952 /* Emit ObjC write barrier, if necessary. */ | 4924 /* Emit ObjC write barrier, if necessary. */ |
4953 if (c_dialect_objc () && flag_objc_gc) | 4925 if (c_dialect_objc () && flag_objc_gc) |
4954 { | 4926 { |
4955 result = objc_generate_write_barrier (lhs, modifycode, newrhs); | 4927 result = objc_generate_write_barrier (lhs, modifycode, newrhs); |
4956 if (result) | 4928 if (result) |
4957 { | 4929 { |
4958 protected_set_expr_location (result, location); | 4930 protected_set_expr_location (result, location); |
4959 return result; | 4931 return result; |
4960 } | 4932 } |
4961 } | 4933 } |
4962 | 4934 |
4963 /* Scan operands. */ | 4935 /* Scan operands. */ |
4964 | 4936 |
4965 result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs); | 4937 result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs); |
4973 | 4945 |
4974 if (olhstype == TREE_TYPE (result)) | 4946 if (olhstype == TREE_TYPE (result)) |
4975 return result; | 4947 return result; |
4976 | 4948 |
4977 result = convert_for_assignment (location, olhstype, result, rhs_origtype, | 4949 result = convert_for_assignment (location, olhstype, result, rhs_origtype, |
4978 ic_assign, false, NULL_TREE, NULL_TREE, 0); | 4950 ic_assign, false, NULL_TREE, NULL_TREE, 0); |
4979 protected_set_expr_location (result, location); | 4951 protected_set_expr_location (result, location); |
4980 return result; | 4952 return result; |
4981 } | 4953 } |
4982 | 4954 |
4983 /* Return whether STRUCT_TYPE has an anonymous field with type TYPE. | 4955 /* Return whether STRUCT_TYPE has an anonymous field with type TYPE. |
5095 FUNCTION is a tree for the function being called. | 5067 FUNCTION is a tree for the function being called. |
5096 PARMNUM is the number of the argument, for printing in error messages. */ | 5068 PARMNUM is the number of the argument, for printing in error messages. */ |
5097 | 5069 |
5098 static tree | 5070 static tree |
5099 convert_for_assignment (location_t location, tree type, tree rhs, | 5071 convert_for_assignment (location_t location, tree type, tree rhs, |
5100 tree origtype, enum impl_conv errtype, | 5072 tree origtype, enum impl_conv errtype, |
5101 bool null_pointer_constant, tree fundecl, | 5073 bool null_pointer_constant, tree fundecl, |
5102 tree function, int parmnum) | 5074 tree function, int parmnum) |
5103 { | 5075 { |
5104 enum tree_code codel = TREE_CODE (type); | 5076 enum tree_code codel = TREE_CODE (type); |
5105 tree orig_rhs = rhs; | 5077 tree orig_rhs = rhs; |
5106 tree rhstype; | 5078 tree rhstype; |
5107 enum tree_code coder; | 5079 enum tree_code coder; |
5110 | 5082 |
5111 if (errtype == ic_argpass) | 5083 if (errtype == ic_argpass) |
5112 { | 5084 { |
5113 tree selector; | 5085 tree selector; |
5114 /* Change pointer to function to the function itself for | 5086 /* Change pointer to function to the function itself for |
5115 diagnostics. */ | 5087 diagnostics. */ |
5116 if (TREE_CODE (function) == ADDR_EXPR | 5088 if (TREE_CODE (function) == ADDR_EXPR |
5117 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL) | 5089 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL) |
5118 function = TREE_OPERAND (function, 0); | 5090 function = TREE_OPERAND (function, 0); |
5119 | 5091 |
5120 /* Handle an ObjC selector specially for diagnostics. */ | 5092 /* Handle an ObjC selector specially for diagnostics. */ |
5121 selector = objc_message_selector (); | 5093 selector = objc_message_selector (); |
5122 rname = function; | 5094 rname = function; |
5123 if (selector && parmnum > 2) | 5095 if (selector && parmnum > 2) |
5124 { | 5096 { |
5125 rname = selector; | 5097 rname = selector; |
5126 parmnum -= 2; | 5098 parmnum -= 2; |
5127 } | 5099 } |
5128 } | 5100 } |
5129 | 5101 |
5130 /* This macro is used to emit diagnostics to ensure that all format | 5102 /* This macro is used to emit diagnostics to ensure that all format |
5131 strings are complete sentences, visible to gettext and checked at | 5103 strings are complete sentences, visible to gettext and checked at |
5132 compile time. */ | 5104 compile time. */ |
5133 #define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \ | 5105 #define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \ |
5134 do { \ | 5106 do { \ |
5135 switch (errtype) \ | 5107 switch (errtype) \ |
5136 { \ | 5108 { \ |
5137 case ic_argpass: \ | 5109 case ic_argpass: \ |
5138 if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \ | 5110 if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \ |
5139 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \ | 5111 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \ |
5140 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \ | 5112 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \ |
5141 "expected %qT but argument is of type %qT", \ | 5113 "expected %qT but argument is of type %qT", \ |
5142 type, rhstype); \ | 5114 type, rhstype); \ |
5143 break; \ | 5115 break; \ |
5144 case ic_assign: \ | 5116 case ic_assign: \ |
5145 pedwarn (LOCATION, OPT, AS); \ | 5117 pedwarn (LOCATION, OPT, AS); \ |
5146 break; \ | 5118 break; \ |
5147 case ic_init: \ | 5119 case ic_init: \ |
5148 pedwarn_init (LOCATION, OPT, IN); \ | 5120 pedwarn_init (LOCATION, OPT, IN); \ |
5149 break; \ | 5121 break; \ |
5150 case ic_return: \ | 5122 case ic_return: \ |
5151 pedwarn (LOCATION, OPT, RE); \ | 5123 pedwarn (LOCATION, OPT, RE); \ |
5152 break; \ | 5124 break; \ |
5153 default: \ | 5125 default: \ |
5154 gcc_unreachable (); \ | 5126 gcc_unreachable (); \ |
5155 } \ | 5127 } \ |
5156 } while (0) | 5128 } while (0) |
5197 if (c_dialect_objc ()) | 5169 if (c_dialect_objc ()) |
5198 { | 5170 { |
5199 int parmno; | 5171 int parmno; |
5200 | 5172 |
5201 switch (errtype) | 5173 switch (errtype) |
5202 { | 5174 { |
5203 case ic_return: | 5175 case ic_return: |
5204 parmno = 0; | 5176 parmno = 0; |
5205 break; | 5177 break; |
5206 | 5178 |
5207 case ic_assign: | 5179 case ic_assign: |
5208 parmno = -1; | 5180 parmno = -1; |
5209 break; | 5181 break; |
5210 | 5182 |
5211 case ic_init: | 5183 case ic_init: |
5212 parmno = -2; | 5184 parmno = -2; |
5213 break; | 5185 break; |
5214 | 5186 |
5215 default: | 5187 default: |
5216 parmno = parmnum; | 5188 parmno = parmnum; |
5217 break; | 5189 break; |
5218 } | 5190 } |
5219 | 5191 |
5220 objc_ok = objc_compare_types (type, rhstype, parmno, rname); | 5192 objc_ok = objc_compare_types (type, rhstype, parmno, rname); |
5221 } | 5193 } |
5222 | 5194 |
5223 if (warn_cxx_compat) | 5195 if (warn_cxx_compat) |
5224 { | 5196 { |
5225 tree checktype = origtype != NULL_TREE ? origtype : rhstype; | 5197 tree checktype = origtype != NULL_TREE ? origtype : rhstype; |
5226 if (checktype != error_mark_node | 5198 if (checktype != error_mark_node |
5227 && TREE_CODE (type) == ENUMERAL_TYPE | 5199 && TREE_CODE (type) == ENUMERAL_TYPE |
5228 && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type)) | 5200 && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type)) |
5229 { | 5201 { |
5230 WARN_FOR_ASSIGNMENT (input_location, OPT_Wc___compat, | 5202 WARN_FOR_ASSIGNMENT (input_location, OPT_Wc___compat, |
5231 G_("enum conversion when passing argument " | 5203 G_("enum conversion when passing argument " |
5232 "%d of %qE is invalid in C++"), | 5204 "%d of %qE is invalid in C++"), |
5233 G_("enum conversion in assignment is " | 5205 G_("enum conversion in assignment is " |
5234 "invalid in C++"), | 5206 "invalid in C++"), |
5235 G_("enum conversion in initialization is " | 5207 G_("enum conversion in initialization is " |
5236 "invalid in C++"), | 5208 "invalid in C++"), |
5237 G_("enum conversion in return is " | 5209 G_("enum conversion in return is " |
5238 "invalid in C++")); | 5210 "invalid in C++")); |
5239 } | 5211 } |
5240 } | 5212 } |
5241 | 5213 |
5242 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)) | 5214 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)) |
5243 return rhs; | 5215 return rhs; |
5244 | 5216 |
5245 if (coder == VOID_TYPE) | 5217 if (coder == VOID_TYPE) |
5246 { | 5218 { |
5247 /* Except for passing an argument to an unprototyped function, | 5219 /* Except for passing an argument to an unprototyped function, |
5248 this is a constraint violation. When passing an argument to | 5220 this is a constraint violation. When passing an argument to |
5249 an unprototyped function, it is compile-time undefined; | 5221 an unprototyped function, it is compile-time undefined; |
5250 making it a constraint in that case was rejected in | 5222 making it a constraint in that case was rejected in |
5251 DR#252. */ | 5223 DR#252. */ |
5252 error_at (location, "void value not ignored as it ought to be"); | 5224 error_at (location, "void value not ignored as it ought to be"); |
5253 return error_mark_node; | 5225 return error_mark_node; |
5254 } | 5226 } |
5255 rhs = require_complete_type (rhs); | 5227 rhs = require_complete_type (rhs); |
5256 if (rhs == error_mark_node) | 5228 if (rhs == error_mark_node) |
5260 special case of va_start and va_copy. */ | 5232 special case of va_start and va_copy. */ |
5261 if (codel == REFERENCE_TYPE | 5233 if (codel == REFERENCE_TYPE |
5262 && comptypes (TREE_TYPE (type), TREE_TYPE (rhs)) == 1) | 5234 && comptypes (TREE_TYPE (type), TREE_TYPE (rhs)) == 1) |
5263 { | 5235 { |
5264 if (!lvalue_p (rhs)) | 5236 if (!lvalue_p (rhs)) |
5265 { | 5237 { |
5266 error_at (location, "cannot pass rvalue to reference parameter"); | 5238 error_at (location, "cannot pass rvalue to reference parameter"); |
5267 return error_mark_node; | 5239 return error_mark_node; |
5268 } | 5240 } |
5269 if (!c_mark_addressable (rhs)) | 5241 if (!c_mark_addressable (rhs)) |
5270 return error_mark_node; | 5242 return error_mark_node; |
5271 rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs); | 5243 rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs); |
5272 SET_EXPR_LOCATION (rhs, location); | 5244 SET_EXPR_LOCATION (rhs, location); |
5273 | 5245 |
5274 /* We already know that these two types are compatible, but they | 5246 /* We already know that these two types are compatible, but they |
5275 may not be exactly identical. In fact, `TREE_TYPE (type)' is | 5247 may not be exactly identical. In fact, `TREE_TYPE (type)' is |
5276 likely to be __builtin_va_list and `TREE_TYPE (rhs)' is | 5248 likely to be __builtin_va_list and `TREE_TYPE (rhs)' is |
5277 likely to be va_list, a typedef to __builtin_va_list, which | 5249 likely to be va_list, a typedef to __builtin_va_list, which |
5278 is different enough that it will cause problems later. */ | 5250 is different enough that it will cause problems later. */ |
5279 if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type)) | 5251 if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type)) |
5280 { | 5252 { |
5281 rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs); | 5253 rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs); |
5282 SET_EXPR_LOCATION (rhs, location); | 5254 SET_EXPR_LOCATION (rhs, location); |
5283 } | 5255 } |
5284 | 5256 |
5285 rhs = build1 (NOP_EXPR, type, rhs); | 5257 rhs = build1 (NOP_EXPR, type, rhs); |
5286 SET_EXPR_LOCATION (rhs, location); | 5258 SET_EXPR_LOCATION (rhs, location); |
5287 return rhs; | 5259 return rhs; |
5288 } | 5260 } |
5289 /* Some types can interconvert without explicit casts. */ | 5261 /* Some types can interconvert without explicit casts. */ |
5290 else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE | 5262 else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE |
5291 && vector_types_convertible_p (type, TREE_TYPE (rhs), true)) | 5263 && vector_types_convertible_p (type, TREE_TYPE (rhs), true)) |
5292 return convert (type, rhs); | 5264 return convert (type, rhs); |
5293 /* Arithmetic types all interconvert, and enum is treated like int. */ | 5265 /* Arithmetic types all interconvert, and enum is treated like int. */ |
5294 else if ((codel == INTEGER_TYPE || codel == REAL_TYPE | 5266 else if ((codel == INTEGER_TYPE || codel == REAL_TYPE |
5295 || codel == FIXED_POINT_TYPE | 5267 || codel == FIXED_POINT_TYPE |
5296 || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE | 5268 || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE |
5297 || codel == BOOLEAN_TYPE) | 5269 || codel == BOOLEAN_TYPE) |
5298 && (coder == INTEGER_TYPE || coder == REAL_TYPE | 5270 && (coder == INTEGER_TYPE || coder == REAL_TYPE |
5299 || coder == FIXED_POINT_TYPE | 5271 || coder == FIXED_POINT_TYPE |
5300 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE | 5272 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE |
5301 || coder == BOOLEAN_TYPE)) | 5273 || coder == BOOLEAN_TYPE)) |
5302 { | 5274 { |
5303 tree ret; | 5275 tree ret; |
5304 bool save = in_late_binary_op; | 5276 bool save = in_late_binary_op; |
5305 if (codel == BOOLEAN_TYPE || codel == COMPLEX_TYPE) | 5277 if (codel == BOOLEAN_TYPE || codel == COMPLEX_TYPE) |
5306 in_late_binary_op = true; | 5278 in_late_binary_op = true; |
5416 G_("initialization discards %qv qualifier " | 5388 G_("initialization discards %qv qualifier " |
5417 "from pointer target type"), | 5389 "from pointer target type"), |
5418 G_("return discards %qv qualifier from " | 5390 G_("return discards %qv qualifier from " |
5419 "pointer target type"), | 5391 "pointer target type"), |
5420 TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl)); | 5392 TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl)); |
5393 | |
5421 memb = marginal_memb; | 5394 memb = marginal_memb; |
5422 } | 5395 } |
5423 | 5396 |
5424 if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)) | 5397 if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)) |
5425 pedwarn (location, OPT_pedantic, | 5398 pedwarn (location, OPT_pedantic, |
5430 } | 5403 } |
5431 } | 5404 } |
5432 | 5405 |
5433 /* Conversions among pointers */ | 5406 /* Conversions among pointers */ |
5434 else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE) | 5407 else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE) |
5435 && (coder == codel)) | 5408 && (coder == codel)) |
5436 { | 5409 { |
5437 tree ttl = TREE_TYPE (type); | 5410 tree ttl = TREE_TYPE (type); |
5438 tree ttr = TREE_TYPE (rhstype); | 5411 tree ttr = TREE_TYPE (rhstype); |
5439 tree mvl = ttl; | 5412 tree mvl = ttl; |
5440 tree mvr = ttr; | 5413 tree mvr = ttr; |
5442 int target_cmp = 0; /* Cache comp_target_types () result. */ | 5415 int target_cmp = 0; /* Cache comp_target_types () result. */ |
5443 addr_space_t asl; | 5416 addr_space_t asl; |
5444 addr_space_t asr; | 5417 addr_space_t asr; |
5445 | 5418 |
5446 if (TREE_CODE (mvl) != ARRAY_TYPE) | 5419 if (TREE_CODE (mvl) != ARRAY_TYPE) |
5447 mvl = TYPE_MAIN_VARIANT (mvl); | 5420 mvl = TYPE_MAIN_VARIANT (mvl); |
5448 if (TREE_CODE (mvr) != ARRAY_TYPE) | 5421 if (TREE_CODE (mvr) != ARRAY_TYPE) |
5449 mvr = TYPE_MAIN_VARIANT (mvr); | 5422 mvr = TYPE_MAIN_VARIANT (mvr); |
5450 /* Opaque pointers are treated like void pointers. */ | 5423 /* Opaque pointers are treated like void pointers. */ |
5451 is_opaque_pointer = vector_targets_convertible_p (ttl, ttr); | 5424 is_opaque_pointer = vector_targets_convertible_p (ttl, ttr); |
5452 | 5425 |
5453 /* The Plan 9 compiler permits a pointer to a struct to be | 5426 /* The Plan 9 compiler permits a pointer to a struct to be |
5454 automatically converted into a pointer to an anonymous field | 5427 automatically converted into a pointer to an anonymous field |
5468 mvr = TYPE_MAIN_VARIANT (ttr); | 5441 mvr = TYPE_MAIN_VARIANT (ttr); |
5469 } | 5442 } |
5470 } | 5443 } |
5471 | 5444 |
5472 /* C++ does not allow the implicit conversion void* -> T*. However, | 5445 /* C++ does not allow the implicit conversion void* -> T*. However, |
5473 for the purpose of reducing the number of false positives, we | 5446 for the purpose of reducing the number of false positives, we |
5474 tolerate the special case of | 5447 tolerate the special case of |
5475 | 5448 |
5476 int *p = NULL; | 5449 int *p = NULL; |
5477 | 5450 |
5478 where NULL is typically defined in C to be '(void *) 0'. */ | 5451 where NULL is typically defined in C to be '(void *) 0'. */ |
5479 if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl)) | 5452 if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl)) |
5480 warning_at (location, OPT_Wc___compat, | 5453 warning_at (location, OPT_Wc___compat, |
5481 "request for implicit conversion " | 5454 "request for implicit conversion " |
5482 "from %qT to %qT not permitted in C++", rhstype, type); | 5455 "from %qT to %qT not permitted in C++", rhstype, type); |
5483 | 5456 |
5484 /* See if the pointers point to incompatible address spaces. */ | 5457 /* See if the pointers point to incompatible address spaces. */ |
5485 asl = TYPE_ADDR_SPACE (ttl); | 5458 asl = TYPE_ADDR_SPACE (ttl); |
5486 asr = TYPE_ADDR_SPACE (ttr); | 5459 asr = TYPE_ADDR_SPACE (ttr); |
5487 if (!null_pointer_constant_p (rhs) | 5460 if (!null_pointer_constant_p (rhs) |
5488 && asr != asl && !targetm.addr_space.subset_p (asr, asl)) | 5461 && asr != asl && !targetm.addr_space.subset_p (asr, asl)) |
5489 { | 5462 { |
5490 switch (errtype) | 5463 switch (errtype) |
5491 { | 5464 { |
5492 case ic_argpass: | 5465 case ic_argpass: |
5493 error_at (location, "passing argument %d of %qE from pointer to " | 5466 error_at (location, "passing argument %d of %qE from pointer to " |
5494 "non-enclosed address space", parmnum, rname); | 5467 "non-enclosed address space", parmnum, rname); |
5495 break; | 5468 break; |
5496 case ic_assign: | 5469 case ic_assign: |
5497 error_at (location, "assignment from pointer to " | 5470 error_at (location, "assignment from pointer to " |
5498 "non-enclosed address space"); | 5471 "non-enclosed address space"); |
5499 break; | 5472 break; |
5500 case ic_init: | 5473 case ic_init: |
5501 error_at (location, "initialization from pointer to " | 5474 error_at (location, "initialization from pointer to " |
5502 "non-enclosed address space"); | 5475 "non-enclosed address space"); |
5503 break; | 5476 break; |
5504 case ic_return: | 5477 case ic_return: |
5505 error_at (location, "return from pointer to " | 5478 error_at (location, "return from pointer to " |
5506 "non-enclosed address space"); | 5479 "non-enclosed address space"); |
5507 break; | 5480 break; |
5508 default: | 5481 default: |
5509 gcc_unreachable (); | 5482 gcc_unreachable (); |
5510 } | 5483 } |
5511 return error_mark_node; | 5484 return error_mark_node; |
5512 } | 5485 } |
5513 | 5486 |
5514 /* Check if the right-hand side has a format attribute but the | 5487 /* Check if the right-hand side has a format attribute but the |
5515 left-hand side doesn't. */ | 5488 left-hand side doesn't. */ |
5516 if (warn_missing_format_attribute | 5489 if (warn_missing_format_attribute |
5517 && check_missing_format_attribute (type, rhstype)) | 5490 && check_missing_format_attribute (type, rhstype)) |
5518 { | 5491 { |
5519 switch (errtype) | 5492 switch (errtype) |
5520 { | 5493 { |
5521 case ic_argpass: | 5494 case ic_argpass: |
5522 warning_at (location, OPT_Wmissing_format_attribute, | 5495 warning_at (location, OPT_Wmissing_format_attribute, |
5523 "argument %d of %qE might be " | 5496 "argument %d of %qE might be " |
5524 "a candidate for a format attribute", | 5497 "a candidate for a format attribute", |
5525 parmnum, rname); | 5498 parmnum, rname); |
5526 break; | 5499 break; |
5527 case ic_assign: | 5500 case ic_assign: |
5528 warning_at (location, OPT_Wmissing_format_attribute, | 5501 warning_at (location, OPT_Wmissing_format_attribute, |
5529 "assignment left-hand side might be " | 5502 "assignment left-hand side might be " |
5530 "a candidate for a format attribute"); | 5503 "a candidate for a format attribute"); |
5531 break; | 5504 break; |
5532 case ic_init: | 5505 case ic_init: |
5533 warning_at (location, OPT_Wmissing_format_attribute, | 5506 warning_at (location, OPT_Wmissing_format_attribute, |
5534 "initialization left-hand side might be " | 5507 "initialization left-hand side might be " |
5535 "a candidate for a format attribute"); | 5508 "a candidate for a format attribute"); |
5536 break; | 5509 break; |
5537 case ic_return: | 5510 case ic_return: |
5538 warning_at (location, OPT_Wmissing_format_attribute, | 5511 warning_at (location, OPT_Wmissing_format_attribute, |
5539 "return type might be " | 5512 "return type might be " |
5540 "a candidate for a format attribute"); | 5513 "a candidate for a format attribute"); |
5541 break; | 5514 break; |
5542 default: | 5515 default: |
5543 gcc_unreachable (); | 5516 gcc_unreachable (); |
5544 } | 5517 } |
5545 } | 5518 } |
5546 | 5519 |
5547 /* Any non-function converts to a [const][volatile] void * | 5520 /* Any non-function converts to a [const][volatile] void * |
5548 and vice versa; otherwise, targets must be the same. | 5521 and vice versa; otherwise, targets must be the same. |
5549 Meanwhile, the lhs target must have all the qualifiers of the rhs. */ | 5522 Meanwhile, the lhs target must have all the qualifiers of the rhs. */ |
5550 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) | 5523 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) |
5551 || (target_cmp = comp_target_types (location, type, rhstype)) | 5524 || (target_cmp = comp_target_types (location, type, rhstype)) |
5552 || is_opaque_pointer | 5525 || is_opaque_pointer |
5553 || (c_common_unsigned_type (mvl) | 5526 || (c_common_unsigned_type (mvl) |
5554 == c_common_unsigned_type (mvr))) | 5527 == c_common_unsigned_type (mvr))) |
5626 "pointer from unqualified"), | 5599 "pointer from unqualified"), |
5627 TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr)); | 5600 TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr)); |
5628 } | 5601 } |
5629 } | 5602 } |
5630 else | 5603 else |
5631 /* Avoid warning about the volatile ObjC EH puts on decls. */ | 5604 /* Avoid warning about the volatile ObjC EH puts on decls. */ |
5632 if (!objc_ok) | 5605 if (!objc_ok) |
5633 WARN_FOR_ASSIGNMENT (location, 0, | 5606 WARN_FOR_ASSIGNMENT (location, 0, |
5634 G_("passing argument %d of %qE from " | 5607 G_("passing argument %d of %qE from " |
5635 "incompatible pointer type"), | 5608 "incompatible pointer type"), |
5636 G_("assignment from incompatible pointer type"), | 5609 G_("assignment from incompatible pointer type"), |
5637 G_("initialization from incompatible " | 5610 G_("initialization from incompatible " |
5638 "pointer type"), | 5611 "pointer type"), |
5639 G_("return from incompatible pointer type")); | 5612 G_("return from incompatible pointer type")); |
5640 | 5613 |
5641 return convert (type, rhs); | 5614 return convert (type, rhs); |
5642 } | 5615 } |
5643 else if (codel == POINTER_TYPE && coder == ARRAY_TYPE) | 5616 else if (codel == POINTER_TYPE && coder == ARRAY_TYPE) |
5644 { | 5617 { |
5645 /* ??? This should not be an error when inlining calls to | 5618 /* ??? This should not be an error when inlining calls to |
5646 unprototyped functions. */ | 5619 unprototyped functions. */ |
5647 error_at (location, "invalid use of non-lvalue array"); | 5620 error_at (location, "invalid use of non-lvalue array"); |
5648 return error_mark_node; | 5621 return error_mark_node; |
5649 } | 5622 } |
5650 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE) | 5623 else if (codel == POINTER_TYPE && coder == INTEGER_TYPE) |
5651 { | 5624 { |
5652 /* An explicit constant 0 can convert to a pointer, | 5625 /* An explicit constant 0 can convert to a pointer, |
5653 or one that results from arithmetic, even including | 5626 or one that results from arithmetic, even including |
5654 a cast to integer type. */ | 5627 a cast to integer type. */ |
5655 if (!null_pointer_constant) | 5628 if (!null_pointer_constant) |
5656 WARN_FOR_ASSIGNMENT (location, 0, | 5629 WARN_FOR_ASSIGNMENT (location, 0, |
5657 G_("passing argument %d of %qE makes " | 5630 G_("passing argument %d of %qE makes " |
5658 "pointer from integer without a cast"), | 5631 "pointer from integer without a cast"), |
5659 G_("assignment makes pointer from integer " | 5632 G_("assignment makes pointer from integer " |
5660 "without a cast"), | 5633 "without a cast"), |
5661 G_("initialization makes pointer from " | 5634 G_("initialization makes pointer from " |
5662 "integer without a cast"), | 5635 "integer without a cast"), |
5663 G_("return makes pointer from integer " | 5636 G_("return makes pointer from integer " |
5664 "without a cast")); | 5637 "without a cast")); |
5665 | 5638 |
5666 return convert (type, rhs); | 5639 return convert (type, rhs); |
5667 } | 5640 } |
5668 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE) | 5641 else if (codel == INTEGER_TYPE && coder == POINTER_TYPE) |
5669 { | 5642 { |
5670 WARN_FOR_ASSIGNMENT (location, 0, | 5643 WARN_FOR_ASSIGNMENT (location, 0, |
5671 G_("passing argument %d of %qE makes integer " | 5644 G_("passing argument %d of %qE makes integer " |
5672 "from pointer without a cast"), | 5645 "from pointer without a cast"), |
5673 G_("assignment makes integer from pointer " | 5646 G_("assignment makes integer from pointer " |
5674 "without a cast"), | 5647 "without a cast"), |
5675 G_("initialization makes integer from pointer " | 5648 G_("initialization makes integer from pointer " |
5676 "without a cast"), | 5649 "without a cast"), |
5677 G_("return makes integer from pointer " | 5650 G_("return makes integer from pointer " |
5678 "without a cast")); | 5651 "without a cast")); |
5679 return convert (type, rhs); | 5652 return convert (type, rhs); |
5680 } | 5653 } |
5681 else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE) | 5654 else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE) |
5682 { | 5655 { |
5683 tree ret; | 5656 tree ret; |
5691 switch (errtype) | 5664 switch (errtype) |
5692 { | 5665 { |
5693 case ic_argpass: | 5666 case ic_argpass: |
5694 error_at (location, "incompatible type for argument %d of %qE", parmnum, rname); | 5667 error_at (location, "incompatible type for argument %d of %qE", parmnum, rname); |
5695 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) | 5668 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) |
5696 ? DECL_SOURCE_LOCATION (fundecl) : input_location, | 5669 ? DECL_SOURCE_LOCATION (fundecl) : input_location, |
5697 "expected %qT but argument is of type %qT", type, rhstype); | 5670 "expected %qT but argument is of type %qT", type, rhstype); |
5698 break; | 5671 break; |
5699 case ic_assign: | 5672 case ic_assign: |
5700 error_at (location, "incompatible types when assigning to type %qT from " | 5673 error_at (location, "incompatible types when assigning to type %qT from " |
5701 "type %qT", type, rhstype); | 5674 "type %qT", type, rhstype); |
5702 break; | 5675 break; |
5703 case ic_init: | 5676 case ic_init: |
5704 error_at (location, | 5677 error_at (location, |
5705 "incompatible types when initializing type %qT using type %qT", | 5678 "incompatible types when initializing type %qT using type %qT", |
5706 type, rhstype); | 5679 type, rhstype); |
5707 break; | 5680 break; |
5708 case ic_return: | 5681 case ic_return: |
5709 error_at (location, | 5682 error_at (location, |
5710 "incompatible types when returning type %qT but %qT was " | 5683 "incompatible types when returning type %qT but %qT was " |
5711 "expected", rhstype, type); | 5684 "expected", rhstype, type); |
5712 break; | 5685 break; |
5713 default: | 5686 default: |
5714 gcc_unreachable (); | 5687 gcc_unreachable (); |
5715 } | 5688 } |
5716 | 5689 |
5727 valid_compound_expr_initializer (tree value, tree endtype) | 5700 valid_compound_expr_initializer (tree value, tree endtype) |
5728 { | 5701 { |
5729 if (TREE_CODE (value) == COMPOUND_EXPR) | 5702 if (TREE_CODE (value) == COMPOUND_EXPR) |
5730 { | 5703 { |
5731 if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype) | 5704 if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype) |
5732 == error_mark_node) | 5705 == error_mark_node) |
5733 return error_mark_node; | 5706 return error_mark_node; |
5734 return valid_compound_expr_initializer (TREE_OPERAND (value, 1), | 5707 return valid_compound_expr_initializer (TREE_OPERAND (value, 1), |
5735 endtype); | 5708 endtype); |
5736 } | 5709 } |
5737 else if (!initializer_constant_valid_p (value, endtype)) | 5710 else if (!initializer_constant_valid_p (value, endtype)) |
5738 return error_mark_node; | 5711 return error_mark_node; |
5739 else | 5712 else |
5740 return value; | 5713 return value; |
5763 /* Digest the specified initializer into an expression. */ | 5736 /* Digest the specified initializer into an expression. */ |
5764 | 5737 |
5765 if (init) | 5738 if (init) |
5766 npc = null_pointer_constant_p (init); | 5739 npc = null_pointer_constant_p (init); |
5767 value = digest_init (init_loc, type, init, origtype, npc, | 5740 value = digest_init (init_loc, type, init, origtype, npc, |
5768 true, TREE_STATIC (decl)); | 5741 true, TREE_STATIC (decl)); |
5769 | 5742 |
5770 /* Store the expression if valid; else report error. */ | 5743 /* Store the expression if valid; else report error. */ |
5771 | 5744 |
5772 if (!in_system_header | 5745 if (!in_system_header |
5773 && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl)) | 5746 && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl)) |
5774 warning (OPT_Wtraditional, "traditional C rejects automatic " | 5747 warning (OPT_Wtraditional, "traditional C rejects automatic " |
5775 "aggregate initialization"); | 5748 "aggregate initialization"); |
5776 | 5749 |
5777 DECL_INITIAL (decl) = value; | 5750 DECL_INITIAL (decl) = value; |
5778 | 5751 |
5779 /* ANSI wants warnings about out-of-range constant initializers. */ | 5752 /* ANSI wants warnings about out-of-range constant initializers. */ |
5780 STRIP_TYPE_NOPS (value); | 5753 STRIP_TYPE_NOPS (value); |
5790 | 5763 |
5791 STRIP_TYPE_NOPS (inside_init); | 5764 STRIP_TYPE_NOPS (inside_init); |
5792 inside_init = fold (inside_init); | 5765 inside_init = fold (inside_init); |
5793 | 5766 |
5794 if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) | 5767 if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) |
5795 { | 5768 { |
5796 tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init); | 5769 tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init); |
5797 | 5770 |
5798 if (TYPE_DOMAIN (TREE_TYPE (cldecl))) | 5771 if (TYPE_DOMAIN (TREE_TYPE (cldecl))) |
5799 { | 5772 { |
5800 /* For int foo[] = (int [3]){1}; we need to set array size | 5773 /* For int foo[] = (int [3]){1}; we need to set array size |
5801 now since later on array initializer will be just the | 5774 now since later on array initializer will be just the |
5802 brace enclosed list of the compound literal. */ | 5775 brace enclosed list of the compound literal. */ |
5803 type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); | 5776 type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); |
5804 TREE_TYPE (decl) = type; | 5777 TREE_TYPE (decl) = type; |
5805 TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl)); | 5778 TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl)); |
5806 layout_type (type); | 5779 layout_type (type); |
5807 layout_decl (cldecl, 0); | 5780 layout_decl (cldecl, 0); |
5808 } | 5781 } |
5809 } | 5782 } |
5810 } | 5783 } |
5811 } | 5784 } |
5812 | 5785 |
5813 /* Methods for storing and printing names for error messages. */ | 5786 /* Methods for storing and printing names for error messages. */ |
5814 | 5787 |
5827 | 5800 |
5828 #define SPELLING_STRING 1 | 5801 #define SPELLING_STRING 1 |
5829 #define SPELLING_MEMBER 2 | 5802 #define SPELLING_MEMBER 2 |
5830 #define SPELLING_BOUNDS 3 | 5803 #define SPELLING_BOUNDS 3 |
5831 | 5804 |
5832 static struct spelling *spelling; /* Next stack element (unused). */ | 5805 static struct spelling *spelling; /* Next stack element (unused). */ |
5833 static struct spelling *spelling_base; /* Spelling stack base. */ | 5806 static struct spelling *spelling_base; /* Spelling stack base. */ |
5834 static int spelling_size; /* Size of the spelling stack. */ | 5807 static int spelling_size; /* Size of the spelling stack. */ |
5835 | 5808 |
5836 /* Macros to save and restore the spelling stack around push_... functions. | 5809 /* Macros to save and restore the spelling stack around push_... functions. |
5837 Alternative to SAVE_SPELLING_STACK. */ | 5810 Alternative to SAVE_SPELLING_STACK. */ |
5838 | 5811 |
5839 #define SPELLING_DEPTH() (spelling - spelling_base) | 5812 #define SPELLING_DEPTH() (spelling - spelling_base) |
5840 #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH)) | 5813 #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH)) |
5841 | 5814 |
5842 /* Push an element on the spelling stack with type KIND and assign VALUE | 5815 /* Push an element on the spelling stack with type KIND and assign VALUE |
5843 to MEMBER. */ | 5816 to MEMBER. */ |
5844 | 5817 |
5845 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \ | 5818 #define PUSH_SPELLING(KIND, VALUE, MEMBER) \ |
5846 { \ | 5819 { \ |
5847 int depth = SPELLING_DEPTH (); \ | 5820 int depth = SPELLING_DEPTH (); \ |
5848 \ | 5821 \ |
5849 if (depth >= spelling_size) \ | 5822 if (depth >= spelling_size) \ |
5850 { \ | 5823 { \ |
5851 spelling_size += 10; \ | 5824 spelling_size += 10; \ |
5852 spelling_base = XRESIZEVEC (struct spelling, spelling_base, \ | 5825 spelling_base = XRESIZEVEC (struct spelling, spelling_base, \ |
5853 spelling_size); \ | 5826 spelling_size); \ |
5854 RESTORE_SPELLING_DEPTH (depth); \ | 5827 RESTORE_SPELLING_DEPTH (depth); \ |
5855 } \ | 5828 } \ |
5856 \ | 5829 \ |
5857 spelling->kind = (KIND); \ | 5830 spelling->kind = (KIND); \ |
5858 spelling->MEMBER = (VALUE); \ | 5831 spelling->MEMBER = (VALUE); \ |
5859 spelling++; \ | 5832 spelling++; \ |
5860 } | 5833 } |
5861 | 5834 |
5862 /* Push STRING on the stack. Printed literally. */ | 5835 /* Push STRING on the stack. Printed literally. */ |
5863 | 5836 |
5864 static void | 5837 static void |
5896 struct spelling *p; | 5869 struct spelling *p; |
5897 | 5870 |
5898 for (p = spelling_base; p < spelling; p++) | 5871 for (p = spelling_base; p < spelling; p++) |
5899 { | 5872 { |
5900 if (p->kind == SPELLING_BOUNDS) | 5873 if (p->kind == SPELLING_BOUNDS) |
5901 size += 25; | 5874 size += 25; |
5902 else | 5875 else |
5903 size += strlen (p->u.s) + 1; | 5876 size += strlen (p->u.s) + 1; |
5904 } | 5877 } |
5905 | 5878 |
5906 return size; | 5879 return size; |
5907 } | 5880 } |
5908 | 5881 |
5915 struct spelling *p; | 5888 struct spelling *p; |
5916 | 5889 |
5917 for (p = spelling_base; p < spelling; p++) | 5890 for (p = spelling_base; p < spelling; p++) |
5918 if (p->kind == SPELLING_BOUNDS) | 5891 if (p->kind == SPELLING_BOUNDS) |
5919 { | 5892 { |
5920 sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i); | 5893 sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i); |
5921 d += strlen (d); | 5894 d += strlen (d); |
5922 } | 5895 } |
5923 else | 5896 else |
5924 { | 5897 { |
5925 const char *s; | 5898 const char *s; |
5926 if (p->kind == SPELLING_MEMBER) | 5899 if (p->kind == SPELLING_MEMBER) |
5927 *d++ = '.'; | 5900 *d++ = '.'; |
5928 for (s = p->u.s; (*d = *s++); d++) | 5901 for (s = p->u.s; (*d = *s++); d++) |
5929 ; | 5902 ; |
5930 } | 5903 } |
5931 *d++ = '\0'; | 5904 *d++ = '\0'; |
5932 return buffer; | 5905 return buffer; |
5933 } | 5906 } |
5934 | 5907 |
5993 if (pedantic | 5966 if (pedantic |
5994 && TREE_CODE (type) == ARRAY_TYPE | 5967 && TREE_CODE (type) == ARRAY_TYPE |
5995 && TREE_CODE (expr.value) == STRING_CST | 5968 && TREE_CODE (expr.value) == STRING_CST |
5996 && expr.original_code != STRING_CST) | 5969 && expr.original_code != STRING_CST) |
5997 pedwarn_init (input_location, OPT_pedantic, | 5970 pedwarn_init (input_location, OPT_pedantic, |
5998 "array initialized from parenthesized string constant"); | 5971 "array initialized from parenthesized string constant"); |
5999 } | 5972 } |
6000 | 5973 |
6001 /* Digest the parser output INIT as an initializer for type TYPE. | 5974 /* Digest the parser output INIT as an initializer for type TYPE. |
6002 Return a C expression of type TYPE to represent the initial value. | 5975 Return a C expression of type TYPE to represent the initial value. |
6003 | 5976 |
6014 REQUIRE_CONSTANT requests an error if non-constant initializers or | 5987 REQUIRE_CONSTANT requests an error if non-constant initializers or |
6015 elements are seen. */ | 5988 elements are seen. */ |
6016 | 5989 |
6017 static tree | 5990 static tree |
6018 digest_init (location_t init_loc, tree type, tree init, tree origtype, | 5991 digest_init (location_t init_loc, tree type, tree init, tree origtype, |
6019 bool null_pointer_constant, bool strict_string, | 5992 bool null_pointer_constant, bool strict_string, |
6020 int require_constant) | 5993 int require_constant) |
6021 { | 5994 { |
6022 enum tree_code code = TREE_CODE (type); | 5995 enum tree_code code = TREE_CODE (type); |
6023 tree inside_init = init; | 5996 tree inside_init = init; |
6024 tree semantic_type = NULL_TREE; | 5997 tree semantic_type = NULL_TREE; |
6025 bool maybe_const = true; | 5998 bool maybe_const = true; |
6046 if (code == ARRAY_TYPE && inside_init | 6019 if (code == ARRAY_TYPE && inside_init |
6047 && TREE_CODE (inside_init) == STRING_CST) | 6020 && TREE_CODE (inside_init) == STRING_CST) |
6048 { | 6021 { |
6049 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type)); | 6022 tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type)); |
6050 /* Note that an array could be both an array of character type | 6023 /* Note that an array could be both an array of character type |
6051 and an array of wchar_t if wchar_t is signed char or unsigned | 6024 and an array of wchar_t if wchar_t is signed char or unsigned |
6052 char. */ | 6025 char. */ |
6053 bool char_array = (typ1 == char_type_node | 6026 bool char_array = (typ1 == char_type_node |
6054 || typ1 == signed_char_type_node | 6027 || typ1 == signed_char_type_node |
6055 || typ1 == unsigned_char_type_node); | 6028 || typ1 == unsigned_char_type_node); |
6056 bool wchar_array = !!comptypes (typ1, wchar_type_node); | 6029 bool wchar_array = !!comptypes (typ1, wchar_type_node); |
6057 bool char16_array = !!comptypes (typ1, char16_type_node); | 6030 bool char16_array = !!comptypes (typ1, char16_type_node); |
6058 bool char32_array = !!comptypes (typ1, char32_type_node); | 6031 bool char32_array = !!comptypes (typ1, char32_type_node); |
6059 | 6032 |
6060 if (char_array || wchar_array || char16_array || char32_array) | 6033 if (char_array || wchar_array || char16_array || char32_array) |
6061 { | 6034 { |
6062 struct c_expr expr; | 6035 struct c_expr expr; |
6063 tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init))); | 6036 tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init))); |
6064 expr.value = inside_init; | 6037 expr.value = inside_init; |
6065 expr.original_code = (strict_string ? STRING_CST : ERROR_MARK); | 6038 expr.original_code = (strict_string ? STRING_CST : ERROR_MARK); |
6066 expr.original_type = NULL; | 6039 expr.original_type = NULL; |
6067 maybe_warn_string_init (type, expr); | 6040 maybe_warn_string_init (type, expr); |
6068 | 6041 |
6069 if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type))) | 6042 if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type))) |
6070 pedwarn_init (init_loc, OPT_pedantic, | 6043 pedwarn_init (init_loc, OPT_pedantic, |
6071 "initialization of a flexible array member"); | 6044 "initialization of a flexible array member"); |
6072 | 6045 |
6073 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), | 6046 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), |
6074 TYPE_MAIN_VARIANT (type))) | 6047 TYPE_MAIN_VARIANT (type))) |
6075 return inside_init; | 6048 return inside_init; |
6076 | 6049 |
6077 if (char_array) | 6050 if (char_array) |
6078 { | 6051 { |
6079 if (typ2 != char_type_node) | 6052 if (typ2 != char_type_node) |
6080 { | 6053 { |
6081 error_init ("char-array initialized from wide string"); | 6054 error_init ("char-array initialized from wide string"); |
6082 return error_mark_node; | 6055 return error_mark_node; |
6083 } | 6056 } |
6084 } | 6057 } |
6085 else | 6058 else |
6086 { | 6059 { |
6087 if (typ2 == char_type_node) | 6060 if (typ2 == char_type_node) |
6088 { | 6061 { |
6089 error_init ("wide character array initialized from non-wide " | 6062 error_init ("wide character array initialized from non-wide " |
6090 "string"); | 6063 "string"); |
6091 return error_mark_node; | 6064 return error_mark_node; |
6092 } | 6065 } |
6093 else if (!comptypes(typ1, typ2)) | 6066 else if (!comptypes(typ1, typ2)) |
6094 { | 6067 { |
6095 error_init ("wide character array initialized from " | 6068 error_init ("wide character array initialized from " |
6096 "incompatible wide string"); | 6069 "incompatible wide string"); |
6097 return error_mark_node; | 6070 return error_mark_node; |
6098 } | 6071 } |
6099 } | 6072 } |
6100 | 6073 |
6101 TREE_TYPE (inside_init) = type; | 6074 TREE_TYPE (inside_init) = type; |
6102 if (TYPE_DOMAIN (type) != 0 | 6075 if (TYPE_DOMAIN (type) != 0 |
6103 && TYPE_SIZE (type) != 0 | 6076 && TYPE_SIZE (type) != 0 |
6104 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) | 6077 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) |
6105 { | 6078 { |
6106 unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init); | 6079 unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init); |
6107 | 6080 |
6108 /* Subtract the size of a single (possibly wide) character | 6081 /* Subtract the size of a single (possibly wide) character |
6109 because it's ok to ignore the terminating null char | 6082 because it's ok to ignore the terminating null char |
6110 that is counted in the length of the constant. */ | 6083 that is counted in the length of the constant. */ |
6111 if (0 > compare_tree_int (TYPE_SIZE_UNIT (type), | 6084 if (0 > compare_tree_int (TYPE_SIZE_UNIT (type), |
6112 (len | 6085 (len |
6113 - (TYPE_PRECISION (typ1) | 6086 - (TYPE_PRECISION (typ1) |
6114 / BITS_PER_UNIT)))) | 6087 / BITS_PER_UNIT)))) |
6115 pedwarn_init (init_loc, 0, | 6088 pedwarn_init (init_loc, 0, |
6116 ("initializer-string for array of chars " | 6089 ("initializer-string for array of chars " |
6117 "is too long")); | 6090 "is too long")); |
6118 else if (warn_cxx_compat | 6091 else if (warn_cxx_compat |
6119 && 0 > compare_tree_int (TYPE_SIZE_UNIT (type), len)) | 6092 && 0 > compare_tree_int (TYPE_SIZE_UNIT (type), len)) |
6120 warning_at (init_loc, OPT_Wc___compat, | 6093 warning_at (init_loc, OPT_Wc___compat, |
6121 ("initializer-string for array chars " | 6094 ("initializer-string for array chars " |
6122 "is too long for C++")); | 6095 "is too long for C++")); |
6123 } | 6096 } |
6124 | 6097 |
6125 return inside_init; | 6098 return inside_init; |
6126 } | 6099 } |
6127 else if (INTEGRAL_TYPE_P (typ1)) | 6100 else if (INTEGRAL_TYPE_P (typ1)) |
6128 { | 6101 { |
6129 error_init ("array of inappropriate type initialized " | 6102 error_init ("array of inappropriate type initialized " |
6130 "from string constant"); | 6103 "from string constant"); |
6131 return error_mark_node; | 6104 return error_mark_node; |
6132 } | 6105 } |
6133 } | 6106 } |
6134 | 6107 |
6135 /* Build a VECTOR_CST from a *constant* vector constructor. If the | 6108 /* Build a VECTOR_CST from a *constant* vector constructor. If the |
6136 vector constructor is not constant (e.g. {1,2,3,foo()}) then punt | 6109 vector constructor is not constant (e.g. {1,2,3,foo()}) then punt |
6137 below and handle as a constructor. */ | 6110 below and handle as a constructor. */ |
6139 && TREE_CODE (TREE_TYPE (inside_init)) == VECTOR_TYPE | 6112 && TREE_CODE (TREE_TYPE (inside_init)) == VECTOR_TYPE |
6140 && vector_types_convertible_p (TREE_TYPE (inside_init), type, true) | 6113 && vector_types_convertible_p (TREE_TYPE (inside_init), type, true) |
6141 && TREE_CONSTANT (inside_init)) | 6114 && TREE_CONSTANT (inside_init)) |
6142 { | 6115 { |
6143 if (TREE_CODE (inside_init) == VECTOR_CST | 6116 if (TREE_CODE (inside_init) == VECTOR_CST |
6144 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), | 6117 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), |
6145 TYPE_MAIN_VARIANT (type))) | 6118 TYPE_MAIN_VARIANT (type))) |
6146 return inside_init; | 6119 return inside_init; |
6147 | 6120 |
6148 if (TREE_CODE (inside_init) == CONSTRUCTOR) | 6121 if (TREE_CODE (inside_init) == CONSTRUCTOR) |
6149 { | 6122 { |
6150 unsigned HOST_WIDE_INT ix; | 6123 unsigned HOST_WIDE_INT ix; |
6151 tree value; | 6124 tree value; |
6152 bool constant_p = true; | 6125 bool constant_p = true; |
6153 | 6126 |
6154 /* Iterate through elements and check if all constructor | 6127 /* Iterate through elements and check if all constructor |
6155 elements are *_CSTs. */ | 6128 elements are *_CSTs. */ |
6156 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value) | 6129 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value) |
6157 if (!CONSTANT_CLASS_P (value)) | 6130 if (!CONSTANT_CLASS_P (value)) |
6158 { | 6131 { |
6159 constant_p = false; | 6132 constant_p = false; |
6160 break; | 6133 break; |
6161 } | 6134 } |
6162 | 6135 |
6163 if (constant_p) | 6136 if (constant_p) |
6164 return build_vector_from_ctor (type, | 6137 return build_vector_from_ctor (type, |
6165 CONSTRUCTOR_ELTS (inside_init)); | 6138 CONSTRUCTOR_ELTS (inside_init)); |
6166 } | 6139 } |
6167 } | 6140 } |
6168 | 6141 |
6169 if (warn_sequence_point) | 6142 if (warn_sequence_point) |
6170 verify_sequence_points (inside_init); | 6143 verify_sequence_points (inside_init); |
6171 | 6144 |
6172 /* Any type can be initialized | 6145 /* Any type can be initialized |
6173 from an expression of the same type, optionally with braces. */ | 6146 from an expression of the same type, optionally with braces. */ |
6174 | 6147 |
6175 if (inside_init && TREE_TYPE (inside_init) != 0 | 6148 if (inside_init && TREE_TYPE (inside_init) != 0 |
6176 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), | 6149 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), |
6177 TYPE_MAIN_VARIANT (type)) | 6150 TYPE_MAIN_VARIANT (type)) |
6178 || (code == ARRAY_TYPE | 6151 || (code == ARRAY_TYPE |
6179 && comptypes (TREE_TYPE (inside_init), type)) | 6152 && comptypes (TREE_TYPE (inside_init), type)) |
6180 || (code == VECTOR_TYPE | 6153 || (code == VECTOR_TYPE |
6181 && comptypes (TREE_TYPE (inside_init), type)) | 6154 && comptypes (TREE_TYPE (inside_init), type)) |
6182 || (code == POINTER_TYPE | 6155 || (code == POINTER_TYPE |
6183 && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE | 6156 && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE |
6184 && comptypes (TREE_TYPE (TREE_TYPE (inside_init)), | 6157 && comptypes (TREE_TYPE (TREE_TYPE (inside_init)), |
6185 TREE_TYPE (type))))) | 6158 TREE_TYPE (type))))) |
6186 { | 6159 { |
6187 if (code == POINTER_TYPE) | 6160 if (code == POINTER_TYPE) |
6188 { | 6161 { |
6189 if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE) | 6162 if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE) |
6190 { | 6163 { |
6191 if (TREE_CODE (inside_init) == STRING_CST | 6164 if (TREE_CODE (inside_init) == STRING_CST |
6192 || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) | 6165 || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) |
6193 inside_init = array_to_pointer_conversion | 6166 inside_init = array_to_pointer_conversion |
6194 (init_loc, inside_init); | 6167 (init_loc, inside_init); |
6195 else | 6168 else |
6196 { | 6169 { |
6197 error_init ("invalid use of non-lvalue array"); | 6170 error_init ("invalid use of non-lvalue array"); |
6198 return error_mark_node; | 6171 return error_mark_node; |
6199 } | 6172 } |
6200 } | 6173 } |
6201 } | 6174 } |
6202 | 6175 |
6203 if (code == VECTOR_TYPE) | 6176 if (code == VECTOR_TYPE) |
6204 /* Although the types are compatible, we may require a | 6177 /* Although the types are compatible, we may require a |
6205 conversion. */ | 6178 conversion. */ |
6206 inside_init = convert (type, inside_init); | 6179 inside_init = convert (type, inside_init); |
6207 | 6180 |
6208 if (require_constant | 6181 if (require_constant |
6209 && (code == VECTOR_TYPE || !flag_isoc99) | 6182 && (code == VECTOR_TYPE || !flag_isoc99) |
6210 && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) | 6183 && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) |
6211 { | 6184 { |
6212 /* As an extension, allow initializing objects with static storage | 6185 /* As an extension, allow initializing objects with static storage |
6213 duration with compound literals (which are then treated just as | 6186 duration with compound literals (which are then treated just as |
6214 the brace enclosed list they contain). Also allow this for | 6187 the brace enclosed list they contain). Also allow this for |
6215 vectors, as we can only assign them with compound literals. */ | 6188 vectors, as we can only assign them with compound literals. */ |
6216 tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init); | 6189 tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init); |
6217 inside_init = DECL_INITIAL (decl); | 6190 inside_init = DECL_INITIAL (decl); |
6218 } | 6191 } |
6219 | 6192 |
6220 if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST | 6193 if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST |
6221 && TREE_CODE (inside_init) != CONSTRUCTOR) | 6194 && TREE_CODE (inside_init) != CONSTRUCTOR) |
6222 { | 6195 { |
6223 error_init ("array initialized from non-constant array expression"); | 6196 error_init ("array initialized from non-constant array expression"); |
6224 return error_mark_node; | 6197 return error_mark_node; |
6225 } | 6198 } |
6226 | 6199 |
6227 /* Compound expressions can only occur here if -pedantic or | 6200 /* Compound expressions can only occur here if -pedantic or |
6228 -pedantic-errors is specified. In the later case, we always want | 6201 -pedantic-errors is specified. In the later case, we always want |
6229 an error. In the former case, we simply want a warning. */ | 6202 an error. In the former case, we simply want a warning. */ |
6230 if (require_constant && pedantic | 6203 if (require_constant && pedantic |
6231 && TREE_CODE (inside_init) == COMPOUND_EXPR) | 6204 && TREE_CODE (inside_init) == COMPOUND_EXPR) |
6232 { | 6205 { |
6233 inside_init | 6206 inside_init |
6234 = valid_compound_expr_initializer (inside_init, | 6207 = valid_compound_expr_initializer (inside_init, |
6235 TREE_TYPE (inside_init)); | 6208 TREE_TYPE (inside_init)); |
6236 if (inside_init == error_mark_node) | 6209 if (inside_init == error_mark_node) |
6237 error_init ("initializer element is not constant"); | 6210 error_init ("initializer element is not constant"); |
6238 else | 6211 else |
6239 pedwarn_init (init_loc, OPT_pedantic, | 6212 pedwarn_init (init_loc, OPT_pedantic, |
6240 "initializer element is not constant"); | 6213 "initializer element is not constant"); |
6241 if (flag_pedantic_errors) | 6214 if (flag_pedantic_errors) |
6242 inside_init = error_mark_node; | 6215 inside_init = error_mark_node; |
6243 } | 6216 } |
6244 else if (require_constant | 6217 else if (require_constant |
6245 && !initializer_constant_valid_p (inside_init, | 6218 && !initializer_constant_valid_p (inside_init, |
6246 TREE_TYPE (inside_init))) | 6219 TREE_TYPE (inside_init))) |
6247 { | 6220 { |
6248 error_init ("initializer element is not constant"); | 6221 error_init ("initializer element is not constant"); |
6249 inside_init = error_mark_node; | 6222 inside_init = error_mark_node; |
6250 } | 6223 } |
6251 else if (require_constant && !maybe_const) | 6224 else if (require_constant && !maybe_const) |
6252 pedwarn_init (init_loc, 0, | 6225 pedwarn_init (init_loc, 0, |
6253 "initializer element is not a constant expression"); | 6226 "initializer element is not a constant expression"); |
6254 | 6227 |
6255 /* Added to enable additional -Wmissing-format-attribute warnings. */ | 6228 /* Added to enable additional -Wmissing-format-attribute warnings. */ |
6256 if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE) | 6229 if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE) |
6257 inside_init = convert_for_assignment (init_loc, type, inside_init, | 6230 inside_init = convert_for_assignment (init_loc, type, inside_init, |
6258 origtype, | 6231 origtype, |
6259 ic_init, null_pointer_constant, | 6232 ic_init, null_pointer_constant, |
6260 NULL_TREE, NULL_TREE, 0); | 6233 NULL_TREE, NULL_TREE, 0); |
6261 return inside_init; | 6234 return inside_init; |
6262 } | 6235 } |
6263 | 6236 |
6264 /* Handle scalar types, including conversions. */ | 6237 /* Handle scalar types, including conversions. */ |
6265 | 6238 |
6266 if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE | 6239 if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE |
6267 || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE | 6240 || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE |
6268 || code == COMPLEX_TYPE || code == VECTOR_TYPE) | 6241 || code == COMPLEX_TYPE || code == VECTOR_TYPE) |
6269 { | 6242 { |
6270 if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE | 6243 if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE |
6271 && (TREE_CODE (init) == STRING_CST | 6244 && (TREE_CODE (init) == STRING_CST |
6272 || TREE_CODE (init) == COMPOUND_LITERAL_EXPR)) | 6245 || TREE_CODE (init) == COMPOUND_LITERAL_EXPR)) |
6273 inside_init = init = array_to_pointer_conversion (init_loc, init); | 6246 inside_init = init = array_to_pointer_conversion (init_loc, init); |
6274 if (semantic_type) | 6247 if (semantic_type) |
6275 inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type, | 6248 inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type, |
6276 inside_init); | 6249 inside_init); |
6277 inside_init | 6250 inside_init |
6278 = convert_for_assignment (init_loc, type, inside_init, origtype, | 6251 = convert_for_assignment (init_loc, type, inside_init, origtype, |
6279 ic_init, null_pointer_constant, | 6252 ic_init, null_pointer_constant, |
6280 NULL_TREE, NULL_TREE, 0); | 6253 NULL_TREE, NULL_TREE, 0); |
6281 | 6254 |
6282 /* Check to see if we have already given an error message. */ | 6255 /* Check to see if we have already given an error message. */ |
6283 if (inside_init == error_mark_node) | 6256 if (inside_init == error_mark_node) |
6284 ; | 6257 ; |
6285 else if (require_constant && !TREE_CONSTANT (inside_init)) | 6258 else if (require_constant && !TREE_CONSTANT (inside_init)) |
6286 { | 6259 { |
6287 error_init ("initializer element is not constant"); | 6260 error_init ("initializer element is not constant"); |
6288 inside_init = error_mark_node; | 6261 inside_init = error_mark_node; |
6289 } | 6262 } |
6290 else if (require_constant | 6263 else if (require_constant |
6291 && !initializer_constant_valid_p (inside_init, | 6264 && !initializer_constant_valid_p (inside_init, |
6292 TREE_TYPE (inside_init))) | 6265 TREE_TYPE (inside_init))) |
6293 { | 6266 { |
6294 error_init ("initializer element is not computable at load time"); | 6267 error_init ("initializer element is not computable at load time"); |
6295 inside_init = error_mark_node; | 6268 inside_init = error_mark_node; |
6296 } | 6269 } |
6297 else if (require_constant && !maybe_const) | 6270 else if (require_constant && !maybe_const) |
6298 pedwarn_init (init_loc, 0, | 6271 pedwarn_init (init_loc, 0, |
6299 "initializer element is not a constant expression"); | 6272 "initializer element is not a constant expression"); |
6300 | 6273 |
6301 return inside_init; | 6274 return inside_init; |
6302 } | 6275 } |
6303 | 6276 |
6304 /* Come here only for records and arrays. */ | 6277 /* Come here only for records and arrays. */ |
6503 | 6476 |
6504 if (decl != 0 && decl != error_mark_node) | 6477 if (decl != 0 && decl != error_mark_node) |
6505 { | 6478 { |
6506 require_constant_value = TREE_STATIC (decl); | 6479 require_constant_value = TREE_STATIC (decl); |
6507 require_constant_elements | 6480 require_constant_elements |
6508 = ((TREE_STATIC (decl) || (pedantic && !flag_isoc99)) | 6481 = ((TREE_STATIC (decl) || (pedantic && !flag_isoc99)) |
6509 /* For a scalar, you can always use any value to initialize, | 6482 /* For a scalar, you can always use any value to initialize, |
6510 even within braces. */ | 6483 even within braces. */ |
6511 && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | 6484 && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE |
6512 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE | 6485 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE |
6513 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE | 6486 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE |
6514 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE)); | 6487 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE)); |
6515 locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))); | 6488 locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))); |
6516 } | 6489 } |
6517 else | 6490 else |
6518 { | 6491 { |
6519 require_constant_value = 0; | 6492 require_constant_value = 0; |
6656 constructor_index | 6629 constructor_index |
6657 = convert (bitsizetype, | 6630 = convert (bitsizetype, |
6658 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); | 6631 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); |
6659 } | 6632 } |
6660 else | 6633 else |
6661 { | 6634 { |
6662 constructor_index = bitsize_zero_node; | 6635 constructor_index = bitsize_zero_node; |
6663 constructor_max_index = NULL_TREE; | 6636 constructor_max_index = NULL_TREE; |
6664 } | 6637 } |
6665 | 6638 |
6666 constructor_unfilled_index = constructor_index; | 6639 constructor_unfilled_index = constructor_index; |
6667 } | 6640 } |
6668 else if (TREE_CODE (constructor_type) == VECTOR_TYPE) | 6641 else if (TREE_CODE (constructor_type) == VECTOR_TYPE) |
6669 { | 6642 { |
6670 /* Vectors are like simple fixed-size arrays. */ | 6643 /* Vectors are like simple fixed-size arrays. */ |
6671 constructor_max_index = | 6644 constructor_max_index = |
6672 build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1); | 6645 build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1); |
6673 constructor_index = bitsize_zero_node; | 6646 constructor_index = bitsize_zero_node; |
6674 constructor_unfilled_index = constructor_index; | 6647 constructor_unfilled_index = constructor_index; |
6675 } | 6648 } |
6676 else | 6649 else |
6677 { | 6650 { |
6775 /* Don't die if an entire brace-pair level is superfluous | 6748 /* Don't die if an entire brace-pair level is superfluous |
6776 in the containing level. */ | 6749 in the containing level. */ |
6777 if (constructor_type == 0) | 6750 if (constructor_type == 0) |
6778 ; | 6751 ; |
6779 else if (TREE_CODE (constructor_type) == RECORD_TYPE | 6752 else if (TREE_CODE (constructor_type) == RECORD_TYPE |
6780 || TREE_CODE (constructor_type) == UNION_TYPE) | 6753 || TREE_CODE (constructor_type) == UNION_TYPE) |
6781 { | 6754 { |
6782 /* Don't die if there are extra init elts at the end. */ | 6755 /* Don't die if there are extra init elts at the end. */ |
6783 if (constructor_fields == 0) | 6756 if (constructor_fields == 0) |
6784 constructor_type = 0; | 6757 constructor_type = 0; |
6785 else | 6758 else |
6786 { | 6759 { |
6787 constructor_type = TREE_TYPE (constructor_fields); | 6760 constructor_type = TREE_TYPE (constructor_fields); |
6788 push_member_name (constructor_fields); | 6761 push_member_name (constructor_fields); |
6789 constructor_depth++; | 6762 constructor_depth++; |
6790 } | 6763 } |
6791 } | 6764 } |
6792 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 6765 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
6793 { | 6766 { |
6794 constructor_type = TREE_TYPE (constructor_type); | 6767 constructor_type = TREE_TYPE (constructor_type); |
6795 push_array_bounds (tree_low_cst (constructor_index, 1)); | 6768 push_array_bounds (tree_low_cst (constructor_index, 1)); |
6821 missing_braces_mentioned = 1; | 6794 missing_braces_mentioned = 1; |
6822 warning_init (OPT_Wmissing_braces, "missing braces around initializer"); | 6795 warning_init (OPT_Wmissing_braces, "missing braces around initializer"); |
6823 } | 6796 } |
6824 | 6797 |
6825 if (TREE_CODE (constructor_type) == RECORD_TYPE | 6798 if (TREE_CODE (constructor_type) == RECORD_TYPE |
6826 || TREE_CODE (constructor_type) == UNION_TYPE) | 6799 || TREE_CODE (constructor_type) == UNION_TYPE) |
6827 { | 6800 { |
6828 constructor_fields = TYPE_FIELDS (constructor_type); | 6801 constructor_fields = TYPE_FIELDS (constructor_type); |
6829 /* Skip any nameless bit fields at the beginning. */ | 6802 /* Skip any nameless bit fields at the beginning. */ |
6830 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields) | 6803 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields) |
6831 && DECL_NAME (constructor_fields) == 0) | 6804 && DECL_NAME (constructor_fields) == 0) |
6836 } | 6809 } |
6837 else if (TREE_CODE (constructor_type) == VECTOR_TYPE) | 6810 else if (TREE_CODE (constructor_type) == VECTOR_TYPE) |
6838 { | 6811 { |
6839 /* Vectors are like simple fixed-size arrays. */ | 6812 /* Vectors are like simple fixed-size arrays. */ |
6840 constructor_max_index = | 6813 constructor_max_index = |
6841 build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1); | 6814 build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1); |
6842 constructor_index = convert (bitsizetype, integer_zero_node); | 6815 constructor_index = convert (bitsizetype, integer_zero_node); |
6843 constructor_unfilled_index = constructor_index; | 6816 constructor_unfilled_index = constructor_index; |
6844 } | 6817 } |
6845 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 6818 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
6846 { | 6819 { |
6864 constructor_index | 6837 constructor_index |
6865 = convert (bitsizetype, | 6838 = convert (bitsizetype, |
6866 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); | 6839 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); |
6867 } | 6840 } |
6868 else | 6841 else |
6869 constructor_index = bitsize_zero_node; | 6842 constructor_index = bitsize_zero_node; |
6870 | 6843 |
6871 constructor_unfilled_index = constructor_index; | 6844 constructor_unfilled_index = constructor_index; |
6872 if (value && TREE_CODE (value) == STRING_CST) | 6845 if (value && TREE_CODE (value) == STRING_CST) |
6873 { | 6846 { |
6874 /* We need to split the char/wchar array into individual | 6847 /* We need to split the char/wchar array into individual |
6878 } | 6851 } |
6879 } | 6852 } |
6880 else | 6853 else |
6881 { | 6854 { |
6882 if (constructor_type != error_mark_node) | 6855 if (constructor_type != error_mark_node) |
6883 warning_init (0, "braces around scalar initializer"); | 6856 warning_init (0, "braces around scalar initializer"); |
6884 constructor_fields = constructor_type; | 6857 constructor_fields = constructor_type; |
6885 constructor_unfilled_fields = constructor_type; | 6858 constructor_unfilled_fields = constructor_type; |
6886 } | 6859 } |
6887 } | 6860 } |
6888 | 6861 |
6907 ret.original_type = NULL; | 6880 ret.original_type = NULL; |
6908 | 6881 |
6909 if (implicit == 0) | 6882 if (implicit == 0) |
6910 { | 6883 { |
6911 /* When we come to an explicit close brace, | 6884 /* When we come to an explicit close brace, |
6912 pop any inner levels that didn't have explicit braces. */ | 6885 pop any inner levels that didn't have explicit braces. */ |
6913 while (constructor_stack->implicit) | 6886 while (constructor_stack->implicit) |
6914 { | 6887 { |
6915 process_init_element (pop_init_level (1, braced_init_obstack), | 6888 process_init_element (pop_init_level (1, braced_init_obstack), |
6916 true, braced_init_obstack); | 6889 true, braced_init_obstack); |
6917 } | 6890 } |
6930 && TREE_CODE (constructor_type) == ARRAY_TYPE | 6903 && TREE_CODE (constructor_type) == ARRAY_TYPE |
6931 && TYPE_DOMAIN (constructor_type) | 6904 && TYPE_DOMAIN (constructor_type) |
6932 && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type))) | 6905 && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type))) |
6933 { | 6906 { |
6934 /* Silently discard empty initializations. The parser will | 6907 /* Silently discard empty initializations. The parser will |
6935 already have pedwarned for empty brackets. */ | 6908 already have pedwarned for empty brackets. */ |
6936 if (integer_zerop (constructor_unfilled_index)) | 6909 if (integer_zerop (constructor_unfilled_index)) |
6937 constructor_type = NULL_TREE; | 6910 constructor_type = NULL_TREE; |
6938 else | 6911 else |
6939 { | 6912 { |
6940 gcc_assert (!TYPE_SIZE (constructor_type)); | 6913 gcc_assert (!TYPE_SIZE (constructor_type)); |
6941 | 6914 |
6942 if (constructor_depth > 2) | 6915 if (constructor_depth > 2) |
6943 error_init ("initialization of flexible array member in a nested context"); | 6916 error_init ("initialization of flexible array member in a nested context"); |
6944 else | 6917 else |
6945 pedwarn_init (input_location, OPT_pedantic, | 6918 pedwarn_init (input_location, OPT_pedantic, |
6946 "initialization of a flexible array member"); | 6919 "initialization of a flexible array member"); |
6947 | |
6948 | 6920 |
6949 /* We have already issued an error message for the existence | 6921 /* We have already issued an error message for the existence |
6950 of a flexible array member not at the end of the structure. | 6922 of a flexible array member not at the end of the structure. |
6951 Discard the initializer so that we do not die later. */ | 6923 Discard the initializer so that we do not die later. */ |
6952 if (DECL_CHAIN (constructor_fields) != NULL_TREE) | 6924 if (DECL_CHAIN (constructor_fields) != NULL_TREE) |
6971 if (constructor_unfilled_fields && !constructor_designated) | 6943 if (constructor_unfilled_fields && !constructor_designated) |
6972 { | 6944 { |
6973 push_member_name (constructor_unfilled_fields); | 6945 push_member_name (constructor_unfilled_fields); |
6974 warning_init (OPT_Wmissing_field_initializers, | 6946 warning_init (OPT_Wmissing_field_initializers, |
6975 "missing initializer"); | 6947 "missing initializer"); |
6976 RESTORE_SPELLING_DEPTH (constructor_depth); | 6948 RESTORE_SPELLING_DEPTH (constructor_depth); |
6977 } | 6949 } |
6978 } | 6950 } |
6979 | 6951 |
6980 /* Pad out the end of the structure. */ | 6952 /* Pad out the end of the structure. */ |
6981 if (p->replacement_value.value) | 6953 if (p->replacement_value.value) |
6982 /* If this closes a superfluous brace pair, | 6954 /* If this closes a superfluous brace pair, |
6983 just pass out the element between them. */ | 6955 just pass out the element between them. */ |
6984 ret = p->replacement_value; | 6956 ret = p->replacement_value; |
6985 else if (constructor_type == 0) | 6957 else if (constructor_type == 0) |
6986 ; | 6958 ; |
6987 else if (TREE_CODE (constructor_type) != RECORD_TYPE | 6959 else if (TREE_CODE (constructor_type) != RECORD_TYPE |
6988 && TREE_CODE (constructor_type) != UNION_TYPE | 6960 && TREE_CODE (constructor_type) != UNION_TYPE |
6989 && TREE_CODE (constructor_type) != ARRAY_TYPE | 6961 && TREE_CODE (constructor_type) != ARRAY_TYPE |
6990 && TREE_CODE (constructor_type) != VECTOR_TYPE) | 6962 && TREE_CODE (constructor_type) != VECTOR_TYPE) |
6991 { | 6963 { |
6992 /* A nonincremental scalar initializer--just return | 6964 /* A nonincremental scalar initializer--just return |
6993 the element, after verifying there is just one. */ | 6965 the element, after verifying there is just one. */ |
6994 if (VEC_empty (constructor_elt,constructor_elements)) | 6966 if (VEC_empty (constructor_elt,constructor_elements)) |
6995 { | 6967 { |
6996 if (!constructor_erroneous) | 6968 if (!constructor_erroneous) |
6997 error_init ("empty scalar initializer"); | 6969 error_init ("empty scalar initializer"); |
6998 ret.value = error_mark_node; | 6970 ret.value = error_mark_node; |
6999 } | 6971 } |
7000 else if (VEC_length (constructor_elt,constructor_elements) != 1) | 6972 else if (VEC_length (constructor_elt,constructor_elements) != 1) |
7001 { | 6973 { |
7002 error_init ("extra elements in scalar initializer"); | 6974 error_init ("extra elements in scalar initializer"); |
7003 ret.value = VEC_index (constructor_elt,constructor_elements,0)->value; | 6975 ret.value = VEC_index (constructor_elt,constructor_elements,0)->value; |
7004 } | 6976 } |
7005 else | 6977 else |
7006 ret.value = VEC_index (constructor_elt,constructor_elements,0)->value; | 6978 ret.value = VEC_index (constructor_elt,constructor_elements,0)->value; |
7007 } | 6979 } |
7008 else | 6980 else |
7009 { | 6981 { |
7010 if (constructor_erroneous) | 6982 if (constructor_erroneous) |
7011 ret.value = error_mark_node; | 6983 ret.value = error_mark_node; |
7012 else | 6984 else |
7013 { | 6985 { |
7014 ret.value = build_constructor (constructor_type, | 6986 ret.value = build_constructor (constructor_type, |
7015 constructor_elements); | 6987 constructor_elements); |
7016 if (constructor_constant) | 6988 if (constructor_constant) |
7017 TREE_CONSTANT (ret.value) = 1; | 6989 TREE_CONSTANT (ret.value) = 1; |
7018 if (constructor_constant && constructor_simple) | 6990 if (constructor_constant && constructor_simple) |
7019 TREE_STATIC (ret.value) = 1; | 6991 TREE_STATIC (ret.value) = 1; |
6992 if (constructor_nonconst) | |
6993 CONSTRUCTOR_NON_CONST (ret.value) = 1; | |
6994 } | |
6995 } | |
6996 | |
6997 if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR) | |
6998 { | |
7020 if (constructor_nonconst) | 6999 if (constructor_nonconst) |
7021 CONSTRUCTOR_NON_CONST (ret.value) = 1; | 7000 ret.original_code = C_MAYBE_CONST_EXPR; |
7022 } | |
7023 } | |
7024 | |
7025 if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR) | |
7026 { | |
7027 if (constructor_nonconst) | |
7028 ret.original_code = C_MAYBE_CONST_EXPR; | |
7029 else if (ret.original_code == C_MAYBE_CONST_EXPR) | 7001 else if (ret.original_code == C_MAYBE_CONST_EXPR) |
7030 ret.original_code = ERROR_MARK; | 7002 ret.original_code = ERROR_MARK; |
7031 } | 7003 } |
7032 | 7004 |
7033 constructor_type = p->type; | 7005 constructor_type = p->type; |
7034 constructor_fields = p->fields; | 7006 constructor_fields = p->fields; |
7035 constructor_index = p->index; | 7007 constructor_index = p->index; |
7080 if (!designator_depth) | 7052 if (!designator_depth) |
7081 { | 7053 { |
7082 gcc_assert (!constructor_range_stack); | 7054 gcc_assert (!constructor_range_stack); |
7083 | 7055 |
7084 /* Designator list starts at the level of closest explicit | 7056 /* Designator list starts at the level of closest explicit |
7085 braces. */ | 7057 braces. */ |
7086 while (constructor_stack->implicit) | 7058 while (constructor_stack->implicit) |
7087 { | 7059 { |
7088 process_init_element (pop_init_level (1, braced_init_obstack), | 7060 process_init_element (pop_init_level (1, braced_init_obstack), |
7089 true, braced_init_obstack); | 7061 true, braced_init_obstack); |
7090 } | 7062 } |
7096 { | 7068 { |
7097 case RECORD_TYPE: | 7069 case RECORD_TYPE: |
7098 case UNION_TYPE: | 7070 case UNION_TYPE: |
7099 subtype = TREE_TYPE (constructor_fields); | 7071 subtype = TREE_TYPE (constructor_fields); |
7100 if (subtype != error_mark_node) | 7072 if (subtype != error_mark_node) |
7101 subtype = TYPE_MAIN_VARIANT (subtype); | 7073 subtype = TYPE_MAIN_VARIANT (subtype); |
7102 break; | 7074 break; |
7103 case ARRAY_TYPE: | 7075 case ARRAY_TYPE: |
7104 subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type)); | 7076 subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type)); |
7105 break; | 7077 break; |
7106 default: | 7078 default: |
7170 | 7142 |
7171 if (TREE_CODE (first) != INTEGER_CST) | 7143 if (TREE_CODE (first) != INTEGER_CST) |
7172 { | 7144 { |
7173 first = c_fully_fold (first, false, NULL); | 7145 first = c_fully_fold (first, false, NULL); |
7174 if (TREE_CODE (first) == INTEGER_CST) | 7146 if (TREE_CODE (first) == INTEGER_CST) |
7175 pedwarn_init (input_location, OPT_pedantic, | 7147 pedwarn_init (input_location, OPT_pedantic, |
7176 "array index in initializer is not " | 7148 "array index in initializer is not " |
7177 "an integer constant expression"); | 7149 "an integer constant expression"); |
7178 } | 7150 } |
7179 | 7151 |
7180 if (last && TREE_CODE (last) != INTEGER_CST) | 7152 if (last && TREE_CODE (last) != INTEGER_CST) |
7181 { | 7153 { |
7182 last = c_fully_fold (last, false, NULL); | 7154 last = c_fully_fold (last, false, NULL); |
7183 if (TREE_CODE (last) == INTEGER_CST) | 7155 if (TREE_CODE (last) == INTEGER_CST) |
7184 pedwarn_init (input_location, OPT_pedantic, | 7156 pedwarn_init (input_location, OPT_pedantic, |
7185 "array index in initializer is not " | 7157 "array index in initializer is not " |
7186 "an integer constant expression"); | 7158 "an integer constant expression"); |
7187 } | 7159 } |
7188 | 7160 |
7189 if (TREE_CODE (first) != INTEGER_CST) | 7161 if (TREE_CODE (first) != INTEGER_CST) |
7190 error_init ("nonconstant array index in initializer"); | 7162 error_init ("nonconstant array index in initializer"); |
7191 else if (last != 0 && TREE_CODE (last) != INTEGER_CST) | 7163 else if (last != 0 && TREE_CODE (last) != INTEGER_CST) |
7193 else if (TREE_CODE (constructor_type) != ARRAY_TYPE) | 7165 else if (TREE_CODE (constructor_type) != ARRAY_TYPE) |
7194 error_init ("array index in non-array initializer"); | 7166 error_init ("array index in non-array initializer"); |
7195 else if (tree_int_cst_sgn (first) == -1) | 7167 else if (tree_int_cst_sgn (first) == -1) |
7196 error_init ("array index in initializer exceeds array bounds"); | 7168 error_init ("array index in initializer exceeds array bounds"); |
7197 else if (constructor_max_index | 7169 else if (constructor_max_index |
7198 && tree_int_cst_lt (constructor_max_index, first)) | 7170 && tree_int_cst_lt (constructor_max_index, first)) |
7199 error_init ("array index in initializer exceeds array bounds"); | 7171 error_init ("array index in initializer exceeds array bounds"); |
7200 else | 7172 else |
7201 { | 7173 { |
7202 constant_expression_warning (first); | 7174 constant_expression_warning (first); |
7203 if (last) | 7175 if (last) |
7204 constant_expression_warning (last); | 7176 constant_expression_warning (last); |
7205 constructor_index = convert (bitsizetype, first); | 7177 constructor_index = convert (bitsizetype, first); |
7206 | 7178 |
7207 if (last) | 7179 if (last) |
7208 { | 7180 { |
7209 if (tree_int_cst_equal (first, last)) | 7181 if (tree_int_cst_equal (first, last)) |
7210 last = 0; | 7182 last = 0; |
7211 else if (tree_int_cst_lt (last, first)) | 7183 else if (tree_int_cst_lt (last, first)) |
7212 { | 7184 { |
7213 error_init ("empty index range in initializer"); | 7185 error_init ("empty index range in initializer"); |
7214 last = 0; | 7186 last = 0; |
7215 } | 7187 } |
7216 else | 7188 else |
7217 { | 7189 { |
7218 last = convert (bitsizetype, last); | 7190 last = convert (bitsizetype, last); |
7219 if (constructor_max_index != 0 | 7191 if (constructor_max_index != 0 |
7220 && tree_int_cst_lt (constructor_max_index, last)) | 7192 && tree_int_cst_lt (constructor_max_index, last)) |
7221 { | 7193 { |
7222 error_init ("array index range in initializer exceeds array bounds"); | 7194 error_init ("array index range in initializer exceeds array bounds"); |
7223 last = 0; | 7195 last = 0; |
7224 } | 7196 } |
7225 } | 7197 } |
7226 } | 7198 } |
7227 | 7199 |
7228 designator_depth++; | 7200 designator_depth++; |
7229 designator_erroneous = 0; | 7201 designator_erroneous = 0; |
7230 if (constructor_range_stack || last) | 7202 if (constructor_range_stack || last) |
7231 push_range_stack (last, braced_init_obstack); | 7203 push_range_stack (last, braced_init_obstack); |
7253 | 7225 |
7254 field = lookup_field (constructor_type, fieldname); | 7226 field = lookup_field (constructor_type, fieldname); |
7255 | 7227 |
7256 if (field == 0) | 7228 if (field == 0) |
7257 error ("unknown field %qE specified in initializer", fieldname); | 7229 error ("unknown field %qE specified in initializer", fieldname); |
7258 else | 7230 else |
7259 do | 7231 do |
7260 { | 7232 { |
7261 constructor_fields = TREE_VALUE (field); | 7233 constructor_fields = TREE_VALUE (field); |
7262 designator_depth++; | 7234 designator_depth++; |
7263 designator_erroneous = 0; | 7235 designator_erroneous = 0; |
7269 if (set_designator (0, braced_init_obstack)) | 7241 if (set_designator (0, braced_init_obstack)) |
7270 return; | 7242 return; |
7271 } | 7243 } |
7272 } | 7244 } |
7273 while (field != NULL_TREE); | 7245 while (field != NULL_TREE); |
7274 | 7246 } |
7275 } | 7247 |
7276 | |
7277 /* Add a new initializer to the tree of pending initializers. PURPOSE | 7248 /* Add a new initializer to the tree of pending initializers. PURPOSE |
7278 identifies the initializer, either array index or field in a structure. | 7249 identifies the initializer, either array index or field in a structure. |
7279 VALUE is the value of that index or field. If ORIGTYPE is not | 7250 VALUE is the value of that index or field. If ORIGTYPE is not |
7280 NULL_TREE, it is the original type of VALUE. | 7251 NULL_TREE, it is the original type of VALUE. |
7281 | 7252 |
7294 p = 0; | 7265 p = 0; |
7295 | 7266 |
7296 if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 7267 if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
7297 { | 7268 { |
7298 while (*q != 0) | 7269 while (*q != 0) |
7299 { | 7270 { |
7300 p = *q; | 7271 p = *q; |
7301 if (tree_int_cst_lt (purpose, p->purpose)) | 7272 if (tree_int_cst_lt (purpose, p->purpose)) |
7302 q = &p->left; | 7273 q = &p->left; |
7303 else if (tree_int_cst_lt (p->purpose, purpose)) | 7274 else if (tree_int_cst_lt (p->purpose, purpose)) |
7304 q = &p->right; | 7275 q = &p->right; |
7305 else | 7276 else |
7306 { | 7277 { |
7307 if (!implicit) | 7278 if (!implicit) |
7308 { | 7279 { |
7309 if (TREE_SIDE_EFFECTS (p->value)) | 7280 if (TREE_SIDE_EFFECTS (p->value)) |
7310 warning_init (0, "initialized field with side-effects overwritten"); | 7281 warning_init (0, "initialized field with side-effects overwritten"); |
7311 else if (warn_override_init) | 7282 else if (warn_override_init) |
7312 warning_init (OPT_Woverride_init, "initialized field overwritten"); | 7283 warning_init (OPT_Woverride_init, "initialized field overwritten"); |
7313 } | 7284 } |
7314 p->value = value; | 7285 p->value = value; |
7315 p->origtype = origtype; | 7286 p->origtype = origtype; |
7316 return; | 7287 return; |
7317 } | 7288 } |
7318 } | 7289 } |
7319 } | 7290 } |
7320 else | 7291 else |
7321 { | 7292 { |
7322 tree bitpos; | 7293 tree bitpos; |
7323 | 7294 |
7324 bitpos = bit_position (purpose); | 7295 bitpos = bit_position (purpose); |
7325 while (*q != NULL) | 7296 while (*q != NULL) |
7326 { | 7297 { |
7327 p = *q; | 7298 p = *q; |
7328 if (tree_int_cst_lt (bitpos, bit_position (p->purpose))) | 7299 if (tree_int_cst_lt (bitpos, bit_position (p->purpose))) |
7329 q = &p->left; | 7300 q = &p->left; |
7330 else if (p->purpose != purpose) | 7301 else if (p->purpose != purpose) |
7331 q = &p->right; | 7302 q = &p->right; |
7332 else | 7303 else |
7333 { | 7304 { |
7334 if (!implicit) | 7305 if (!implicit) |
7335 { | 7306 { |
7336 if (TREE_SIDE_EFFECTS (p->value)) | 7307 if (TREE_SIDE_EFFECTS (p->value)) |
7337 warning_init (0, "initialized field with side-effects overwritten"); | 7308 warning_init (0, "initialized field with side-effects overwritten"); |
7338 else if (warn_override_init) | 7309 else if (warn_override_init) |
7339 warning_init (OPT_Woverride_init, "initialized field overwritten"); | 7310 warning_init (OPT_Woverride_init, "initialized field overwritten"); |
7340 } | 7311 } |
7341 p->value = value; | 7312 p->value = value; |
7342 p->origtype = origtype; | 7313 p->origtype = origtype; |
7343 return; | 7314 return; |
7344 } | 7315 } |
7345 } | 7316 } |
7346 } | 7317 } |
7347 | 7318 |
7348 r = (struct init_node *) obstack_alloc (braced_init_obstack, | 7319 r = (struct init_node *) obstack_alloc (braced_init_obstack, |
7349 sizeof (struct init_node)); | 7320 sizeof (struct init_node)); |
7350 r->purpose = purpose; | 7321 r->purpose = purpose; |
7360 while (p) | 7331 while (p) |
7361 { | 7332 { |
7362 struct init_node *s; | 7333 struct init_node *s; |
7363 | 7334 |
7364 if (r == p->left) | 7335 if (r == p->left) |
7365 { | 7336 { |
7366 if (p->balance == 0) | 7337 if (p->balance == 0) |
7367 p->balance = -1; | 7338 p->balance = -1; |
7368 else if (p->balance < 0) | 7339 else if (p->balance < 0) |
7369 { | 7340 { |
7370 if (r->balance < 0) | 7341 if (r->balance < 0) |
7371 { | 7342 { |
7372 /* L rotation. */ | 7343 /* L rotation. */ |
7373 p->left = r->right; | 7344 p->left = r->right; |
7374 if (p->left) | 7345 if (p->left) |
7375 p->left->parent = p; | 7346 p->left->parent = p; |
7376 r->right = p; | 7347 r->right = p; |
7377 | 7348 |
7378 p->balance = 0; | 7349 p->balance = 0; |
7379 r->balance = 0; | 7350 r->balance = 0; |
7380 | 7351 |
7381 s = p->parent; | 7352 s = p->parent; |
7382 p->parent = r; | 7353 p->parent = r; |
7383 r->parent = s; | 7354 r->parent = s; |
7384 if (s) | 7355 if (s) |
7385 { | 7356 { |
7386 if (s->left == p) | 7357 if (s->left == p) |
7387 s->left = r; | 7358 s->left = r; |
7388 else | 7359 else |
7389 s->right = r; | 7360 s->right = r; |
7390 } | 7361 } |
7391 else | 7362 else |
7392 constructor_pending_elts = r; | 7363 constructor_pending_elts = r; |
7393 } | 7364 } |
7394 else | 7365 else |
7395 { | 7366 { |
7396 /* LR rotation. */ | 7367 /* LR rotation. */ |
7397 struct init_node *t = r->right; | 7368 struct init_node *t = r->right; |
7398 | 7369 |
7399 r->right = t->left; | 7370 r->right = t->left; |
7400 if (r->right) | 7371 if (r->right) |
7401 r->right->parent = r; | 7372 r->right->parent = r; |
7402 t->left = r; | 7373 t->left = r; |
7403 | 7374 |
7404 p->left = t->right; | 7375 p->left = t->right; |
7405 if (p->left) | 7376 if (p->left) |
7406 p->left->parent = p; | 7377 p->left->parent = p; |
7407 t->right = p; | 7378 t->right = p; |
7408 | 7379 |
7409 p->balance = t->balance < 0; | 7380 p->balance = t->balance < 0; |
7410 r->balance = -(t->balance > 0); | 7381 r->balance = -(t->balance > 0); |
7411 t->balance = 0; | 7382 t->balance = 0; |
7412 | 7383 |
7413 s = p->parent; | 7384 s = p->parent; |
7414 p->parent = t; | 7385 p->parent = t; |
7415 r->parent = t; | 7386 r->parent = t; |
7416 t->parent = s; | 7387 t->parent = s; |
7417 if (s) | 7388 if (s) |
7418 { | 7389 { |
7419 if (s->left == p) | 7390 if (s->left == p) |
7420 s->left = t; | 7391 s->left = t; |
7421 else | 7392 else |
7422 s->right = t; | 7393 s->right = t; |
7423 } | 7394 } |
7424 else | 7395 else |
7425 constructor_pending_elts = t; | 7396 constructor_pending_elts = t; |
7426 } | 7397 } |
7427 break; | 7398 break; |
7428 } | 7399 } |
7429 else | 7400 else |
7430 { | 7401 { |
7431 /* p->balance == +1; growth of left side balances the node. */ | 7402 /* p->balance == +1; growth of left side balances the node. */ |
7432 p->balance = 0; | 7403 p->balance = 0; |
7433 break; | 7404 break; |
7434 } | 7405 } |
7435 } | 7406 } |
7436 else /* r == p->right */ | 7407 else /* r == p->right */ |
7437 { | 7408 { |
7438 if (p->balance == 0) | 7409 if (p->balance == 0) |
7439 /* Growth propagation from right side. */ | 7410 /* Growth propagation from right side. */ |
7440 p->balance++; | 7411 p->balance++; |
7441 else if (p->balance > 0) | 7412 else if (p->balance > 0) |
7442 { | 7413 { |
7443 if (r->balance > 0) | 7414 if (r->balance > 0) |
7444 { | 7415 { |
7445 /* R rotation. */ | 7416 /* R rotation. */ |
7446 p->right = r->left; | 7417 p->right = r->left; |
7447 if (p->right) | 7418 if (p->right) |
7448 p->right->parent = p; | 7419 p->right->parent = p; |
7449 r->left = p; | 7420 r->left = p; |
7450 | 7421 |
7451 p->balance = 0; | 7422 p->balance = 0; |
7452 r->balance = 0; | 7423 r->balance = 0; |
7453 | 7424 |
7454 s = p->parent; | 7425 s = p->parent; |
7455 p->parent = r; | 7426 p->parent = r; |
7456 r->parent = s; | 7427 r->parent = s; |
7457 if (s) | 7428 if (s) |
7458 { | 7429 { |
7459 if (s->left == p) | 7430 if (s->left == p) |
7460 s->left = r; | 7431 s->left = r; |
7461 else | 7432 else |
7462 s->right = r; | 7433 s->right = r; |
7463 } | 7434 } |
7464 else | 7435 else |
7465 constructor_pending_elts = r; | 7436 constructor_pending_elts = r; |
7466 } | 7437 } |
7467 else /* r->balance == -1 */ | 7438 else /* r->balance == -1 */ |
7468 { | 7439 { |
7469 /* RL rotation */ | 7440 /* RL rotation */ |
7470 struct init_node *t = r->left; | 7441 struct init_node *t = r->left; |
7471 | 7442 |
7472 r->left = t->right; | 7443 r->left = t->right; |
7473 if (r->left) | 7444 if (r->left) |
7474 r->left->parent = r; | 7445 r->left->parent = r; |
7475 t->right = r; | 7446 t->right = r; |
7476 | 7447 |
7477 p->right = t->left; | 7448 p->right = t->left; |
7478 if (p->right) | 7449 if (p->right) |
7479 p->right->parent = p; | 7450 p->right->parent = p; |
7480 t->left = p; | 7451 t->left = p; |
7481 | 7452 |
7482 r->balance = (t->balance < 0); | 7453 r->balance = (t->balance < 0); |
7483 p->balance = -(t->balance > 0); | 7454 p->balance = -(t->balance > 0); |
7484 t->balance = 0; | 7455 t->balance = 0; |
7485 | 7456 |
7486 s = p->parent; | 7457 s = p->parent; |
7487 p->parent = t; | 7458 p->parent = t; |
7488 r->parent = t; | 7459 r->parent = t; |
7489 t->parent = s; | 7460 t->parent = s; |
7490 if (s) | 7461 if (s) |
7491 { | 7462 { |
7492 if (s->left == p) | 7463 if (s->left == p) |
7493 s->left = t; | 7464 s->left = t; |
7494 else | 7465 else |
7495 s->right = t; | 7466 s->right = t; |
7496 } | 7467 } |
7497 else | 7468 else |
7498 constructor_pending_elts = t; | 7469 constructor_pending_elts = t; |
7499 } | 7470 } |
7500 break; | 7471 break; |
7501 } | 7472 } |
7502 else | 7473 else |
7503 { | 7474 { |
7504 /* p->balance == -1; growth of right side balances the node. */ | 7475 /* p->balance == -1; growth of right side balances the node. */ |
7505 p->balance = 0; | 7476 p->balance = 0; |
7506 break; | 7477 break; |
7507 } | 7478 } |
7508 } | 7479 } |
7509 | 7480 |
7510 r = p; | 7481 r = p; |
7511 p = p->parent; | 7482 p = p->parent; |
7512 } | 7483 } |
7513 } | 7484 } |
7533 if (TREE_CODE (constructor_type) == RECORD_TYPE) | 7504 if (TREE_CODE (constructor_type) == RECORD_TYPE) |
7534 { | 7505 { |
7535 constructor_unfilled_fields = TYPE_FIELDS (constructor_type); | 7506 constructor_unfilled_fields = TYPE_FIELDS (constructor_type); |
7536 /* Skip any nameless bit fields at the beginning. */ | 7507 /* Skip any nameless bit fields at the beginning. */ |
7537 while (constructor_unfilled_fields != 0 | 7508 while (constructor_unfilled_fields != 0 |
7538 && DECL_C_BIT_FIELD (constructor_unfilled_fields) | 7509 && DECL_C_BIT_FIELD (constructor_unfilled_fields) |
7539 && DECL_NAME (constructor_unfilled_fields) == 0) | 7510 && DECL_NAME (constructor_unfilled_fields) == 0) |
7540 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields); | 7511 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields); |
7541 | 7512 |
7542 } | 7513 } |
7543 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 7514 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
7544 { | 7515 { |
7545 if (TYPE_DOMAIN (constructor_type)) | 7516 if (TYPE_DOMAIN (constructor_type)) |
7546 constructor_unfilled_index | 7517 constructor_unfilled_index |
7547 = convert (bitsizetype, | 7518 = convert (bitsizetype, |
7548 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); | 7519 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); |
7549 else | 7520 else |
7550 constructor_unfilled_index = bitsize_zero_node; | 7521 constructor_unfilled_index = bitsize_zero_node; |
7551 } | 7522 } |
7552 constructor_incremental = 0; | 7523 constructor_incremental = 0; |
7553 } | 7524 } |
7554 | 7525 |
7555 /* Build AVL tree from a string constant. */ | 7526 /* Build AVL tree from a string constant. */ |
7574 for (purpose = bitsize_zero_node; | 7545 for (purpose = bitsize_zero_node; |
7575 p < end && !tree_int_cst_lt (constructor_max_index, purpose); | 7546 p < end && !tree_int_cst_lt (constructor_max_index, purpose); |
7576 purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node)) | 7547 purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node)) |
7577 { | 7548 { |
7578 if (wchar_bytes == 1) | 7549 if (wchar_bytes == 1) |
7579 { | 7550 { |
7580 val[1] = (unsigned char) *p++; | 7551 val[1] = (unsigned char) *p++; |
7581 val[0] = 0; | 7552 val[0] = 0; |
7582 } | 7553 } |
7583 else | 7554 else |
7584 { | 7555 { |
7585 val[0] = 0; | 7556 val[0] = 0; |
7586 val[1] = 0; | 7557 val[1] = 0; |
7587 for (byte = 0; byte < wchar_bytes; byte++) | 7558 for (byte = 0; byte < wchar_bytes; byte++) |
7588 { | 7559 { |
7589 if (BYTES_BIG_ENDIAN) | 7560 if (BYTES_BIG_ENDIAN) |
7590 bitpos = (wchar_bytes - byte - 1) * charwidth; | 7561 bitpos = (wchar_bytes - byte - 1) * charwidth; |
7591 else | 7562 else |
7592 bitpos = byte * charwidth; | 7563 bitpos = byte * charwidth; |
7593 val[bitpos < HOST_BITS_PER_WIDE_INT] | 7564 val[bitpos < HOST_BITS_PER_WIDE_INT] |
7594 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++)) | 7565 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++)) |
7595 << (bitpos % HOST_BITS_PER_WIDE_INT); | 7566 << (bitpos % HOST_BITS_PER_WIDE_INT); |
7596 } | 7567 } |
7597 } | 7568 } |
7598 | 7569 |
7599 if (!TYPE_UNSIGNED (type)) | 7570 if (!TYPE_UNSIGNED (type)) |
7600 { | 7571 { |
7601 bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR; | 7572 bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR; |
7602 if (bitpos < HOST_BITS_PER_WIDE_INT) | 7573 if (bitpos < HOST_BITS_PER_WIDE_INT) |
7603 { | 7574 { |
7604 if (val[1] & (((HOST_WIDE_INT) 1) << (bitpos - 1))) | 7575 if (val[1] & (((HOST_WIDE_INT) 1) << (bitpos - 1))) |
7605 { | 7576 { |
7606 val[1] |= ((HOST_WIDE_INT) -1) << bitpos; | 7577 val[1] |= ((HOST_WIDE_INT) -1) << bitpos; |
7607 val[0] = -1; | 7578 val[0] = -1; |
7608 } | 7579 } |
7609 } | 7580 } |
7610 else if (bitpos == HOST_BITS_PER_WIDE_INT) | 7581 else if (bitpos == HOST_BITS_PER_WIDE_INT) |
7611 { | 7582 { |
7612 if (val[1] < 0) | 7583 if (val[1] < 0) |
7613 val[0] = -1; | 7584 val[0] = -1; |
7614 } | 7585 } |
7615 else if (val[0] & (((HOST_WIDE_INT) 1) | 7586 else if (val[0] & (((HOST_WIDE_INT) 1) |
7616 << (bitpos - 1 - HOST_BITS_PER_WIDE_INT))) | 7587 << (bitpos - 1 - HOST_BITS_PER_WIDE_INT))) |
7617 val[0] |= ((HOST_WIDE_INT) -1) | 7588 val[0] |= ((HOST_WIDE_INT) -1) |
7618 << (bitpos - HOST_BITS_PER_WIDE_INT); | 7589 << (bitpos - HOST_BITS_PER_WIDE_INT); |
7619 } | 7590 } |
7620 | 7591 |
7621 value = build_int_cst_wide (type, val[1], val[0]); | 7592 value = build_int_cst_wide (type, val[1], val[0]); |
7622 add_pending_init (purpose, value, NULL_TREE, false, | 7593 add_pending_init (purpose, value, NULL_TREE, false, |
7623 braced_init_obstack); | 7594 braced_init_obstack); |
7624 } | 7595 } |
7640 && tree_int_cst_lt (field, constructor_unfilled_index)) | 7611 && tree_int_cst_lt (field, constructor_unfilled_index)) |
7641 set_nonincremental_init (braced_init_obstack); | 7612 set_nonincremental_init (braced_init_obstack); |
7642 | 7613 |
7643 p = constructor_pending_elts; | 7614 p = constructor_pending_elts; |
7644 while (p) | 7615 while (p) |
7645 { | 7616 { |
7646 if (tree_int_cst_lt (field, p->purpose)) | 7617 if (tree_int_cst_lt (field, p->purpose)) |
7647 p = p->left; | 7618 p = p->left; |
7648 else if (tree_int_cst_lt (p->purpose, field)) | 7619 else if (tree_int_cst_lt (p->purpose, field)) |
7649 p = p->right; | 7620 p = p->right; |
7650 else | 7621 else |
7651 return p->value; | 7622 return p->value; |
7652 } | 7623 } |
7653 } | 7624 } |
7654 else if (TREE_CODE (constructor_type) == RECORD_TYPE) | 7625 else if (TREE_CODE (constructor_type) == RECORD_TYPE) |
7655 { | 7626 { |
7656 tree bitpos = bit_position (field); | 7627 tree bitpos = bit_position (field); |
7657 | 7628 |
7661 bit_position (constructor_unfilled_fields)))) | 7632 bit_position (constructor_unfilled_fields)))) |
7662 set_nonincremental_init (braced_init_obstack); | 7633 set_nonincremental_init (braced_init_obstack); |
7663 | 7634 |
7664 p = constructor_pending_elts; | 7635 p = constructor_pending_elts; |
7665 while (p) | 7636 while (p) |
7666 { | 7637 { |
7667 if (field == p->purpose) | 7638 if (field == p->purpose) |
7668 return p->value; | 7639 return p->value; |
7669 else if (tree_int_cst_lt (bitpos, bit_position (p->purpose))) | 7640 else if (tree_int_cst_lt (bitpos, bit_position (p->purpose))) |
7670 p = p->left; | 7641 p = p->left; |
7671 else | 7642 else |
7672 p = p->right; | 7643 p = p->right; |
7673 } | 7644 } |
7674 } | 7645 } |
7675 else if (TREE_CODE (constructor_type) == UNION_TYPE) | 7646 else if (TREE_CODE (constructor_type) == UNION_TYPE) |
7676 { | 7647 { |
7677 if (!VEC_empty (constructor_elt, constructor_elements) | 7648 if (!VEC_empty (constructor_elt, constructor_elements) |
7678 && (VEC_last (constructor_elt, constructor_elements)->index | 7649 && (VEC_last (constructor_elt, constructor_elements)->index |
7679 == field)) | 7650 == field)) |
7680 return VEC_last (constructor_elt, constructor_elements)->value; | 7651 return VEC_last (constructor_elt, constructor_elements)->value; |
7681 } | 7652 } |
7682 return 0; | 7653 return 0; |
7683 } | 7654 } |
7684 | 7655 |
7685 /* "Output" the next constructor element. | 7656 /* "Output" the next constructor element. |
7716 constructor_erroneous = 1; | 7687 constructor_erroneous = 1; |
7717 return; | 7688 return; |
7718 } | 7689 } |
7719 if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE | 7690 if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE |
7720 && (TREE_CODE (value) == STRING_CST | 7691 && (TREE_CODE (value) == STRING_CST |
7721 || TREE_CODE (value) == COMPOUND_LITERAL_EXPR) | 7692 || TREE_CODE (value) == COMPOUND_LITERAL_EXPR) |
7722 && !(TREE_CODE (value) == STRING_CST | 7693 && !(TREE_CODE (value) == STRING_CST |
7723 && TREE_CODE (type) == ARRAY_TYPE | 7694 && TREE_CODE (type) == ARRAY_TYPE |
7724 && INTEGRAL_TYPE_P (TREE_TYPE (type))) | 7695 && INTEGRAL_TYPE_P (TREE_TYPE (type))) |
7725 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)), | 7696 && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)), |
7726 TYPE_MAIN_VARIANT (type))) | 7697 TYPE_MAIN_VARIANT (type))) |
7727 value = array_to_pointer_conversion (input_location, value); | 7698 value = array_to_pointer_conversion (input_location, value); |
7728 | 7699 |
7729 if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR | 7700 if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR |
7730 && require_constant_value && !flag_isoc99 && pending) | 7701 && require_constant_value && !flag_isoc99 && pending) |
7731 { | 7702 { |
7732 /* As an extension, allow initializing objects with static storage | 7703 /* As an extension, allow initializing objects with static storage |
7733 duration with compound literals (which are then treated just as | 7704 duration with compound literals (which are then treated just as |
7734 the brace enclosed list they contain). */ | 7705 the brace enclosed list they contain). */ |
7735 tree decl = COMPOUND_LITERAL_EXPR_DECL (value); | 7706 tree decl = COMPOUND_LITERAL_EXPR_DECL (value); |
7736 value = DECL_INITIAL (decl); | 7707 value = DECL_INITIAL (decl); |
7737 } | 7708 } |
7738 | 7709 |
7739 npc = null_pointer_constant_p (value); | 7710 npc = null_pointer_constant_p (value); |
7747 if (value == error_mark_node) | 7718 if (value == error_mark_node) |
7748 constructor_erroneous = 1; | 7719 constructor_erroneous = 1; |
7749 else if (!TREE_CONSTANT (value)) | 7720 else if (!TREE_CONSTANT (value)) |
7750 constructor_constant = 0; | 7721 constructor_constant = 0; |
7751 else if (!initializer_constant_valid_p (value, TREE_TYPE (value)) | 7722 else if (!initializer_constant_valid_p (value, TREE_TYPE (value)) |
7752 || ((TREE_CODE (constructor_type) == RECORD_TYPE | 7723 || ((TREE_CODE (constructor_type) == RECORD_TYPE |
7753 || TREE_CODE (constructor_type) == UNION_TYPE) | 7724 || TREE_CODE (constructor_type) == UNION_TYPE) |
7754 && DECL_C_BIT_FIELD (field) | 7725 && DECL_C_BIT_FIELD (field) |
7755 && TREE_CODE (value) != INTEGER_CST)) | 7726 && TREE_CODE (value) != INTEGER_CST)) |
7756 constructor_simple = 0; | 7727 constructor_simple = 0; |
7757 if (!maybe_const) | 7728 if (!maybe_const) |
7758 constructor_nonconst = 1; | 7729 constructor_nonconst = 1; |
7759 | 7730 |
7760 if (!initializer_constant_valid_p (value, TREE_TYPE (value))) | 7731 if (!initializer_constant_valid_p (value, TREE_TYPE (value))) |
7761 { | 7732 { |
7762 if (require_constant_value) | 7733 if (require_constant_value) |
7763 { | 7734 { |
7764 error_init ("initializer element is not constant"); | 7735 error_init ("initializer element is not constant"); |
7765 value = error_mark_node; | 7736 value = error_mark_node; |
7766 } | 7737 } |
7767 else if (require_constant_elements) | 7738 else if (require_constant_elements) |
7768 pedwarn (input_location, 0, | 7739 pedwarn (input_location, 0, |
7769 "initializer element is not computable at load time"); | 7740 "initializer element is not computable at load time"); |
7770 } | 7741 } |
7771 else if (!maybe_const | 7742 else if (!maybe_const |
7772 && (require_constant_value || require_constant_elements)) | 7743 && (require_constant_value || require_constant_elements)) |
7773 pedwarn_init (input_location, 0, | 7744 pedwarn_init (input_location, 0, |
7774 "initializer element is not a constant expression"); | 7745 "initializer element is not a constant expression"); |
7775 | 7746 |
7776 /* Issue -Wc++-compat warnings about initializing a bitfield with | 7747 /* Issue -Wc++-compat warnings about initializing a bitfield with |
7777 enum type. */ | 7748 enum type. */ |
7778 if (warn_cxx_compat | 7749 if (warn_cxx_compat |
7779 && field != NULL_TREE | 7750 && field != NULL_TREE |
7780 && TREE_CODE (field) == FIELD_DECL | 7751 && TREE_CODE (field) == FIELD_DECL |
7781 && DECL_BIT_FIELD_TYPE (field) != NULL_TREE | 7752 && DECL_BIT_FIELD_TYPE (field) != NULL_TREE |
7782 && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field)) | 7753 && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field)) |
7783 != TYPE_MAIN_VARIANT (type)) | 7754 != TYPE_MAIN_VARIANT (type)) |
7784 && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE) | 7755 && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE) |
7785 { | 7756 { |
7786 tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value); | 7757 tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value); |
7787 if (checktype != error_mark_node | 7758 if (checktype != error_mark_node |
7788 && (TYPE_MAIN_VARIANT (checktype) | 7759 && (TYPE_MAIN_VARIANT (checktype) |
7789 != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field)))) | 7760 != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field)))) |
7790 warning_init (OPT_Wc___compat, | 7761 warning_init (OPT_Wc___compat, |
7791 "enum conversion in initialization is invalid in C++"); | 7762 "enum conversion in initialization is invalid in C++"); |
7792 } | 7763 } |
7793 | 7764 |
7794 /* If this field is empty (and not at the end of structure), | 7765 /* If this field is empty (and not at the end of structure), |
7795 don't do anything other than checking the initializer. */ | 7766 don't do anything other than checking the initializer. */ |
7796 if (field | 7767 if (field |
7802 return; | 7773 return; |
7803 | 7774 |
7804 if (semantic_type) | 7775 if (semantic_type) |
7805 value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value); | 7776 value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value); |
7806 value = digest_init (input_location, type, value, origtype, npc, | 7777 value = digest_init (input_location, type, value, origtype, npc, |
7807 strict_string, require_constant_value); | 7778 strict_string, require_constant_value); |
7808 if (value == error_mark_node) | 7779 if (value == error_mark_node) |
7809 { | 7780 { |
7810 constructor_erroneous = 1; | 7781 constructor_erroneous = 1; |
7811 return; | 7782 return; |
7812 } | 7783 } |
7815 | 7786 |
7816 /* If this element doesn't come next in sequence, | 7787 /* If this element doesn't come next in sequence, |
7817 put it on constructor_pending_elts. */ | 7788 put it on constructor_pending_elts. */ |
7818 if (TREE_CODE (constructor_type) == ARRAY_TYPE | 7789 if (TREE_CODE (constructor_type) == ARRAY_TYPE |
7819 && (!constructor_incremental | 7790 && (!constructor_incremental |
7820 || !tree_int_cst_equal (field, constructor_unfilled_index))) | 7791 || !tree_int_cst_equal (field, constructor_unfilled_index))) |
7821 { | 7792 { |
7822 if (constructor_incremental | 7793 if (constructor_incremental |
7823 && tree_int_cst_lt (field, constructor_unfilled_index)) | 7794 && tree_int_cst_lt (field, constructor_unfilled_index)) |
7824 set_nonincremental_init (braced_init_obstack); | 7795 set_nonincremental_init (braced_init_obstack); |
7825 | 7796 |
7826 add_pending_init (field, value, origtype, implicit, | 7797 add_pending_init (field, value, origtype, implicit, |
7827 braced_init_obstack); | 7798 braced_init_obstack); |
7828 return; | 7799 return; |
7829 } | 7800 } |
7830 else if (TREE_CODE (constructor_type) == RECORD_TYPE | 7801 else if (TREE_CODE (constructor_type) == RECORD_TYPE |
7831 && (!constructor_incremental | 7802 && (!constructor_incremental |
7832 || field != constructor_unfilled_fields)) | 7803 || field != constructor_unfilled_fields)) |
7833 { | 7804 { |
7834 /* We do this for records but not for unions. In a union, | 7805 /* We do this for records but not for unions. In a union, |
7835 no matter which field is specified, it can be initialized | 7806 no matter which field is specified, it can be initialized |
7836 right away since it starts at the beginning of the union. */ | 7807 right away since it starts at the beginning of the union. */ |
7837 if (constructor_incremental) | 7808 if (constructor_incremental) |
7838 { | 7809 { |
7839 if (!constructor_unfilled_fields) | 7810 if (!constructor_unfilled_fields) |
7840 set_nonincremental_init (braced_init_obstack); | 7811 set_nonincremental_init (braced_init_obstack); |
7841 else | 7812 else |
7853 add_pending_init (field, value, origtype, implicit, | 7824 add_pending_init (field, value, origtype, implicit, |
7854 braced_init_obstack); | 7825 braced_init_obstack); |
7855 return; | 7826 return; |
7856 } | 7827 } |
7857 else if (TREE_CODE (constructor_type) == UNION_TYPE | 7828 else if (TREE_CODE (constructor_type) == UNION_TYPE |
7858 && !VEC_empty (constructor_elt, constructor_elements)) | 7829 && !VEC_empty (constructor_elt, constructor_elements)) |
7859 { | 7830 { |
7860 if (!implicit) | 7831 if (!implicit) |
7861 { | 7832 { |
7862 if (TREE_SIDE_EFFECTS (VEC_last (constructor_elt, | 7833 if (TREE_SIDE_EFFECTS (VEC_last (constructor_elt, |
7863 constructor_elements)->value)) | 7834 constructor_elements)->value)) |
7864 warning_init (0, | 7835 warning_init (0, |
7865 "initialized field with side-effects overwritten"); | 7836 "initialized field with side-effects overwritten"); |
7866 else if (warn_override_init) | 7837 else if (warn_override_init) |
7867 warning_init (OPT_Woverride_init, "initialized field overwritten"); | 7838 warning_init (OPT_Woverride_init, "initialized field overwritten"); |
7868 } | 7839 } |
7869 | 7840 |
7870 /* We can have just one union field set. */ | 7841 /* We can have just one union field set. */ |
7871 constructor_elements = 0; | 7842 constructor_elements = 0; |
7872 } | 7843 } |
7873 | 7844 |
7880 | 7851 |
7881 /* Advance the variable that indicates sequential elements output. */ | 7852 /* Advance the variable that indicates sequential elements output. */ |
7882 if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 7853 if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
7883 constructor_unfilled_index | 7854 constructor_unfilled_index |
7884 = size_binop_loc (input_location, PLUS_EXPR, constructor_unfilled_index, | 7855 = size_binop_loc (input_location, PLUS_EXPR, constructor_unfilled_index, |
7885 bitsize_one_node); | 7856 bitsize_one_node); |
7886 else if (TREE_CODE (constructor_type) == RECORD_TYPE) | 7857 else if (TREE_CODE (constructor_type) == RECORD_TYPE) |
7887 { | 7858 { |
7888 constructor_unfilled_fields | 7859 constructor_unfilled_fields |
7889 = DECL_CHAIN (constructor_unfilled_fields); | 7860 = DECL_CHAIN (constructor_unfilled_fields); |
7890 | 7861 |
8079 && TREE_CODE (constructor_type) == ARRAY_TYPE | 8050 && TREE_CODE (constructor_type) == ARRAY_TYPE |
8080 && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type)) | 8051 && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type)) |
8081 && integer_zerop (constructor_unfilled_index)) | 8052 && integer_zerop (constructor_unfilled_index)) |
8082 { | 8053 { |
8083 if (constructor_stack->replacement_value.value) | 8054 if (constructor_stack->replacement_value.value) |
8084 error_init ("excess elements in char array initializer"); | 8055 error_init ("excess elements in char array initializer"); |
8085 constructor_stack->replacement_value = value; | 8056 constructor_stack->replacement_value = value; |
8086 return; | 8057 return; |
8087 } | 8058 } |
8088 | 8059 |
8089 if (constructor_stack->replacement_value.value != 0) | 8060 if (constructor_stack->replacement_value.value != 0) |
8112 || tree_int_cst_lt (constructor_max_index, | 8083 || tree_int_cst_lt (constructor_max_index, |
8113 constructor_index))) | 8084 constructor_index))) |
8114 process_init_element (pop_init_level (1, braced_init_obstack), | 8085 process_init_element (pop_init_level (1, braced_init_obstack), |
8115 true, braced_init_obstack); | 8086 true, braced_init_obstack); |
8116 else | 8087 else |
8117 break; | 8088 break; |
8118 } | 8089 } |
8119 | 8090 |
8120 /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */ | 8091 /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */ |
8121 if (constructor_range_stack) | 8092 if (constructor_range_stack) |
8122 { | 8093 { |
8123 /* If value is a compound literal and we'll be just using its | 8094 /* If value is a compound literal and we'll be just using its |
8124 content, don't put it into a SAVE_EXPR. */ | 8095 content, don't put it into a SAVE_EXPR. */ |
8125 if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR | 8096 if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR |
8126 || !require_constant_value | 8097 || !require_constant_value |
8127 || flag_isoc99) | 8098 || flag_isoc99) |
8128 { | 8099 { |
8129 tree semantic_type = NULL_TREE; | 8100 tree semantic_type = NULL_TREE; |
8130 if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR) | 8101 if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR) |
8131 { | 8102 { |
8132 semantic_type = TREE_TYPE (value.value); | 8103 semantic_type = TREE_TYPE (value.value); |
8133 value.value = TREE_OPERAND (value.value, 0); | 8104 value.value = TREE_OPERAND (value.value, 0); |
8134 } | 8105 } |
8135 value.value = c_save_expr (value.value); | 8106 value.value = c_save_expr (value.value); |
8136 if (semantic_type) | 8107 if (semantic_type) |
8137 value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type, | 8108 value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type, |
8138 value.value); | 8109 value.value); |
8139 } | 8110 } |
8140 } | 8111 } |
8141 | 8112 |
8142 while (1) | 8113 while (1) |
8143 { | 8114 { |
8144 if (TREE_CODE (constructor_type) == RECORD_TYPE) | 8115 if (TREE_CODE (constructor_type) == RECORD_TYPE) |
8384 constructor_unfilled_index. */ | 8355 constructor_unfilled_index. */ |
8385 constructor_unfilled_index = constructor_index; | 8356 constructor_unfilled_index = constructor_index; |
8386 } | 8357 } |
8387 | 8358 |
8388 /* Handle the sole element allowed in a braced initializer | 8359 /* Handle the sole element allowed in a braced initializer |
8389 for a scalar variable. */ | 8360 for a scalar variable. */ |
8390 else if (constructor_type != error_mark_node | 8361 else if (constructor_type != error_mark_node |
8391 && constructor_fields == 0) | 8362 && constructor_fields == 0) |
8392 { | 8363 { |
8393 pedwarn_init (input_location, 0, | 8364 pedwarn_init (input_location, 0, |
8394 "excess elements in scalar initializer"); | 8365 "excess elements in scalar initializer"); |
8395 break; | 8366 break; |
8396 } | 8367 } |
8397 else | 8368 else |
8398 { | 8369 { |
8399 if (value.value) | 8370 if (value.value) |
8400 output_init_element (value.value, value.original_type, | 8371 output_init_element (value.value, value.original_type, |
8401 strict_string, constructor_type, | 8372 strict_string, constructor_type, |
8403 braced_init_obstack); | 8374 braced_init_obstack); |
8404 constructor_fields = 0; | 8375 constructor_fields = 0; |
8405 } | 8376 } |
8406 | 8377 |
8407 /* Handle range initializers either at this level or anywhere higher | 8378 /* Handle range initializers either at this level or anywhere higher |
8408 in the designator stack. */ | 8379 in the designator stack. */ |
8409 if (constructor_range_stack) | 8380 if (constructor_range_stack) |
8410 { | 8381 { |
8411 struct constructor_range_stack *p, *range_stack; | 8382 struct constructor_range_stack *p, *range_stack; |
8412 int finish = 0; | 8383 int finish = 0; |
8413 | 8384 |
8479 SIMPLE indicates whether there was anything at all after the | 8450 SIMPLE indicates whether there was anything at all after the |
8480 string in the asm expression -- asm("blah") and asm("blah" : ) | 8451 string in the asm expression -- asm("blah") and asm("blah" : ) |
8481 are subtly different. We use a ASM_EXPR node to represent this. */ | 8452 are subtly different. We use a ASM_EXPR node to represent this. */ |
8482 tree | 8453 tree |
8483 build_asm_expr (location_t loc, tree string, tree outputs, tree inputs, | 8454 build_asm_expr (location_t loc, tree string, tree outputs, tree inputs, |
8484 tree clobbers, tree labels, bool simple) | 8455 tree clobbers, tree labels, bool simple) |
8485 { | 8456 { |
8486 tree tail; | 8457 tree tail; |
8487 tree args; | 8458 tree args; |
8488 int i; | 8459 int i; |
8489 const char *constraint; | 8460 const char *constraint; |
8501 for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail)) | 8472 for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail)) |
8502 { | 8473 { |
8503 tree output = TREE_VALUE (tail); | 8474 tree output = TREE_VALUE (tail); |
8504 | 8475 |
8505 /* ??? Really, this should not be here. Users should be using a | 8476 /* ??? Really, this should not be here. Users should be using a |
8506 proper lvalue, dammit. But there's a long history of using casts | 8477 proper lvalue, dammit. But there's a long history of using casts |
8507 in the output operands. In cases like longlong.h, this becomes a | 8478 in the output operands. In cases like longlong.h, this becomes a |
8508 primitive form of typechecking -- if the cast can be removed, then | 8479 primitive form of typechecking -- if the cast can be removed, then |
8509 the output operand had a type of the proper width; otherwise we'll | 8480 the output operand had a type of the proper width; otherwise we'll |
8510 get an error. Gross, but ... */ | 8481 get an error. Gross, but ... */ |
8511 STRIP_NOPS (output); | 8482 STRIP_NOPS (output); |
8512 | 8483 |
8513 if (!lvalue_or_else (loc, output, lv_asm)) | 8484 if (!lvalue_or_else (loc, output, lv_asm)) |
8514 output = error_mark_node; | 8485 output = error_mark_node; |
8515 | 8486 |
8516 if (output != error_mark_node | 8487 if (output != error_mark_node |
8517 && (TREE_READONLY (output) | 8488 && (TREE_READONLY (output) |
8518 || TYPE_READONLY (TREE_TYPE (output)) | 8489 || TYPE_READONLY (TREE_TYPE (output)) |
8519 || ((TREE_CODE (TREE_TYPE (output)) == RECORD_TYPE | 8490 || ((TREE_CODE (TREE_TYPE (output)) == RECORD_TYPE |
8520 || TREE_CODE (TREE_TYPE (output)) == UNION_TYPE) | 8491 || TREE_CODE (TREE_TYPE (output)) == UNION_TYPE) |
8521 && C_TYPE_FIELDS_READONLY (TREE_TYPE (output))))) | 8492 && C_TYPE_FIELDS_READONLY (TREE_TYPE (output))))) |
8522 readonly_error (output, lv_asm); | 8493 readonly_error (output, lv_asm); |
8523 | 8494 |
8524 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail))); | 8495 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail))); |
8525 oconstraints[i] = constraint; | 8496 oconstraints[i] = constraint; |
8526 | 8497 |
8527 if (parse_output_constraint (&constraint, i, ninputs, noutputs, | 8498 if (parse_output_constraint (&constraint, i, ninputs, noutputs, |
8528 &allows_mem, &allows_reg, &is_inout)) | 8499 &allows_mem, &allows_reg, &is_inout)) |
8529 { | 8500 { |
8530 /* If the operand is going to end up in memory, | 8501 /* If the operand is going to end up in memory, |
8531 mark it addressable. */ | 8502 mark it addressable. */ |
8532 if (!allows_reg && !c_mark_addressable (output)) | 8503 if (!allows_reg && !c_mark_addressable (output)) |
8533 output = error_mark_node; | 8504 output = error_mark_node; |
8534 } | 8505 } |
8535 else | 8506 else |
8536 output = error_mark_node; | 8507 output = error_mark_node; |
8537 | 8508 |
8538 TREE_VALUE (tail) = output; | 8509 TREE_VALUE (tail) = output; |
8539 } | 8510 } |
8540 | 8511 |
8541 for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail)) | 8512 for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail)) |
8544 | 8515 |
8545 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail))); | 8516 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail))); |
8546 input = TREE_VALUE (tail); | 8517 input = TREE_VALUE (tail); |
8547 | 8518 |
8548 if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0, | 8519 if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0, |
8549 oconstraints, &allows_mem, &allows_reg)) | 8520 oconstraints, &allows_mem, &allows_reg)) |
8550 { | 8521 { |
8551 /* If the operand is going to end up in memory, | 8522 /* If the operand is going to end up in memory, |
8552 mark it addressable. */ | 8523 mark it addressable. */ |
8553 if (!allows_reg && allows_mem) | 8524 if (!allows_reg && allows_mem) |
8554 { | 8525 { |
8555 /* Strip the nops as we allow this case. FIXME, this really | 8526 /* Strip the nops as we allow this case. FIXME, this really |
8556 should be rejected or made deprecated. */ | 8527 should be rejected or made deprecated. */ |
8557 STRIP_NOPS (input); | 8528 STRIP_NOPS (input); |
8558 if (!c_mark_addressable (input)) | 8529 if (!c_mark_addressable (input)) |
8559 input = error_mark_node; | 8530 input = error_mark_node; |
8560 } | 8531 } |
8561 } | 8532 } |
8562 else | 8533 else |
8563 input = error_mark_node; | 8534 input = error_mark_node; |
8564 | 8535 |
8565 TREE_VALUE (tail) = input; | 8536 TREE_VALUE (tail) = input; |
8566 } | 8537 } |
8567 | 8538 |
8568 /* ASMs with labels cannot have outputs. This should have been | 8539 /* ASMs with labels cannot have outputs. This should have been |
8623 bool no_warning = false; | 8594 bool no_warning = false; |
8624 bool npc = false; | 8595 bool npc = false; |
8625 | 8596 |
8626 if (TREE_THIS_VOLATILE (current_function_decl)) | 8597 if (TREE_THIS_VOLATILE (current_function_decl)) |
8627 warning_at (loc, 0, | 8598 warning_at (loc, 0, |
8628 "function declared %<noreturn%> has a %<return%> statement"); | 8599 "function declared %<noreturn%> has a %<return%> statement"); |
8629 | 8600 |
8630 if (retval) | 8601 if (retval) |
8631 { | 8602 { |
8632 tree semantic_type = NULL_TREE; | 8603 tree semantic_type = NULL_TREE; |
8633 npc = null_pointer_constant_p (retval); | 8604 npc = null_pointer_constant_p (retval); |
8634 if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR) | 8605 if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR) |
8635 { | 8606 { |
8636 semantic_type = TREE_TYPE (retval); | 8607 semantic_type = TREE_TYPE (retval); |
8637 retval = TREE_OPERAND (retval, 0); | 8608 retval = TREE_OPERAND (retval, 0); |
8638 } | 8609 } |
8639 retval = c_fully_fold (retval, false, NULL); | 8610 retval = c_fully_fold (retval, false, NULL); |
8640 if (semantic_type) | 8611 if (semantic_type) |
8641 retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval); | 8612 retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval); |
8642 } | 8613 } |
8643 | 8614 |
8644 if (!retval) | 8615 if (!retval) |
8645 { | 8616 { |
8646 current_function_returns_null = 1; | 8617 current_function_returns_null = 1; |
8647 if ((warn_return_type || flag_isoc99) | 8618 if ((warn_return_type || flag_isoc99) |
8648 && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE) | 8619 && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE) |
8649 { | 8620 { |
8650 pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wreturn_type, | 8621 pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wreturn_type, |
8651 "%<return%> with no value, in " | 8622 "%<return%> with no value, in " |
8652 "function returning non-void"); | 8623 "function returning non-void"); |
8653 no_warning = true; | 8624 no_warning = true; |
8654 } | 8625 } |
8655 } | 8626 } |
8656 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE) | 8627 else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE) |
8657 { | 8628 { |
8658 current_function_returns_null = 1; | 8629 current_function_returns_null = 1; |
8659 if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) | 8630 if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) |
8660 pedwarn (loc, 0, | 8631 pedwarn (loc, 0, |
8661 "%<return%> with a value, in function returning void"); | 8632 "%<return%> with a value, in function returning void"); |
8662 else | 8633 else |
8663 pedwarn (loc, OPT_pedantic, "ISO C forbids " | 8634 pedwarn (loc, OPT_pedantic, "ISO C forbids " |
8664 "%<return%> with expression, in function returning void"); | 8635 "%<return%> with expression, in function returning void"); |
8665 } | 8636 } |
8666 else | 8637 else |
8667 { | 8638 { |
8668 tree t = convert_for_assignment (loc, valtype, retval, origtype, | 8639 tree t = convert_for_assignment (loc, valtype, retval, origtype, |
8669 ic_return, | 8640 ic_return, |
8670 npc, NULL_TREE, NULL_TREE, 0); | 8641 npc, NULL_TREE, NULL_TREE, 0); |
8671 tree res = DECL_RESULT (current_function_decl); | 8642 tree res = DECL_RESULT (current_function_decl); |
8672 tree inner; | 8643 tree inner; |
8673 | 8644 |
8674 current_function_returns_value = 1; | 8645 current_function_returns_value = 1; |
8675 if (t == error_mark_node) | 8646 if (t == error_mark_node) |
8676 return NULL_TREE; | 8647 return NULL_TREE; |
8677 | 8648 |
8678 inner = t = convert (TREE_TYPE (res), t); | 8649 inner = t = convert (TREE_TYPE (res), t); |
8679 | 8650 |
8680 /* Strip any conversions, additions, and subtractions, and see if | 8651 /* Strip any conversions, additions, and subtractions, and see if |
8681 we are returning the address of a local variable. Warn if so. */ | 8652 we are returning the address of a local variable. Warn if so. */ |
8682 while (1) | 8653 while (1) |
8683 { | 8654 { |
8684 switch (TREE_CODE (inner)) | 8655 switch (TREE_CODE (inner)) |
8685 { | 8656 { |
8686 CASE_CONVERT: | 8657 CASE_CONVERT: |
8687 case NON_LVALUE_EXPR: | 8658 case NON_LVALUE_EXPR: |
8688 case PLUS_EXPR: | 8659 case PLUS_EXPR: |
8689 case POINTER_PLUS_EXPR: | 8660 case POINTER_PLUS_EXPR: |
8690 inner = TREE_OPERAND (inner, 0); | 8661 inner = TREE_OPERAND (inner, 0); |
8691 continue; | 8662 continue; |
8692 | 8663 |
8693 case MINUS_EXPR: | 8664 case MINUS_EXPR: |
8694 /* If the second operand of the MINUS_EXPR has a pointer | 8665 /* If the second operand of the MINUS_EXPR has a pointer |
8695 type (or is converted from it), this may be valid, so | 8666 type (or is converted from it), this may be valid, so |
8696 don't give a warning. */ | 8667 don't give a warning. */ |
8697 { | 8668 { |
8698 tree op1 = TREE_OPERAND (inner, 1); | 8669 tree op1 = TREE_OPERAND (inner, 1); |
8699 | 8670 |
8700 while (!POINTER_TYPE_P (TREE_TYPE (op1)) | 8671 while (!POINTER_TYPE_P (TREE_TYPE (op1)) |
8701 && (CONVERT_EXPR_P (op1) | 8672 && (CONVERT_EXPR_P (op1) |
8702 || TREE_CODE (op1) == NON_LVALUE_EXPR)) | 8673 || TREE_CODE (op1) == NON_LVALUE_EXPR)) |
8703 op1 = TREE_OPERAND (op1, 0); | 8674 op1 = TREE_OPERAND (op1, 0); |
8704 | 8675 |
8705 if (POINTER_TYPE_P (TREE_TYPE (op1))) | 8676 if (POINTER_TYPE_P (TREE_TYPE (op1))) |
8706 break; | 8677 break; |
8707 | 8678 |
8708 inner = TREE_OPERAND (inner, 0); | 8679 inner = TREE_OPERAND (inner, 0); |
8709 continue; | 8680 continue; |
8710 } | 8681 } |
8711 | 8682 |
8712 case ADDR_EXPR: | 8683 case ADDR_EXPR: |
8713 inner = TREE_OPERAND (inner, 0); | 8684 inner = TREE_OPERAND (inner, 0); |
8714 | 8685 |
8715 while (REFERENCE_CLASS_P (inner) | 8686 while (REFERENCE_CLASS_P (inner) |
8716 && TREE_CODE (inner) != INDIRECT_REF) | 8687 && TREE_CODE (inner) != INDIRECT_REF) |
8717 inner = TREE_OPERAND (inner, 0); | 8688 inner = TREE_OPERAND (inner, 0); |
8718 | 8689 |
8719 if (DECL_P (inner) | 8690 if (DECL_P (inner) |
8720 && !DECL_EXTERNAL (inner) | 8691 && !DECL_EXTERNAL (inner) |
8721 && !TREE_STATIC (inner) | 8692 && !TREE_STATIC (inner) |
8722 && DECL_CONTEXT (inner) == current_function_decl) | 8693 && DECL_CONTEXT (inner) == current_function_decl) |
8723 warning_at (loc, | 8694 warning_at (loc, |
8724 0, "function returns address of local variable"); | 8695 0, "function returns address of local variable"); |
8725 break; | 8696 break; |
8726 | 8697 |
8727 default: | 8698 default: |
8728 break; | 8699 break; |
8729 } | 8700 } |
8730 | 8701 |
8731 break; | 8702 break; |
8732 } | 8703 } |
8733 | 8704 |
8734 retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t); | 8705 retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t); |
8735 SET_EXPR_LOCATION (retval, loc); | 8706 SET_EXPR_LOCATION (retval, loc); |
8736 | 8707 |
8737 if (warn_sequence_point) | 8708 if (warn_sequence_point) |
8738 verify_sequence_points (retval); | 8709 verify_sequence_points (retval); |
8739 } | 8710 } |
8740 | 8711 |
8741 ret_stmt = build_stmt (loc, RETURN_EXPR, retval); | 8712 ret_stmt = build_stmt (loc, RETURN_EXPR, retval); |
8742 TREE_NO_WARNING (ret_stmt) |= no_warning; | 8713 TREE_NO_WARNING (ret_stmt) |= no_warning; |
8743 return add_stmt (ret_stmt); | 8714 return add_stmt (ret_stmt); |
8778 SWITCH_EXPR. SWITCH_LOC is the location of the `switch'. | 8749 SWITCH_EXPR. SWITCH_LOC is the location of the `switch'. |
8779 SWITCH_COND_LOC is the location of the switch's condition. */ | 8750 SWITCH_COND_LOC is the location of the switch's condition. */ |
8780 | 8751 |
8781 tree | 8752 tree |
8782 c_start_case (location_t switch_loc, | 8753 c_start_case (location_t switch_loc, |
8783 location_t switch_cond_loc, | 8754 location_t switch_cond_loc, |
8784 tree exp) | 8755 tree exp) |
8785 { | 8756 { |
8786 tree orig_type = error_mark_node; | 8757 tree orig_type = error_mark_node; |
8787 struct c_switch *cs; | 8758 struct c_switch *cs; |
8788 | 8759 |
8789 if (exp != error_mark_node) | 8760 if (exp != error_mark_node) |
8790 { | 8761 { |
8791 orig_type = TREE_TYPE (exp); | 8762 orig_type = TREE_TYPE (exp); |
8792 | 8763 |
8793 if (!INTEGRAL_TYPE_P (orig_type)) | 8764 if (!INTEGRAL_TYPE_P (orig_type)) |
8794 { | 8765 { |
8795 if (orig_type != error_mark_node) | 8766 if (orig_type != error_mark_node) |
8796 { | 8767 { |
8797 error_at (switch_cond_loc, "switch quantity not an integer"); | 8768 error_at (switch_cond_loc, "switch quantity not an integer"); |
8798 orig_type = error_mark_node; | 8769 orig_type = error_mark_node; |
8799 } | 8770 } |
8800 exp = integer_zero_node; | 8771 exp = integer_zero_node; |
8801 } | 8772 } |
8802 else | 8773 else |
8803 { | 8774 { |
8804 tree type = TYPE_MAIN_VARIANT (orig_type); | 8775 tree type = TYPE_MAIN_VARIANT (orig_type); |
8805 | 8776 |
8806 if (!in_system_header | 8777 if (!in_system_header |
8807 && (type == long_integer_type_node | 8778 && (type == long_integer_type_node |
8808 || type == long_unsigned_type_node)) | 8779 || type == long_unsigned_type_node)) |
8809 warning_at (switch_cond_loc, | 8780 warning_at (switch_cond_loc, |
8810 OPT_Wtraditional, "%<long%> switch expression not " | 8781 OPT_Wtraditional, "%<long%> switch expression not " |
8811 "converted to %<int%> in ISO C"); | 8782 "converted to %<int%> in ISO C"); |
8812 | 8783 |
8813 exp = c_fully_fold (exp, false, NULL); | 8784 exp = c_fully_fold (exp, false, NULL); |
8814 exp = default_conversion (exp); | 8785 exp = default_conversion (exp); |
8815 | 8786 |
8816 if (warn_sequence_point) | 8787 if (warn_sequence_point) |
8817 verify_sequence_points (exp); | 8788 verify_sequence_points (exp); |
8818 } | 8789 } |
8819 } | 8790 } |
8820 | 8791 |
8821 /* Add this new SWITCH_EXPR to the stack. */ | 8792 /* Add this new SWITCH_EXPR to the stack. */ |
8822 cs = XNEW (struct c_switch); | 8793 cs = XNEW (struct c_switch); |
8823 cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp, NULL_TREE, NULL_TREE); | 8794 cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp, NULL_TREE, NULL_TREE); |
8840 | 8811 |
8841 if (low_value && TREE_CODE (low_value) != INTEGER_CST) | 8812 if (low_value && TREE_CODE (low_value) != INTEGER_CST) |
8842 { | 8813 { |
8843 low_value = c_fully_fold (low_value, false, NULL); | 8814 low_value = c_fully_fold (low_value, false, NULL); |
8844 if (TREE_CODE (low_value) == INTEGER_CST) | 8815 if (TREE_CODE (low_value) == INTEGER_CST) |
8845 pedwarn (input_location, OPT_pedantic, | 8816 pedwarn (input_location, OPT_pedantic, |
8846 "case label is not an integer constant expression"); | 8817 "case label is not an integer constant expression"); |
8847 } | 8818 } |
8848 | 8819 |
8849 if (high_value && TREE_CODE (high_value) != INTEGER_CST) | 8820 if (high_value && TREE_CODE (high_value) != INTEGER_CST) |
8850 { | 8821 { |
8851 high_value = c_fully_fold (high_value, false, NULL); | 8822 high_value = c_fully_fold (high_value, false, NULL); |
8852 if (TREE_CODE (high_value) == INTEGER_CST) | 8823 if (TREE_CODE (high_value) == INTEGER_CST) |
8853 pedwarn (input_location, OPT_pedantic, | 8824 pedwarn (input_location, OPT_pedantic, |
8854 "case label is not an integer constant expression"); | 8825 "case label is not an integer constant expression"); |
8855 } | 8826 } |
8856 | 8827 |
8857 if (c_switch_stack == NULL) | 8828 if (c_switch_stack == NULL) |
8858 { | 8829 { |
8859 if (low_value) | 8830 if (low_value) |
8860 error_at (loc, "case label not within a switch statement"); | 8831 error_at (loc, "case label not within a switch statement"); |
8861 else | 8832 else |
8862 error_at (loc, "%<default%> label not within a switch statement"); | 8833 error_at (loc, "%<default%> label not within a switch statement"); |
8863 return NULL_TREE; | 8834 return NULL_TREE; |
8864 } | 8835 } |
8865 | 8836 |
8866 if (c_check_switch_jump_warnings (c_switch_stack->bindings, | 8837 if (c_check_switch_jump_warnings (c_switch_stack->bindings, |
8867 EXPR_LOCATION (c_switch_stack->switch_expr), | 8838 EXPR_LOCATION (c_switch_stack->switch_expr), |
8868 loc)) | 8839 loc)) |
8869 return NULL_TREE; | 8840 return NULL_TREE; |
8870 | 8841 |
8871 label = c_add_case_label (loc, c_switch_stack->cases, | 8842 label = c_add_case_label (loc, c_switch_stack->cases, |
8872 SWITCH_COND (c_switch_stack->switch_expr), | 8843 SWITCH_COND (c_switch_stack->switch_expr), |
8873 c_switch_stack->orig_type, | 8844 c_switch_stack->orig_type, |
8874 low_value, high_value); | 8845 low_value, high_value); |
8875 if (label == error_mark_node) | 8846 if (label == error_mark_node) |
8876 label = NULL_TREE; | 8847 label = NULL_TREE; |
8877 return label; | 8848 return label; |
8878 } | 8849 } |
8879 | 8850 |
8888 SWITCH_BODY (cs->switch_expr) = body; | 8859 SWITCH_BODY (cs->switch_expr) = body; |
8889 | 8860 |
8890 /* Emit warnings as needed. */ | 8861 /* Emit warnings as needed. */ |
8891 switch_location = EXPR_LOCATION (cs->switch_expr); | 8862 switch_location = EXPR_LOCATION (cs->switch_expr); |
8892 c_do_switch_warnings (cs->cases, switch_location, | 8863 c_do_switch_warnings (cs->cases, switch_location, |
8893 TREE_TYPE (cs->switch_expr), | 8864 TREE_TYPE (cs->switch_expr), |
8894 SWITCH_COND (cs->switch_expr)); | 8865 SWITCH_COND (cs->switch_expr)); |
8895 | 8866 |
8896 /* Pop the stack. */ | 8867 /* Pop the stack. */ |
8897 c_switch_stack = cs->next; | 8868 c_switch_stack = cs->next; |
8898 splay_tree_delete (cs->cases); | 8869 splay_tree_delete (cs->cases); |
8899 c_release_switch_bindings (cs->bindings); | 8870 c_release_switch_bindings (cs->bindings); |
8905 may be null. NESTED_IF is true if THEN_BLOCK contains another IF | 8876 may be null. NESTED_IF is true if THEN_BLOCK contains another IF |
8906 statement, and was not surrounded with parenthesis. */ | 8877 statement, and was not surrounded with parenthesis. */ |
8907 | 8878 |
8908 void | 8879 void |
8909 c_finish_if_stmt (location_t if_locus, tree cond, tree then_block, | 8880 c_finish_if_stmt (location_t if_locus, tree cond, tree then_block, |
8910 tree else_block, bool nested_if) | 8881 tree else_block, bool nested_if) |
8911 { | 8882 { |
8912 tree stmt; | 8883 tree stmt; |
8913 | 8884 |
8914 /* Diagnose an ambiguous else if if-then-else is nested inside if-then. */ | 8885 /* Diagnose an ambiguous else if if-then-else is nested inside if-then. */ |
8915 if (warn_parentheses && nested_if && else_block == NULL) | 8886 if (warn_parentheses && nested_if && else_block == NULL) |
8916 { | 8887 { |
8917 tree inner_if = then_block; | 8888 tree inner_if = then_block; |
8918 | 8889 |
8919 /* We know from the grammar productions that there is an IF nested | 8890 /* We know from the grammar productions that there is an IF nested |
8920 within THEN_BLOCK. Due to labels and c99 conditional declarations, | 8891 within THEN_BLOCK. Due to labels and c99 conditional declarations, |
8921 it might not be exactly THEN_BLOCK, but should be the last | 8892 it might not be exactly THEN_BLOCK, but should be the last |
8922 non-container statement within. */ | 8893 non-container statement within. */ |
8923 while (1) | 8894 while (1) |
8924 switch (TREE_CODE (inner_if)) | 8895 switch (TREE_CODE (inner_if)) |
8925 { | 8896 { |
8926 case COND_EXPR: | 8897 case COND_EXPR: |
8927 goto found; | 8898 goto found; |
8928 case BIND_EXPR: | 8899 case BIND_EXPR: |
8929 inner_if = BIND_EXPR_BODY (inner_if); | 8900 inner_if = BIND_EXPR_BODY (inner_if); |
8930 break; | 8901 break; |
8931 case STATEMENT_LIST: | 8902 case STATEMENT_LIST: |
8932 inner_if = expr_last (then_block); | 8903 inner_if = expr_last (then_block); |
8933 break; | 8904 break; |
8934 case TRY_FINALLY_EXPR: | 8905 case TRY_FINALLY_EXPR: |
8935 case TRY_CATCH_EXPR: | 8906 case TRY_CATCH_EXPR: |
8936 inner_if = TREE_OPERAND (inner_if, 0); | 8907 inner_if = TREE_OPERAND (inner_if, 0); |
8937 break; | 8908 break; |
8938 default: | 8909 default: |
8939 gcc_unreachable (); | 8910 gcc_unreachable (); |
8940 } | 8911 } |
8941 found: | 8912 found: |
8942 | 8913 |
8943 if (COND_EXPR_ELSE (inner_if)) | 8914 if (COND_EXPR_ELSE (inner_if)) |
8944 warning_at (if_locus, OPT_Wparentheses, | 8915 warning_at (if_locus, OPT_Wparentheses, |
8945 "suggest explicit braces to avoid ambiguous %<else%>"); | 8916 "suggest explicit braces to avoid ambiguous %<else%>"); |
8946 } | 8917 } |
8947 | 8918 |
8948 stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block); | 8919 stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block); |
8949 SET_EXPR_LOCATION (stmt, if_locus); | 8920 SET_EXPR_LOCATION (stmt, if_locus); |
8950 add_stmt (stmt); | 8921 add_stmt (stmt); |
8956 the statement controlled by the loop. BLAB is the break label. CLAB is | 8927 the statement controlled by the loop. BLAB is the break label. CLAB is |
8957 the continue label. Everything is allowed to be NULL. */ | 8928 the continue label. Everything is allowed to be NULL. */ |
8958 | 8929 |
8959 void | 8930 void |
8960 c_finish_loop (location_t start_locus, tree cond, tree incr, tree body, | 8931 c_finish_loop (location_t start_locus, tree cond, tree incr, tree body, |
8961 tree blab, tree clab, bool cond_is_first) | 8932 tree blab, tree clab, bool cond_is_first) |
8962 { | 8933 { |
8963 tree entry = NULL, exit = NULL, t; | 8934 tree entry = NULL, exit = NULL, t; |
8964 | 8935 |
8965 /* If the condition is zero don't generate a loop construct. */ | 8936 /* If the condition is zero don't generate a loop construct. */ |
8966 if (cond && integer_zerop (cond)) | 8937 if (cond && integer_zerop (cond)) |
8967 { | 8938 { |
8968 if (cond_is_first) | 8939 if (cond_is_first) |
8969 { | 8940 { |
8970 t = build_and_jump (&blab); | 8941 t = build_and_jump (&blab); |
8971 SET_EXPR_LOCATION (t, start_locus); | 8942 SET_EXPR_LOCATION (t, start_locus); |
8972 add_stmt (t); | 8943 add_stmt (t); |
8973 } | 8944 } |
8974 } | 8945 } |
8975 else | 8946 else |
8976 { | 8947 { |
8977 tree top = build1 (LABEL_EXPR, void_type_node, NULL_TREE); | 8948 tree top = build1 (LABEL_EXPR, void_type_node, NULL_TREE); |
8978 | 8949 |
8979 /* If we have an exit condition, then we build an IF with gotos either | 8950 /* If we have an exit condition, then we build an IF with gotos either |
8980 out of the loop, or to the top of it. If there's no exit condition, | 8951 out of the loop, or to the top of it. If there's no exit condition, |
8981 then we just build a jump back to the top. */ | 8952 then we just build a jump back to the top. */ |
8982 exit = build_and_jump (&LABEL_EXPR_LABEL (top)); | 8953 exit = build_and_jump (&LABEL_EXPR_LABEL (top)); |
8983 | 8954 |
8984 if (cond && !integer_nonzerop (cond)) | 8955 if (cond && !integer_nonzerop (cond)) |
8985 { | 8956 { |
8986 /* Canonicalize the loop condition to the end. This means | 8957 /* Canonicalize the loop condition to the end. This means |
8987 generating a branch to the loop condition. Reuse the | 8958 generating a branch to the loop condition. Reuse the |
8988 continue label, if possible. */ | 8959 continue label, if possible. */ |
8989 if (cond_is_first) | 8960 if (cond_is_first) |
8990 { | 8961 { |
8991 if (incr || !clab) | 8962 if (incr || !clab) |
8992 { | 8963 { |
8993 entry = build1 (LABEL_EXPR, void_type_node, NULL_TREE); | 8964 entry = build1 (LABEL_EXPR, void_type_node, NULL_TREE); |
8994 t = build_and_jump (&LABEL_EXPR_LABEL (entry)); | 8965 t = build_and_jump (&LABEL_EXPR_LABEL (entry)); |
8995 } | 8966 } |
8996 else | 8967 else |
8997 t = build1 (GOTO_EXPR, void_type_node, clab); | 8968 t = build1 (GOTO_EXPR, void_type_node, clab); |
8998 SET_EXPR_LOCATION (t, start_locus); | 8969 SET_EXPR_LOCATION (t, start_locus); |
8999 add_stmt (t); | 8970 add_stmt (t); |
9000 } | 8971 } |
9001 | 8972 |
9002 t = build_and_jump (&blab); | 8973 t = build_and_jump (&blab); |
9003 if (cond_is_first) | 8974 if (cond_is_first) |
9004 exit = fold_build3_loc (start_locus, | 8975 exit = fold_build3_loc (start_locus, |
9005 COND_EXPR, void_type_node, cond, exit, t); | 8976 COND_EXPR, void_type_node, cond, exit, t); |
9006 else | 8977 else |
9007 exit = fold_build3_loc (input_location, | 8978 exit = fold_build3_loc (input_location, |
9008 COND_EXPR, void_type_node, cond, exit, t); | 8979 COND_EXPR, void_type_node, cond, exit, t); |
9009 } | 8980 } |
9010 | 8981 |
9011 add_stmt (top); | 8982 add_stmt (top); |
9012 } | 8983 } |
9013 | 8984 |
9014 if (body) | 8985 if (body) |
9041 skip = !block_may_fallthru (cur_stmt_list); | 9012 skip = !block_may_fallthru (cur_stmt_list); |
9042 | 9013 |
9043 if (!label) | 9014 if (!label) |
9044 { | 9015 { |
9045 if (!skip) | 9016 if (!skip) |
9046 *label_p = label = create_artificial_label (loc); | 9017 *label_p = label = create_artificial_label (loc); |
9047 } | 9018 } |
9048 else if (TREE_CODE (label) == LABEL_DECL) | 9019 else if (TREE_CODE (label) == LABEL_DECL) |
9049 ; | 9020 ; |
9050 else switch (TREE_INT_CST_LOW (label)) | 9021 else switch (TREE_INT_CST_LOW (label)) |
9051 { | 9022 { |
9052 case 0: | 9023 case 0: |
9053 if (is_break) | 9024 if (is_break) |
9054 error_at (loc, "break statement not within loop or switch"); | 9025 error_at (loc, "break statement not within loop or switch"); |
9055 else | 9026 else |
9056 error_at (loc, "continue statement not within a loop"); | 9027 error_at (loc, "continue statement not within a loop"); |
9057 return NULL_TREE; | 9028 return NULL_TREE; |
9058 | 9029 |
9059 case 1: | 9030 case 1: |
9060 gcc_assert (is_break); | 9031 gcc_assert (is_break); |
9061 error_at (loc, "break statement used with OpenMP for loop"); | 9032 error_at (loc, "break statement used with OpenMP for loop"); |
9082 if (expr == error_mark_node) | 9053 if (expr == error_mark_node) |
9083 ; | 9054 ; |
9084 else if (!TREE_SIDE_EFFECTS (expr)) | 9055 else if (!TREE_SIDE_EFFECTS (expr)) |
9085 { | 9056 { |
9086 if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr)) | 9057 if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr)) |
9087 warning_at (loc, OPT_Wunused_value, "statement with no effect"); | 9058 warning_at (loc, OPT_Wunused_value, "statement with no effect"); |
9088 } | 9059 } |
9089 else | 9060 else |
9090 warn_if_unused_value (expr, loc); | 9061 warn_if_unused_value (expr, loc); |
9091 } | 9062 } |
9092 | 9063 |
9161 are contained in it. */ | 9132 are contained in it. */ |
9162 keep_next_level (); | 9133 keep_next_level (); |
9163 ret = c_begin_compound_stmt (true); | 9134 ret = c_begin_compound_stmt (true); |
9164 | 9135 |
9165 c_bindings_start_stmt_expr (c_switch_stack == NULL | 9136 c_bindings_start_stmt_expr (c_switch_stack == NULL |
9166 ? NULL | 9137 ? NULL |
9167 : c_switch_stack->bindings); | 9138 : c_switch_stack->bindings); |
9168 | 9139 |
9169 /* Mark the current statement list as belonging to a statement list. */ | 9140 /* Mark the current statement list as belonging to a statement list. */ |
9170 STATEMENT_LIST_STMT_EXPR (ret) = 1; | 9141 STATEMENT_LIST_STMT_EXPR (ret) = 1; |
9171 | 9142 |
9172 return ret; | 9143 return ret; |
9182 tree *last_p; | 9153 tree *last_p; |
9183 | 9154 |
9184 body = c_end_compound_stmt (loc, body, true); | 9155 body = c_end_compound_stmt (loc, body, true); |
9185 | 9156 |
9186 c_bindings_end_stmt_expr (c_switch_stack == NULL | 9157 c_bindings_end_stmt_expr (c_switch_stack == NULL |
9187 ? NULL | 9158 ? NULL |
9188 : c_switch_stack->bindings); | 9159 : c_switch_stack->bindings); |
9189 | 9160 |
9190 /* Locate the last statement in BODY. See c_end_compound_stmt | 9161 /* Locate the last statement in BODY. See c_end_compound_stmt |
9191 about always returning a BIND_EXPR. */ | 9162 about always returning a BIND_EXPR. */ |
9192 last_p = &BIND_EXPR_BODY (body); | 9163 last_p = &BIND_EXPR_BODY (body); |
9193 last = BIND_EXPR_BODY (body); | 9164 last = BIND_EXPR_BODY (body); |
9197 { | 9168 { |
9198 tree_stmt_iterator i; | 9169 tree_stmt_iterator i; |
9199 | 9170 |
9200 /* This can happen with degenerate cases like ({ }). No value. */ | 9171 /* This can happen with degenerate cases like ({ }). No value. */ |
9201 if (!TREE_SIDE_EFFECTS (last)) | 9172 if (!TREE_SIDE_EFFECTS (last)) |
9202 return body; | 9173 return body; |
9203 | 9174 |
9204 /* If we're supposed to generate side effects warnings, process | 9175 /* If we're supposed to generate side effects warnings, process |
9205 all of the statements except the last. */ | 9176 all of the statements except the last. */ |
9206 if (warn_unused_value) | 9177 if (warn_unused_value) |
9207 { | 9178 { |
9208 for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i)) | 9179 for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i)) |
9209 { | 9180 { |
9210 location_t tloc; | 9181 location_t tloc; |
9211 tree t = tsi_stmt (i); | 9182 tree t = tsi_stmt (i); |
9212 | 9183 |
9213 tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc; | 9184 tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc; |
9214 emit_side_effect_warnings (tloc, t); | 9185 emit_side_effect_warnings (tloc, t); |
9215 } | 9186 } |
9216 } | 9187 } |
9217 else | 9188 else |
9218 i = tsi_last (last); | 9189 i = tsi_last (last); |
9219 last_p = tsi_stmt_ptr (i); | 9190 last_p = tsi_stmt_ptr (i); |
9220 last = *last_p; | 9191 last = *last_p; |
9221 } | 9192 } |
9222 | 9193 |
9223 /* If the end of the list is exception related, then the list was split | 9194 /* If the end of the list is exception related, then the list was split |
9237 expression out from inside it. */ | 9208 expression out from inside it. */ |
9238 if (last == BIND_EXPR_BODY (body) | 9209 if (last == BIND_EXPR_BODY (body) |
9239 && BIND_EXPR_VARS (body) == NULL) | 9210 && BIND_EXPR_VARS (body) == NULL) |
9240 { | 9211 { |
9241 /* Even if this looks constant, do not allow it in a constant | 9212 /* Even if this looks constant, do not allow it in a constant |
9242 expression. */ | 9213 expression. */ |
9243 last = c_wrap_maybe_const (last, true); | 9214 last = c_wrap_maybe_const (last, true); |
9244 /* Do not warn if the return value of a statement expression is | 9215 /* Do not warn if the return value of a statement expression is |
9245 unused. */ | 9216 unused. */ |
9246 TREE_NO_WARNING (last) = 1; | 9217 TREE_NO_WARNING (last) = 1; |
9247 return last; | 9218 return last; |
9248 } | 9219 } |
9249 | 9220 |
9250 /* Extract the type of said expression. */ | 9221 /* Extract the type of said expression. */ |
9299 tree block = NULL; | 9270 tree block = NULL; |
9300 | 9271 |
9301 if (do_scope) | 9272 if (do_scope) |
9302 { | 9273 { |
9303 if (c_dialect_objc ()) | 9274 if (c_dialect_objc ()) |
9304 objc_clear_super_receiver (); | 9275 objc_clear_super_receiver (); |
9305 block = pop_scope (); | 9276 block = pop_scope (); |
9306 } | 9277 } |
9307 | 9278 |
9308 stmt = pop_stmt_list (stmt); | 9279 stmt = pop_stmt_list (stmt); |
9309 stmt = c_build_bind_expr (loc, block, stmt); | 9280 stmt = c_build_bind_expr (loc, block, stmt); |
9361 performed or they have both just been converted to some other type in which | 9332 performed or they have both just been converted to some other type in which |
9362 the arithmetic is to be done. */ | 9333 the arithmetic is to be done. */ |
9363 | 9334 |
9364 tree | 9335 tree |
9365 build_binary_op (location_t location, enum tree_code code, | 9336 build_binary_op (location_t location, enum tree_code code, |
9366 tree orig_op0, tree orig_op1, int convert_p) | 9337 tree orig_op0, tree orig_op1, int convert_p) |
9367 { | 9338 { |
9368 tree type0, type1, orig_type0, orig_type1; | 9339 tree type0, type1, orig_type0, orig_type1; |
9369 tree eptype; | 9340 tree eptype; |
9370 enum tree_code code0, code1; | 9341 enum tree_code code0, code1; |
9371 tree op0, op1; | 9342 tree op0, op1; |
9445 op1 = remove_c_maybe_const_expr (op1); | 9416 op1 = remove_c_maybe_const_expr (op1); |
9446 int_operands = (op0_int_operands && op1_int_operands); | 9417 int_operands = (op0_int_operands && op1_int_operands); |
9447 if (int_operands) | 9418 if (int_operands) |
9448 { | 9419 { |
9449 int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST | 9420 int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST |
9450 && TREE_CODE (orig_op1) == INTEGER_CST); | 9421 && TREE_CODE (orig_op1) == INTEGER_CST); |
9451 int_const = (int_const_or_overflow | 9422 int_const = (int_const_or_overflow |
9452 && !TREE_OVERFLOW (orig_op0) | 9423 && !TREE_OVERFLOW (orig_op0) |
9453 && !TREE_OVERFLOW (orig_op1)); | 9424 && !TREE_OVERFLOW (orig_op1)); |
9454 } | 9425 } |
9455 else | 9426 else |
9456 int_const = int_const_or_overflow = false; | 9427 int_const = int_const_or_overflow = false; |
9457 | 9428 |
9458 if (convert_p) | 9429 if (convert_p) |
9506 { | 9477 { |
9507 op0 = TREE_OPERAND (op0, 0); | 9478 op0 = TREE_OPERAND (op0, 0); |
9508 type0 = TREE_TYPE (op0); | 9479 type0 = TREE_TYPE (op0); |
9509 } | 9480 } |
9510 else if (may_need_excess_precision | 9481 else if (may_need_excess_precision |
9511 && (eptype = excess_precision_type (type0)) != NULL_TREE) | 9482 && (eptype = excess_precision_type (type0)) != NULL_TREE) |
9512 { | 9483 { |
9513 type0 = eptype; | 9484 type0 = eptype; |
9514 op0 = convert (eptype, op0); | 9485 op0 = convert (eptype, op0); |
9515 } | 9486 } |
9516 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR) | 9487 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR) |
9517 { | 9488 { |
9518 op1 = TREE_OPERAND (op1, 0); | 9489 op1 = TREE_OPERAND (op1, 0); |
9519 type1 = TREE_TYPE (op1); | 9490 type1 = TREE_TYPE (op1); |
9520 } | 9491 } |
9521 else if (may_need_excess_precision | 9492 else if (may_need_excess_precision |
9522 && (eptype = excess_precision_type (type1)) != NULL_TREE) | 9493 && (eptype = excess_precision_type (type1)) != NULL_TREE) |
9523 { | 9494 { |
9524 type1 = eptype; | 9495 type1 = eptype; |
9525 op1 = convert (eptype, op1); | 9496 op1 = convert (eptype, op1); |
9526 } | 9497 } |
9527 | 9498 |
9530 switch (code) | 9501 switch (code) |
9531 { | 9502 { |
9532 case PLUS_EXPR: | 9503 case PLUS_EXPR: |
9533 /* Handle the pointer + int case. */ | 9504 /* Handle the pointer + int case. */ |
9534 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) | 9505 if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) |
9535 { | 9506 { |
9536 ret = pointer_int_sum (location, PLUS_EXPR, op0, op1); | 9507 ret = pointer_int_sum (location, PLUS_EXPR, op0, op1); |
9537 goto return_build_binary_op; | 9508 goto return_build_binary_op; |
9538 } | 9509 } |
9539 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE) | 9510 else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE) |
9540 { | 9511 { |
9541 ret = pointer_int_sum (location, PLUS_EXPR, op1, op0); | 9512 ret = pointer_int_sum (location, PLUS_EXPR, op1, op0); |
9542 goto return_build_binary_op; | 9513 goto return_build_binary_op; |
9543 } | 9514 } |
9544 else | 9515 else |
9545 common = 1; | 9516 common = 1; |
9546 break; | 9517 break; |
9547 | 9518 |
9548 case MINUS_EXPR: | 9519 case MINUS_EXPR: |
9549 /* Subtraction of two similar pointers. | 9520 /* Subtraction of two similar pointers. |
9550 We must subtract them as integers, then divide by object size. */ | 9521 We must subtract them as integers, then divide by object size. */ |
9551 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE | 9522 if (code0 == POINTER_TYPE && code1 == POINTER_TYPE |
9552 && comp_target_types (location, type0, type1)) | 9523 && comp_target_types (location, type0, type1)) |
9553 { | 9524 { |
9554 ret = pointer_diff (location, op0, op1); | 9525 ret = pointer_diff (location, op0, op1); |
9555 goto return_build_binary_op; | 9526 goto return_build_binary_op; |
9556 } | 9527 } |
9557 /* Handle pointer minus int. Just like pointer plus int. */ | 9528 /* Handle pointer minus int. Just like pointer plus int. */ |
9558 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) | 9529 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) |
9559 { | 9530 { |
9560 ret = pointer_int_sum (location, MINUS_EXPR, op0, op1); | 9531 ret = pointer_int_sum (location, MINUS_EXPR, op0, op1); |
9561 goto return_build_binary_op; | 9532 goto return_build_binary_op; |
9562 } | 9533 } |
9563 else | 9534 else |
9564 common = 1; | 9535 common = 1; |
9565 break; | 9536 break; |
9566 | 9537 |
9567 case MULT_EXPR: | 9538 case MULT_EXPR: |
9568 common = 1; | 9539 common = 1; |
9569 break; | 9540 break; |
9574 case ROUND_DIV_EXPR: | 9545 case ROUND_DIV_EXPR: |
9575 case EXACT_DIV_EXPR: | 9546 case EXACT_DIV_EXPR: |
9576 warn_for_div_by_zero (location, op1); | 9547 warn_for_div_by_zero (location, op1); |
9577 | 9548 |
9578 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE | 9549 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE |
9579 || code0 == FIXED_POINT_TYPE | 9550 || code0 == FIXED_POINT_TYPE |
9580 || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE) | 9551 || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE) |
9581 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE | 9552 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE |
9582 || code1 == FIXED_POINT_TYPE | 9553 || code1 == FIXED_POINT_TYPE |
9583 || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)) | 9554 || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)) |
9584 { | 9555 { |
9585 enum tree_code tcode0 = code0, tcode1 = code1; | 9556 enum tree_code tcode0 = code0, tcode1 = code1; |
9586 | 9557 |
9587 if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE) | 9558 if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE) |
9588 tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0))); | 9559 tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0))); |
9589 if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE) | 9560 if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE) |
9590 tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1))); | 9561 tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1))); |
9591 | 9562 |
9592 if (!((tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE) | 9563 if (!((tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE) |
9593 || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE))) | 9564 || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE))) |
9594 resultcode = RDIV_EXPR; | 9565 resultcode = RDIV_EXPR; |
9595 else | 9566 else |
9596 /* Although it would be tempting to shorten always here, that | 9567 /* Although it would be tempting to shorten always here, that |
9597 loses on some targets, since the modulo instruction is | 9568 loses on some targets, since the modulo instruction is |
9598 undefined if the quotient can't be represented in the | 9569 undefined if the quotient can't be represented in the |
9599 computation mode. We shorten only if unsigned or if | 9570 computation mode. We shorten only if unsigned or if |
9600 dividing by something we know != -1. */ | 9571 dividing by something we know != -1. */ |
9601 shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0)) | 9572 shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0)) |
9602 || (TREE_CODE (op1) == INTEGER_CST | 9573 || (TREE_CODE (op1) == INTEGER_CST |
9603 && !integer_all_onesp (op1))); | 9574 && !integer_all_onesp (op1))); |
9604 common = 1; | 9575 common = 1; |
9605 } | 9576 } |
9606 break; | 9577 break; |
9607 | 9578 |
9608 case BIT_AND_EXPR: | 9579 case BIT_AND_EXPR: |
9609 case BIT_IOR_EXPR: | 9580 case BIT_IOR_EXPR: |
9610 case BIT_XOR_EXPR: | 9581 case BIT_XOR_EXPR: |
9611 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) | 9582 if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) |
9612 shorten = -1; | 9583 shorten = -1; |
9613 /* Allow vector types which are not floating point types. */ | 9584 /* Allow vector types which are not floating point types. */ |
9614 else if (code0 == VECTOR_TYPE | 9585 else if (code0 == VECTOR_TYPE |
9615 && code1 == VECTOR_TYPE | 9586 && code1 == VECTOR_TYPE |
9616 && !VECTOR_FLOAT_TYPE_P (type0) | 9587 && !VECTOR_FLOAT_TYPE_P (type0) |
9617 && !VECTOR_FLOAT_TYPE_P (type1)) | 9588 && !VECTOR_FLOAT_TYPE_P (type1)) |
9618 common = 1; | 9589 common = 1; |
9619 break; | 9590 break; |
9620 | 9591 |
9621 case TRUNC_MOD_EXPR: | 9592 case TRUNC_MOD_EXPR: |
9622 case FLOOR_MOD_EXPR: | 9593 case FLOOR_MOD_EXPR: |
9623 warn_for_div_by_zero (location, op1); | 9594 warn_for_div_by_zero (location, op1); |
9624 | 9595 |
9625 if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE | 9596 if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE |
9626 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE | 9597 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE |
9627 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE) | 9598 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE) |
9628 common = 1; | 9599 common = 1; |
9629 else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) | 9600 else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) |
9630 { | 9601 { |
9631 /* Although it would be tempting to shorten always here, that loses | 9602 /* Although it would be tempting to shorten always here, that loses |
9632 on some targets, since the modulo instruction is undefined if the | 9603 on some targets, since the modulo instruction is undefined if the |
9633 quotient can't be represented in the computation mode. We shorten | 9604 quotient can't be represented in the computation mode. We shorten |
9634 only if unsigned or if dividing by something we know != -1. */ | 9605 only if unsigned or if dividing by something we know != -1. */ |
9635 shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0)) | 9606 shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0)) |
9636 || (TREE_CODE (op1) == INTEGER_CST | 9607 || (TREE_CODE (op1) == INTEGER_CST |
9637 && !integer_all_onesp (op1))); | 9608 && !integer_all_onesp (op1))); |
9638 common = 1; | 9609 common = 1; |
9639 } | 9610 } |
9640 break; | 9611 break; |
9641 | 9612 |
9642 case TRUTH_ANDIF_EXPR: | 9613 case TRUTH_ANDIF_EXPR: |
9643 case TRUTH_ORIF_EXPR: | 9614 case TRUTH_ORIF_EXPR: |
9644 case TRUTH_AND_EXPR: | 9615 case TRUTH_AND_EXPR: |
9659 op1 = c_common_truthvalue_conversion (location, op1); | 9630 op1 = c_common_truthvalue_conversion (location, op1); |
9660 converted = 1; | 9631 converted = 1; |
9661 boolean_op = true; | 9632 boolean_op = true; |
9662 } | 9633 } |
9663 if (code == TRUTH_ANDIF_EXPR) | 9634 if (code == TRUTH_ANDIF_EXPR) |
9664 { | 9635 { |
9665 int_const_or_overflow = (int_operands | 9636 int_const_or_overflow = (int_operands |
9666 && TREE_CODE (orig_op0) == INTEGER_CST | 9637 && TREE_CODE (orig_op0) == INTEGER_CST |
9667 && (op0 == truthvalue_false_node | 9638 && (op0 == truthvalue_false_node |
9668 || TREE_CODE (orig_op1) == INTEGER_CST)); | 9639 || TREE_CODE (orig_op1) == INTEGER_CST)); |
9669 int_const = (int_const_or_overflow | 9640 int_const = (int_const_or_overflow |
9670 && !TREE_OVERFLOW (orig_op0) | 9641 && !TREE_OVERFLOW (orig_op0) |
9671 && (op0 == truthvalue_false_node | 9642 && (op0 == truthvalue_false_node |
9672 || !TREE_OVERFLOW (orig_op1))); | 9643 || !TREE_OVERFLOW (orig_op1))); |
9673 } | 9644 } |
9674 else if (code == TRUTH_ORIF_EXPR) | 9645 else if (code == TRUTH_ORIF_EXPR) |
9675 { | 9646 { |
9676 int_const_or_overflow = (int_operands | 9647 int_const_or_overflow = (int_operands |
9677 && TREE_CODE (orig_op0) == INTEGER_CST | 9648 && TREE_CODE (orig_op0) == INTEGER_CST |
9678 && (op0 == truthvalue_true_node | 9649 && (op0 == truthvalue_true_node |
9679 || TREE_CODE (orig_op1) == INTEGER_CST)); | 9650 || TREE_CODE (orig_op1) == INTEGER_CST)); |
9680 int_const = (int_const_or_overflow | 9651 int_const = (int_const_or_overflow |
9681 && !TREE_OVERFLOW (orig_op0) | 9652 && !TREE_OVERFLOW (orig_op0) |
9682 && (op0 == truthvalue_true_node | 9653 && (op0 == truthvalue_true_node |
9683 || !TREE_OVERFLOW (orig_op1))); | 9654 || !TREE_OVERFLOW (orig_op1))); |
9684 } | 9655 } |
9685 break; | 9656 break; |
9686 | 9657 |
9687 /* Shift operations: result has same type as first operand; | 9658 /* Shift operations: result has same type as first operand; |
9688 always convert second operand to int. | 9659 always convert second operand to int. |
9689 Also set SHORT_SHIFT if shifting rightward. */ | 9660 Also set SHORT_SHIFT if shifting rightward. */ |
9690 | 9661 |
9691 case RSHIFT_EXPR: | 9662 case RSHIFT_EXPR: |
9692 if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE | 9663 if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE |
9693 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE) | 9664 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE) |
9694 { | 9665 { |
9788 break; | 9759 break; |
9789 | 9760 |
9790 case EQ_EXPR: | 9761 case EQ_EXPR: |
9791 case NE_EXPR: | 9762 case NE_EXPR: |
9792 if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)) | 9763 if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)) |
9793 warning_at (location, | 9764 warning_at (location, |
9794 OPT_Wfloat_equal, | 9765 OPT_Wfloat_equal, |
9795 "comparing floating point with == or != is unsafe"); | 9766 "comparing floating point with == or != is unsafe"); |
9796 /* Result of comparison is always int, | 9767 /* Result of comparison is always int, |
9797 but don't convert the args to int! */ | 9768 but don't convert the args to int! */ |
9798 build_type = integer_type_node; | 9769 build_type = integer_type_node; |
9799 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE | 9770 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE |
9800 || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE) | 9771 || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE) |
9801 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE | 9772 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE |
9802 || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE)) | 9773 || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE)) |
9884 result_type = build_pointer_type | 9855 result_type = build_pointer_type |
9885 (build_qualified_type (void_type_node, qual)); | 9856 (build_qualified_type (void_type_node, qual)); |
9886 } | 9857 } |
9887 } | 9858 } |
9888 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) | 9859 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) |
9889 { | 9860 { |
9890 result_type = type0; | 9861 result_type = type0; |
9891 pedwarn (location, 0, "comparison between pointer and integer"); | 9862 pedwarn (location, 0, "comparison between pointer and integer"); |
9892 } | 9863 } |
9893 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) | 9864 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) |
9894 { | 9865 { |
9895 result_type = type1; | 9866 result_type = type1; |
9896 pedwarn (location, 0, "comparison between pointer and integer"); | 9867 pedwarn (location, 0, "comparison between pointer and integer"); |
9897 } | 9868 } |
9898 break; | 9869 break; |
9899 | 9870 |
9900 case LE_EXPR: | 9871 case LE_EXPR: |
9901 case GE_EXPR: | 9872 case GE_EXPR: |
9902 case LT_EXPR: | 9873 case LT_EXPR: |
9903 case GT_EXPR: | 9874 case GT_EXPR: |
9904 build_type = integer_type_node; | 9875 build_type = integer_type_node; |
9905 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE | 9876 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE |
9906 || code0 == FIXED_POINT_TYPE) | 9877 || code0 == FIXED_POINT_TYPE) |
9907 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE | 9878 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE |
9908 || code1 == FIXED_POINT_TYPE)) | 9879 || code1 == FIXED_POINT_TYPE)) |
9909 short_compare = 1; | 9880 short_compare = 1; |
9910 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) | 9881 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) |
9911 { | 9882 { |
9912 addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0)); | 9883 addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0)); |
9913 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1)); | 9884 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1)); |
9914 addr_space_t as_common; | 9885 addr_space_t as_common; |
9963 else if (extra_warnings) | 9934 else if (extra_warnings) |
9964 warning_at (location, OPT_Wextra, | 9935 warning_at (location, OPT_Wextra, |
9965 "ordered comparison of pointer with integer zero"); | 9936 "ordered comparison of pointer with integer zero"); |
9966 } | 9937 } |
9967 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) | 9938 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) |
9968 { | 9939 { |
9969 result_type = type0; | 9940 result_type = type0; |
9970 pedwarn (location, 0, "comparison between pointer and integer"); | 9941 pedwarn (location, 0, "comparison between pointer and integer"); |
9971 } | 9942 } |
9972 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) | 9943 else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) |
9973 { | 9944 { |
9974 result_type = type1; | 9945 result_type = type1; |
9975 pedwarn (location, 0, "comparison between pointer and integer"); | 9946 pedwarn (location, 0, "comparison between pointer and integer"); |
9976 } | 9947 } |
9977 break; | 9948 break; |
9978 | 9949 |
9979 default: | 9950 default: |
9980 gcc_unreachable (); | 9951 gcc_unreachable (); |
9981 } | 9952 } |
9983 if (code0 == ERROR_MARK || code1 == ERROR_MARK) | 9954 if (code0 == ERROR_MARK || code1 == ERROR_MARK) |
9984 return error_mark_node; | 9955 return error_mark_node; |
9985 | 9956 |
9986 if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE | 9957 if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE |
9987 && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1)) | 9958 && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1)) |
9988 || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0), | 9959 || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0), |
9989 TREE_TYPE (type1)))) | 9960 TREE_TYPE (type1)))) |
9990 { | 9961 { |
9991 binary_op_error (location, code, type0, type1); | 9962 binary_op_error (location, code, type0, type1); |
9992 return error_mark_node; | 9963 return error_mark_node; |
9993 } | 9964 } |
9994 | 9965 |
10096 ret = build2 (COMPLEX_EXPR, result_type, real, imag); | 10067 ret = build2 (COMPLEX_EXPR, result_type, real, imag); |
10097 goto return_build_binary_op; | 10068 goto return_build_binary_op; |
10098 } | 10069 } |
10099 | 10070 |
10100 /* For certain operations (which identify themselves by shorten != 0) | 10071 /* For certain operations (which identify themselves by shorten != 0) |
10101 if both args were extended from the same smaller type, | 10072 if both args were extended from the same smaller type, |
10102 do the arithmetic in that type and then extend. | 10073 do the arithmetic in that type and then extend. |
10103 | 10074 |
10104 shorten !=0 and !=1 indicates a bitwise operation. | 10075 shorten !=0 and !=1 indicates a bitwise operation. |
10105 For them, this optimization is safe only if | 10076 For them, this optimization is safe only if |
10106 both args are zero-extended or both are sign-extended. | 10077 both args are zero-extended or both are sign-extended. |
10107 Otherwise, we might change the result. | 10078 Otherwise, we might change the result. |
10108 Eg, (short)-1 | (unsigned short)-1 is (int)-1 | 10079 Eg, (short)-1 | (unsigned short)-1 is (int)-1 |
10109 but calculated in (unsigned short) it would be (unsigned short)-1. */ | 10080 but calculated in (unsigned short) it would be (unsigned short)-1. */ |
10110 | 10081 |
10111 if (shorten && none_complex) | 10082 if (shorten && none_complex) |
10112 { | 10083 { |
10113 final_type = result_type; | 10084 final_type = result_type; |
10114 result_type = shorten_binary_op (result_type, op0, op1, | 10085 result_type = shorten_binary_op (result_type, op0, op1, |
10115 shorten == -1); | 10086 shorten == -1); |
10116 } | 10087 } |
10117 | 10088 |
10118 /* Shifts can be shortened if shifting right. */ | 10089 /* Shifts can be shortened if shifting right. */ |
10119 | 10090 |
10120 if (short_shift) | 10091 if (short_shift) |
10121 { | 10092 { |
10122 int unsigned_arg; | 10093 int unsigned_arg; |
10123 tree arg0 = get_narrower (op0, &unsigned_arg); | 10094 tree arg0 = get_narrower (op0, &unsigned_arg); |
10124 | 10095 |
10125 final_type = result_type; | 10096 final_type = result_type; |
10126 | 10097 |
10127 if (arg0 == op0 && final_type == TREE_TYPE (op0)) | 10098 if (arg0 == op0 && final_type == TREE_TYPE (op0)) |
10128 unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0)); | 10099 unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0)); |
10129 | 10100 |
10130 if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type) | 10101 if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type) |
10131 && tree_int_cst_sgn (op1) > 0 | 10102 && tree_int_cst_sgn (op1) > 0 |
10132 /* We can shorten only if the shift count is less than the | 10103 /* We can shorten only if the shift count is less than the |
10133 number of bits in the smaller type size. */ | 10104 number of bits in the smaller type size. */ |
10134 && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0 | 10105 && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0 |
10135 /* We cannot drop an unsigned shift after sign-extension. */ | 10106 /* We cannot drop an unsigned shift after sign-extension. */ |
10136 && (!TYPE_UNSIGNED (final_type) || unsigned_arg)) | 10107 && (!TYPE_UNSIGNED (final_type) || unsigned_arg)) |
10137 { | 10108 { |
10138 /* Do an unsigned shift if the operand was zero-extended. */ | 10109 /* Do an unsigned shift if the operand was zero-extended. */ |
10139 result_type | 10110 result_type |
10140 = c_common_signed_or_unsigned_type (unsigned_arg, | 10111 = c_common_signed_or_unsigned_type (unsigned_arg, |
10141 TREE_TYPE (arg0)); | 10112 TREE_TYPE (arg0)); |
10142 /* Convert value-to-be-shifted to that type. */ | 10113 /* Convert value-to-be-shifted to that type. */ |
10143 if (TREE_TYPE (op0) != result_type) | 10114 if (TREE_TYPE (op0) != result_type) |
10144 op0 = convert (result_type, op0); | 10115 op0 = convert (result_type, op0); |
10145 converted = 1; | 10116 converted = 1; |
10146 } | 10117 } |
10147 } | 10118 } |
10148 | 10119 |
10149 /* Comparison operations are shortened too but differently. | 10120 /* Comparison operations are shortened too but differently. |
10150 They identify themselves by setting short_compare = 1. */ | 10121 They identify themselves by setting short_compare = 1. */ |
10151 | 10122 |
10152 if (short_compare) | 10123 if (short_compare) |
10153 { | 10124 { |
10154 /* Don't write &op0, etc., because that would prevent op0 | 10125 /* Don't write &op0, etc., because that would prevent op0 |
10155 from being kept in a register. | 10126 from being kept in a register. |
10156 Instead, make copies of the our local variables and | 10127 Instead, make copies of the our local variables and |
10157 pass the copies by reference, then copy them back afterward. */ | 10128 pass the copies by reference, then copy them back afterward. */ |
10158 tree xop0 = op0, xop1 = op1, xresult_type = result_type; | 10129 tree xop0 = op0, xop1 = op1, xresult_type = result_type; |
10159 enum tree_code xresultcode = resultcode; | 10130 enum tree_code xresultcode = resultcode; |
10160 tree val | 10131 tree val |
10161 = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode); | 10132 = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode); |
10162 | 10133 |
10163 if (val != 0) | 10134 if (val != 0) |
10164 { | 10135 { |
10165 ret = val; | 10136 ret = val; |
10166 goto return_build_binary_op; | 10137 goto return_build_binary_op; |
10167 } | 10138 } |
10168 | 10139 |
10169 op0 = xop0, op1 = xop1; | 10140 op0 = xop0, op1 = xop1; |
10170 converted = 1; | 10141 converted = 1; |
10171 resultcode = xresultcode; | 10142 resultcode = xresultcode; |
10172 | 10143 |
10173 if (c_inhibit_evaluation_warnings == 0) | 10144 if (c_inhibit_evaluation_warnings == 0) |
10174 { | 10145 { |
10175 bool op0_maybe_const = true; | 10146 bool op0_maybe_const = true; |
10176 bool op1_maybe_const = true; | 10147 bool op1_maybe_const = true; |
10177 tree orig_op0_folded, orig_op1_folded; | 10148 tree orig_op0_folded, orig_op1_folded; |
10178 | 10149 |
10179 if (in_late_binary_op) | 10150 if (in_late_binary_op) |
10180 { | 10151 { |
10181 orig_op0_folded = orig_op0; | 10152 orig_op0_folded = orig_op0; |
10182 orig_op1_folded = orig_op1; | 10153 orig_op1_folded = orig_op1; |
10183 } | 10154 } |
10184 else | 10155 else |
10185 { | 10156 { |
10186 /* Fold for the sake of possible warnings, as in | 10157 /* Fold for the sake of possible warnings, as in |
10187 build_conditional_expr. This requires the | 10158 build_conditional_expr. This requires the |
10188 "original" values to be folded, not just op0 and | 10159 "original" values to be folded, not just op0 and |
10189 op1. */ | 10160 op1. */ |
10190 c_inhibit_evaluation_warnings++; | 10161 c_inhibit_evaluation_warnings++; |
10191 op0 = c_fully_fold (op0, require_constant_value, | 10162 op0 = c_fully_fold (op0, require_constant_value, |
10192 &op0_maybe_const); | 10163 &op0_maybe_const); |
10193 op1 = c_fully_fold (op1, require_constant_value, | 10164 op1 = c_fully_fold (op1, require_constant_value, |
10194 &op1_maybe_const); | 10165 &op1_maybe_const); |
10195 c_inhibit_evaluation_warnings--; | 10166 c_inhibit_evaluation_warnings--; |
10196 orig_op0_folded = c_fully_fold (orig_op0, | 10167 orig_op0_folded = c_fully_fold (orig_op0, |
10197 require_constant_value, | 10168 require_constant_value, |
10198 NULL); | 10169 NULL); |
10199 orig_op1_folded = c_fully_fold (orig_op1, | 10170 orig_op1_folded = c_fully_fold (orig_op1, |
10200 require_constant_value, | 10171 require_constant_value, |
10201 NULL); | 10172 NULL); |
10202 } | 10173 } |
10203 | 10174 |
10204 if (warn_sign_compare) | 10175 if (warn_sign_compare) |
10205 warn_for_sign_compare (location, orig_op0_folded, | 10176 warn_for_sign_compare (location, orig_op0_folded, |
10206 orig_op1_folded, op0, op1, | 10177 orig_op1_folded, op0, op1, |
10207 result_type, resultcode); | 10178 result_type, resultcode); |
10208 if (!in_late_binary_op) | 10179 if (!in_late_binary_op) |
10209 { | 10180 { |
10210 if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST) | 10181 if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST) |
10211 op0 = c_wrap_maybe_const (op0, !op0_maybe_const); | 10182 op0 = c_wrap_maybe_const (op0, !op0_maybe_const); |
10212 if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST) | 10183 if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST) |
10213 op1 = c_wrap_maybe_const (op1, !op1_maybe_const); | 10184 op1 = c_wrap_maybe_const (op1, !op1_maybe_const); |
10214 } | 10185 } |
10215 } | 10186 } |
10216 } | 10187 } |
10217 } | 10188 } |
10218 | 10189 |
10219 /* At this point, RESULT_TYPE must be nonzero to avoid an error message. | 10190 /* At this point, RESULT_TYPE must be nonzero to avoid an error message. |
10220 If CONVERTED is zero, both args will be converted to type RESULT_TYPE. | 10191 If CONVERTED is zero, both args will be converted to type RESULT_TYPE. |
10221 Then the expression will be built. | 10192 Then the expression will be built. |
10243 { | 10214 { |
10244 op0 = ep_convert_and_check (result_type, op0, semantic_result_type); | 10215 op0 = ep_convert_and_check (result_type, op0, semantic_result_type); |
10245 op1 = ep_convert_and_check (result_type, op1, semantic_result_type); | 10216 op1 = ep_convert_and_check (result_type, op1, semantic_result_type); |
10246 | 10217 |
10247 /* This can happen if one operand has a vector type, and the other | 10218 /* This can happen if one operand has a vector type, and the other |
10248 has a different type. */ | 10219 has a different type. */ |
10249 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK) | 10220 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK) |
10250 return error_mark_node; | 10221 return error_mark_node; |
10251 } | 10222 } |
10252 | 10223 |
10253 /* Treat expressions in initializers specially as they can't trap. */ | 10224 /* Treat expressions in initializers specially as they can't trap. */ |
10254 if (int_const_or_overflow) | 10225 if (int_const_or_overflow) |
10255 ret = (require_constant_value | 10226 ret = (require_constant_value |
10256 ? fold_build2_initializer_loc (location, resultcode, build_type, | 10227 ? fold_build2_initializer_loc (location, resultcode, build_type, |
10257 op0, op1) | 10228 op0, op1) |
10258 : fold_build2_loc (location, resultcode, build_type, op0, op1)); | 10229 : fold_build2_loc (location, resultcode, build_type, op0, op1)); |
10259 else | 10230 else |
10260 ret = build2 (resultcode, build_type, op0, op1); | 10231 ret = build2 (resultcode, build_type, op0, op1); |
10261 if (final_type != 0) | 10232 if (final_type != 0) |
10262 ret = convert (final_type, ret); | 10233 ret = convert (final_type, ret); |
10263 | 10234 |
10264 return_build_binary_op: | 10235 return_build_binary_op: |
10265 gcc_assert (ret != error_mark_node); | 10236 gcc_assert (ret != error_mark_node); |
10266 if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const) | 10237 if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const) |
10267 ret = (int_operands | 10238 ret = (int_operands |
10268 ? note_integer_operands (ret) | 10239 ? note_integer_operands (ret) |
10269 : build1 (NOP_EXPR, TREE_TYPE (ret), ret)); | 10240 : build1 (NOP_EXPR, TREE_TYPE (ret), ret)); |
10270 else if (TREE_CODE (ret) != INTEGER_CST && int_operands | 10241 else if (TREE_CODE (ret) != INTEGER_CST && int_operands |
10271 && !in_late_binary_op) | 10242 && !in_late_binary_op) |
10272 ret = note_integer_operands (ret); | 10243 ret = note_integer_operands (ret); |
10273 if (semantic_result_type) | 10244 if (semantic_result_type) |
10274 ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret); | 10245 ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret); |
10275 protected_set_expr_location (ret, location); | 10246 protected_set_expr_location (ret, location); |
10276 return ret; | 10247 return ret; |
10320 expr = c_common_truthvalue_conversion (location, expr); | 10291 expr = c_common_truthvalue_conversion (location, expr); |
10321 | 10292 |
10322 if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const) | 10293 if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const) |
10323 { | 10294 { |
10324 if (TREE_OVERFLOW (expr)) | 10295 if (TREE_OVERFLOW (expr)) |
10325 return expr; | 10296 return expr; |
10326 else | 10297 else |
10327 return note_integer_operands (expr); | 10298 return note_integer_operands (expr); |
10328 } | 10299 } |
10329 if (TREE_CODE (expr) == INTEGER_CST && !int_const) | 10300 if (TREE_CODE (expr) == INTEGER_CST && !int_const) |
10330 return build1 (NOP_EXPR, TREE_TYPE (expr), expr); | 10301 return build1 (NOP_EXPR, TREE_TYPE (expr), expr); |
10331 return expr; | 10302 return expr; |
10332 } | 10303 } |
10340 { | 10311 { |
10341 if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR) | 10312 if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR) |
10342 { | 10313 { |
10343 tree decl = COMPOUND_LITERAL_EXPR_DECL (expr); | 10314 tree decl = COMPOUND_LITERAL_EXPR_DECL (expr); |
10344 /* Executing a compound literal inside a function reinitializes | 10315 /* Executing a compound literal inside a function reinitializes |
10345 it. */ | 10316 it. */ |
10346 if (!TREE_STATIC (decl)) | 10317 if (!TREE_STATIC (decl)) |
10347 *se = true; | 10318 *se = true; |
10348 return decl; | 10319 return decl; |
10349 } | 10320 } |
10350 else | 10321 else |
10351 return expr; | 10322 return expr; |
10352 } | 10323 } |
10435 bool remove = false; | 10406 bool remove = false; |
10436 bool need_complete = false; | 10407 bool need_complete = false; |
10437 bool need_implicitly_determined = false; | 10408 bool need_implicitly_determined = false; |
10438 | 10409 |
10439 switch (OMP_CLAUSE_CODE (c)) | 10410 switch (OMP_CLAUSE_CODE (c)) |
10440 { | 10411 { |
10441 case OMP_CLAUSE_SHARED: | 10412 case OMP_CLAUSE_SHARED: |
10442 name = "shared"; | 10413 name = "shared"; |
10443 need_implicitly_determined = true; | 10414 need_implicitly_determined = true; |
10444 goto check_dup_generic; | 10415 goto check_dup_generic; |
10445 | 10416 |
10446 case OMP_CLAUSE_PRIVATE: | 10417 case OMP_CLAUSE_PRIVATE: |
10447 name = "private"; | 10418 name = "private"; |
10448 need_complete = true; | 10419 need_complete = true; |
10449 need_implicitly_determined = true; | 10420 need_implicitly_determined = true; |
10450 goto check_dup_generic; | 10421 goto check_dup_generic; |
10451 | 10422 |
10452 case OMP_CLAUSE_REDUCTION: | 10423 case OMP_CLAUSE_REDUCTION: |
10453 name = "reduction"; | 10424 name = "reduction"; |
10454 need_implicitly_determined = true; | 10425 need_implicitly_determined = true; |
10455 t = OMP_CLAUSE_DECL (c); | 10426 t = OMP_CLAUSE_DECL (c); |
10456 if (AGGREGATE_TYPE_P (TREE_TYPE (t)) | 10427 if (AGGREGATE_TYPE_P (TREE_TYPE (t)) |
10457 || POINTER_TYPE_P (TREE_TYPE (t))) | 10428 || POINTER_TYPE_P (TREE_TYPE (t))) |
10458 { | 10429 { |
10459 error_at (OMP_CLAUSE_LOCATION (c), | 10430 error_at (OMP_CLAUSE_LOCATION (c), |
10460 "%qE has invalid type for %<reduction%>", t); | 10431 "%qE has invalid type for %<reduction%>", t); |
10461 remove = true; | 10432 remove = true; |
10462 } | 10433 } |
10463 else if (FLOAT_TYPE_P (TREE_TYPE (t))) | 10434 else if (FLOAT_TYPE_P (TREE_TYPE (t))) |
10464 { | 10435 { |
10465 enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c); | 10436 enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c); |
10466 const char *r_name = NULL; | 10437 const char *r_name = NULL; |
10467 | 10438 |
10468 switch (r_code) | 10439 switch (r_code) |
10469 { | 10440 { |
10470 case PLUS_EXPR: | 10441 case PLUS_EXPR: |
10471 case MULT_EXPR: | 10442 case MULT_EXPR: |
10472 case MINUS_EXPR: | 10443 case MINUS_EXPR: |
10473 break; | 10444 break; |
10474 case BIT_AND_EXPR: | 10445 case BIT_AND_EXPR: |
10475 r_name = "&"; | 10446 r_name = "&"; |
10476 break; | 10447 break; |
10477 case BIT_XOR_EXPR: | 10448 case BIT_XOR_EXPR: |
10478 r_name = "^"; | 10449 r_name = "^"; |
10479 break; | 10450 break; |
10480 case BIT_IOR_EXPR: | 10451 case BIT_IOR_EXPR: |
10481 r_name = "|"; | 10452 r_name = "|"; |
10482 break; | 10453 break; |
10483 case TRUTH_ANDIF_EXPR: | 10454 case TRUTH_ANDIF_EXPR: |
10484 r_name = "&&"; | 10455 r_name = "&&"; |
10485 break; | 10456 break; |
10486 case TRUTH_ORIF_EXPR: | 10457 case TRUTH_ORIF_EXPR: |
10487 r_name = "||"; | 10458 r_name = "||"; |
10488 break; | 10459 break; |
10489 default: | 10460 default: |
10490 gcc_unreachable (); | 10461 gcc_unreachable (); |
10491 } | 10462 } |
10492 if (r_name) | 10463 if (r_name) |
10493 { | 10464 { |
10494 error_at (OMP_CLAUSE_LOCATION (c), | 10465 error_at (OMP_CLAUSE_LOCATION (c), |
10495 "%qE has invalid type for %<reduction(%s)%>", | 10466 "%qE has invalid type for %<reduction(%s)%>", |
10496 t, r_name); | 10467 t, r_name); |
10497 remove = true; | 10468 remove = true; |
10498 } | 10469 } |
10499 } | 10470 } |
10500 goto check_dup_generic; | 10471 goto check_dup_generic; |
10501 | 10472 |
10502 case OMP_CLAUSE_COPYPRIVATE: | 10473 case OMP_CLAUSE_COPYPRIVATE: |
10503 name = "copyprivate"; | 10474 name = "copyprivate"; |
10504 goto check_dup_generic; | 10475 goto check_dup_generic; |
10505 | 10476 |
10506 case OMP_CLAUSE_COPYIN: | 10477 case OMP_CLAUSE_COPYIN: |
10507 name = "copyin"; | 10478 name = "copyin"; |
10508 t = OMP_CLAUSE_DECL (c); | 10479 t = OMP_CLAUSE_DECL (c); |
10509 if (TREE_CODE (t) != VAR_DECL || !DECL_THREAD_LOCAL_P (t)) | 10480 if (TREE_CODE (t) != VAR_DECL || !DECL_THREAD_LOCAL_P (t)) |
10510 { | 10481 { |
10511 error_at (OMP_CLAUSE_LOCATION (c), | 10482 error_at (OMP_CLAUSE_LOCATION (c), |
10512 "%qE must be %<threadprivate%> for %<copyin%>", t); | 10483 "%qE must be %<threadprivate%> for %<copyin%>", t); |
10513 remove = true; | 10484 remove = true; |
10514 } | 10485 } |
10515 goto check_dup_generic; | 10486 goto check_dup_generic; |
10516 | 10487 |
10517 check_dup_generic: | 10488 check_dup_generic: |
10518 t = OMP_CLAUSE_DECL (c); | 10489 t = OMP_CLAUSE_DECL (c); |
10519 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) | 10490 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) |
10520 { | 10491 { |
10521 error_at (OMP_CLAUSE_LOCATION (c), | 10492 error_at (OMP_CLAUSE_LOCATION (c), |
10522 "%qE is not a variable in clause %qs", t, name); | 10493 "%qE is not a variable in clause %qs", t, name); |
10523 remove = true; | 10494 remove = true; |
10524 } | 10495 } |
10525 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | 10496 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) |
10526 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) | 10497 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)) |
10527 || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) | 10498 || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) |
10528 { | 10499 { |
10529 error_at (OMP_CLAUSE_LOCATION (c), | 10500 error_at (OMP_CLAUSE_LOCATION (c), |
10530 "%qE appears more than once in data clauses", t); | 10501 "%qE appears more than once in data clauses", t); |
10531 remove = true; | 10502 remove = true; |
10532 } | 10503 } |
10504 else | |
10505 bitmap_set_bit (&generic_head, DECL_UID (t)); | |
10506 break; | |
10507 | |
10508 case OMP_CLAUSE_FIRSTPRIVATE: | |
10509 name = "firstprivate"; | |
10510 t = OMP_CLAUSE_DECL (c); | |
10511 need_complete = true; | |
10512 need_implicitly_determined = true; | |
10513 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) | |
10514 { | |
10515 error_at (OMP_CLAUSE_LOCATION (c), | |
10516 "%qE is not a variable in clause %<firstprivate%>", t); | |
10517 remove = true; | |
10518 } | |
10519 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
10520 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) | |
10521 { | |
10522 error_at (OMP_CLAUSE_LOCATION (c), | |
10523 "%qE appears more than once in data clauses", t); | |
10524 remove = true; | |
10525 } | |
10526 else | |
10527 bitmap_set_bit (&firstprivate_head, DECL_UID (t)); | |
10528 break; | |
10529 | |
10530 case OMP_CLAUSE_LASTPRIVATE: | |
10531 name = "lastprivate"; | |
10532 t = OMP_CLAUSE_DECL (c); | |
10533 need_complete = true; | |
10534 need_implicitly_determined = true; | |
10535 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) | |
10536 { | |
10537 error_at (OMP_CLAUSE_LOCATION (c), | |
10538 "%qE is not a variable in clause %<lastprivate%>", t); | |
10539 remove = true; | |
10540 } | |
10541 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
10542 || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) | |
10543 { | |
10544 error_at (OMP_CLAUSE_LOCATION (c), | |
10545 "%qE appears more than once in data clauses", t); | |
10546 remove = true; | |
10547 } | |
10548 else | |
10549 bitmap_set_bit (&lastprivate_head, DECL_UID (t)); | |
10550 break; | |
10551 | |
10552 case OMP_CLAUSE_IF: | |
10553 case OMP_CLAUSE_NUM_THREADS: | |
10554 case OMP_CLAUSE_SCHEDULE: | |
10555 case OMP_CLAUSE_NOWAIT: | |
10556 case OMP_CLAUSE_ORDERED: | |
10557 case OMP_CLAUSE_DEFAULT: | |
10558 case OMP_CLAUSE_UNTIED: | |
10559 case OMP_CLAUSE_COLLAPSE: | |
10560 pc = &OMP_CLAUSE_CHAIN (c); | |
10561 continue; | |
10562 | |
10563 default: | |
10564 gcc_unreachable (); | |
10565 } | |
10566 | |
10567 if (!remove) | |
10568 { | |
10569 t = OMP_CLAUSE_DECL (c); | |
10570 | |
10571 if (need_complete) | |
10572 { | |
10573 t = require_complete_type (t); | |
10574 if (t == error_mark_node) | |
10575 remove = true; | |
10576 } | |
10577 | |
10578 if (need_implicitly_determined) | |
10579 { | |
10580 const char *share_name = NULL; | |
10581 | |
10582 if (TREE_CODE (t) == VAR_DECL && DECL_THREAD_LOCAL_P (t)) | |
10583 share_name = "threadprivate"; | |
10584 else switch (c_omp_predetermined_sharing (t)) | |
10585 { | |
10586 case OMP_CLAUSE_DEFAULT_UNSPECIFIED: | |
10587 break; | |
10588 case OMP_CLAUSE_DEFAULT_SHARED: | |
10589 share_name = "shared"; | |
10590 break; | |
10591 case OMP_CLAUSE_DEFAULT_PRIVATE: | |
10592 share_name = "private"; | |
10593 break; | |
10594 default: | |
10595 gcc_unreachable (); | |
10596 } | |
10597 if (share_name) | |
10598 { | |
10599 error_at (OMP_CLAUSE_LOCATION (c), | |
10600 "%qE is predetermined %qs for %qs", | |
10601 t, share_name, name); | |
10602 remove = true; | |
10603 } | |
10604 } | |
10605 } | |
10606 | |
10607 if (remove) | |
10608 *pc = OMP_CLAUSE_CHAIN (c); | |
10533 else | 10609 else |
10534 bitmap_set_bit (&generic_head, DECL_UID (t)); | 10610 pc = &OMP_CLAUSE_CHAIN (c); |
10535 break; | |
10536 | |
10537 case OMP_CLAUSE_FIRSTPRIVATE: | |
10538 name = "firstprivate"; | |
10539 t = OMP_CLAUSE_DECL (c); | |
10540 need_complete = true; | |
10541 need_implicitly_determined = true; | |
10542 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) | |
10543 { | |
10544 error_at (OMP_CLAUSE_LOCATION (c), | |
10545 "%qE is not a variable in clause %<firstprivate%>", t); | |
10546 remove = true; | |
10547 } | |
10548 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
10549 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))) | |
10550 { | |
10551 error_at (OMP_CLAUSE_LOCATION (c), | |
10552 "%qE appears more than once in data clauses", t); | |
10553 remove = true; | |
10554 } | |
10555 else | |
10556 bitmap_set_bit (&firstprivate_head, DECL_UID (t)); | |
10557 break; | |
10558 | |
10559 case OMP_CLAUSE_LASTPRIVATE: | |
10560 name = "lastprivate"; | |
10561 t = OMP_CLAUSE_DECL (c); | |
10562 need_complete = true; | |
10563 need_implicitly_determined = true; | |
10564 if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) | |
10565 { | |
10566 error_at (OMP_CLAUSE_LOCATION (c), | |
10567 "%qE is not a variable in clause %<lastprivate%>", t); | |
10568 remove = true; | |
10569 } | |
10570 else if (bitmap_bit_p (&generic_head, DECL_UID (t)) | |
10571 || bitmap_bit_p (&lastprivate_head, DECL_UID (t))) | |
10572 { | |
10573 error_at (OMP_CLAUSE_LOCATION (c), | |
10574 "%qE appears more than once in data clauses", t); | |
10575 remove = true; | |
10576 } | |
10577 else | |
10578 bitmap_set_bit (&lastprivate_head, DECL_UID (t)); | |
10579 break; | |
10580 | |
10581 case OMP_CLAUSE_IF: | |
10582 case OMP_CLAUSE_NUM_THREADS: | |
10583 case OMP_CLAUSE_SCHEDULE: | |
10584 case OMP_CLAUSE_NOWAIT: | |
10585 case OMP_CLAUSE_ORDERED: | |
10586 case OMP_CLAUSE_DEFAULT: | |
10587 case OMP_CLAUSE_UNTIED: | |
10588 case OMP_CLAUSE_COLLAPSE: | |
10589 pc = &OMP_CLAUSE_CHAIN (c); | |
10590 continue; | |
10591 | |
10592 default: | |
10593 gcc_unreachable (); | |
10594 } | |
10595 | |
10596 if (!remove) | |
10597 { | |
10598 t = OMP_CLAUSE_DECL (c); | |
10599 | |
10600 if (need_complete) | |
10601 { | |
10602 t = require_complete_type (t); | |
10603 if (t == error_mark_node) | |
10604 remove = true; | |
10605 } | |
10606 | |
10607 if (need_implicitly_determined) | |
10608 { | |
10609 const char *share_name = NULL; | |
10610 | |
10611 if (TREE_CODE (t) == VAR_DECL && DECL_THREAD_LOCAL_P (t)) | |
10612 share_name = "threadprivate"; | |
10613 else switch (c_omp_predetermined_sharing (t)) | |
10614 { | |
10615 case OMP_CLAUSE_DEFAULT_UNSPECIFIED: | |
10616 break; | |
10617 case OMP_CLAUSE_DEFAULT_SHARED: | |
10618 share_name = "shared"; | |
10619 break; | |
10620 case OMP_CLAUSE_DEFAULT_PRIVATE: | |
10621 share_name = "private"; | |
10622 break; | |
10623 default: | |
10624 gcc_unreachable (); | |
10625 } | |
10626 if (share_name) | |
10627 { | |
10628 error_at (OMP_CLAUSE_LOCATION (c), | |
10629 "%qE is predetermined %qs for %qs", | |
10630 t, share_name, name); | |
10631 remove = true; | |
10632 } | |
10633 } | |
10634 } | |
10635 | |
10636 if (remove) | |
10637 *pc = OMP_CLAUSE_CHAIN (c); | |
10638 else | |
10639 pc = &OMP_CLAUSE_CHAIN (c); | |
10640 } | 10611 } |
10641 | 10612 |
10642 bitmap_obstack_release (NULL); | 10613 bitmap_obstack_release (NULL); |
10643 return clauses; | 10614 return clauses; |
10644 } | 10615 } |
10654 | 10625 |
10655 if (TREE_CODE (type) == ARRAY_TYPE) | 10626 if (TREE_CODE (type) == ARRAY_TYPE) |
10656 { | 10627 { |
10657 tree t; | 10628 tree t; |
10658 tree element_type = c_build_qualified_type (TREE_TYPE (type), | 10629 tree element_type = c_build_qualified_type (TREE_TYPE (type), |
10659 type_quals); | 10630 type_quals); |
10660 | 10631 |
10661 /* See if we already have an identically qualified type. */ | 10632 /* See if we already have an identically qualified type. */ |
10662 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) | 10633 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) |
10663 { | 10634 { |
10664 if (TYPE_QUALS (strip_array_types (t)) == type_quals | 10635 if (TYPE_QUALS (strip_array_types (t)) == type_quals |
10665 && TYPE_NAME (t) == TYPE_NAME (type) | 10636 && TYPE_NAME (t) == TYPE_NAME (type) |
10666 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type) | 10637 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type) |
10667 && attribute_list_equal (TYPE_ATTRIBUTES (t), | 10638 && attribute_list_equal (TYPE_ATTRIBUTES (t), |
10668 TYPE_ATTRIBUTES (type))) | 10639 TYPE_ATTRIBUTES (type))) |
10669 break; | 10640 break; |
10670 } | 10641 } |
10671 if (!t) | 10642 if (!t) |
10672 { | 10643 { |
10673 tree domain = TYPE_DOMAIN (type); | 10644 tree domain = TYPE_DOMAIN (type); |
10674 | 10645 |
10675 t = build_variant_type_copy (type); | 10646 t = build_variant_type_copy (type); |
10676 TREE_TYPE (t) = element_type; | 10647 TREE_TYPE (t) = element_type; |
10677 | 10648 |
10678 if (TYPE_STRUCTURAL_EQUALITY_P (element_type) | 10649 if (TYPE_STRUCTURAL_EQUALITY_P (element_type) |
10679 || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain))) | 10650 || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain))) |
10680 SET_TYPE_STRUCTURAL_EQUALITY (t); | 10651 SET_TYPE_STRUCTURAL_EQUALITY (t); |
10681 else if (TYPE_CANONICAL (element_type) != element_type | 10652 else if (TYPE_CANONICAL (element_type) != element_type |
10688 TYPE_CANONICAL (t) | 10659 TYPE_CANONICAL (t) |
10689 = c_build_qualified_type (unqualified_canon, type_quals); | 10660 = c_build_qualified_type (unqualified_canon, type_quals); |
10690 } | 10661 } |
10691 else | 10662 else |
10692 TYPE_CANONICAL (t) = t; | 10663 TYPE_CANONICAL (t) = t; |
10693 } | 10664 } |
10694 return t; | 10665 return t; |
10695 } | 10666 } |
10696 | 10667 |
10697 /* A restrict-qualified pointer type must be a pointer to object or | 10668 /* A restrict-qualified pointer type must be a pointer to object or |
10698 incomplete type. Note that the use of POINTER_TYPE_P also allows | 10669 incomplete type. Note that the use of POINTER_TYPE_P also allows |
10699 REFERENCE_TYPEs, which is appropriate for C++. */ | 10670 REFERENCE_TYPEs, which is appropriate for C++. */ |
10700 if ((type_quals & TYPE_QUAL_RESTRICT) | 10671 if ((type_quals & TYPE_QUAL_RESTRICT) |
10701 && (!POINTER_TYPE_P (type) | 10672 && (!POINTER_TYPE_P (type) |
10702 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type)))) | 10673 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type)))) |
10703 { | 10674 { |
10704 error ("invalid use of %<restrict%>"); | 10675 error ("invalid use of %<restrict%>"); |
10705 type_quals &= ~TYPE_QUAL_RESTRICT; | 10676 type_quals &= ~TYPE_QUAL_RESTRICT; |
10706 } | 10677 } |
10707 | 10678 |
10713 tree | 10684 tree |
10714 c_build_va_arg (location_t loc, tree expr, tree type) | 10685 c_build_va_arg (location_t loc, tree expr, tree type) |
10715 { | 10686 { |
10716 if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE) | 10687 if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE) |
10717 warning_at (loc, OPT_Wc___compat, | 10688 warning_at (loc, OPT_Wc___compat, |
10718 "C++ requires promoted type, not enum type, in %<va_arg%>"); | 10689 "C++ requires promoted type, not enum type, in %<va_arg%>"); |
10719 return build_va_arg (loc, expr, type); | 10690 return build_va_arg (loc, expr, type); |
10720 } | 10691 } |