Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-typeck.c @ 69:1b10fe6932e1
merge 69
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 21 Aug 2011 07:53:12 +0900 |
parents | 326d9e06c2e3 f6334be47118 |
children | b81903832de2 |
comparison
equal
deleted
inserted
replaced
66:b362627d71ba | 69:1b10fe6932e1 |
---|---|
1 /* Build expressions with type checking for C compiler. | 1 /* Build expressions with type checking for C compiler. |
2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | 2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 | 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
4 Free Software Foundation, Inc. | 4 Free Software Foundation, Inc. |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
8 GCC is free software; you can redistribute it and/or modify it under | 8 GCC is free software; you can redistribute it and/or modify it under |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "system.h" | 29 #include "system.h" |
30 #include "coretypes.h" | 30 #include "coretypes.h" |
31 #include "tm.h" | 31 #include "tm.h" |
32 #include "rtl.h" | |
33 #include "tree.h" | 32 #include "tree.h" |
34 #include "langhooks.h" | 33 #include "langhooks.h" |
35 #include "c-tree.h" | 34 #include "c-tree.h" |
36 #include "c-lang.h" | 35 #include "c-lang.h" |
37 #include "tm_p.h" | |
38 #include "flags.h" | 36 #include "flags.h" |
39 #include "output.h" | 37 #include "output.h" |
40 #include "expr.h" | |
41 #include "toplev.h" | |
42 #include "intl.h" | 38 #include "intl.h" |
43 #include "ggc.h" | |
44 #include "target.h" | 39 #include "target.h" |
45 #include "tree-iterator.h" | 40 #include "tree-iterator.h" |
41 #include "bitmap.h" | |
46 #include "gimple.h" | 42 #include "gimple.h" |
47 #include "tree-flow.h" | 43 #include "tree-flow.h" |
48 #ifndef noCbC | 44 #ifndef noCbC |
49 #include "cbc-tree.h" | 45 #include "cbc-tree.h" |
50 #endif | 46 #endif |
47 #include "c-family/c-objc.h" | |
51 | 48 |
52 /* Possible cases of implicit bad conversions. Used to select | 49 /* Possible cases of implicit bad conversions. Used to select |
53 diagnostic messages in convert_for_assignment. */ | 50 diagnostic messages in convert_for_assignment. */ |
54 enum impl_conv { | 51 enum impl_conv { |
55 ic_argpass, | 52 ic_argpass, |
56 ic_assign, | 53 ic_assign, |
57 ic_init, | 54 ic_init, |
58 ic_return | 55 ic_return |
59 }; | 56 }; |
60 | 57 |
61 /* Whether we are building a boolean conversion inside | |
62 convert_for_assignment, or some other late binary operation. If | |
63 build_binary_op is called (from code shared with C++) in this case, | |
64 then the operands have already been folded and the result will not | |
65 be folded again, so C_MAYBE_CONST_EXPR should not be generated. */ | |
66 bool in_late_binary_op; | |
67 | |
68 /* The level of nesting inside "__alignof__". */ | 58 /* The level of nesting inside "__alignof__". */ |
69 int in_alignof; | 59 int in_alignof; |
70 | 60 |
71 /* The level of nesting inside "sizeof". */ | 61 /* The level of nesting inside "sizeof". */ |
72 int in_sizeof; | 62 int in_sizeof; |
81 static int require_constant_value; | 71 static int require_constant_value; |
82 static int require_constant_elements; | 72 static int require_constant_elements; |
83 | 73 |
84 static bool null_pointer_constant_p (const_tree); | 74 static bool null_pointer_constant_p (const_tree); |
85 static tree qualify_type (tree, tree); | 75 static tree qualify_type (tree, tree); |
86 static int tagged_types_tu_compatible_p (const_tree, const_tree, bool *); | 76 static int tagged_types_tu_compatible_p (const_tree, const_tree, bool *, |
77 bool *); | |
87 static int comp_target_types (location_t, tree, tree); | 78 static int comp_target_types (location_t, tree, tree); |
88 static int function_types_compatible_p (const_tree, const_tree, bool *); | 79 static int function_types_compatible_p (const_tree, const_tree, bool *, |
89 static int type_lists_compatible_p (const_tree, const_tree, bool *); | 80 bool *); |
81 static int type_lists_compatible_p (const_tree, const_tree, bool *, bool *); | |
90 static tree lookup_field (tree, tree); | 82 static tree lookup_field (tree, tree); |
91 static int convert_arguments (tree, VEC(tree,gc) *, VEC(tree,gc) *, tree, | 83 static int convert_arguments (tree, VEC(tree,gc) *, VEC(tree,gc) *, tree, |
92 tree); | 84 tree); |
93 static tree pointer_diff (location_t, tree, tree); | 85 static tree pointer_diff (location_t, tree, tree); |
94 static tree convert_for_assignment (location_t, tree, tree, tree, | 86 static tree convert_for_assignment (location_t, tree, tree, tree, |
98 static void push_member_name (tree); | 90 static void push_member_name (tree); |
99 static int spelling_length (void); | 91 static int spelling_length (void); |
100 static char *print_spelling (char *); | 92 static char *print_spelling (char *); |
101 static void warning_init (int, const char *); | 93 static void warning_init (int, const char *); |
102 static tree digest_init (location_t, tree, tree, tree, bool, bool, int); | 94 static tree digest_init (location_t, tree, tree, tree, bool, bool, int); |
103 static void output_init_element (tree, tree, bool, tree, tree, int, bool); | 95 static void output_init_element (tree, tree, bool, tree, tree, int, bool, |
104 static void output_pending_init_elements (int); | 96 struct obstack *); |
105 static int set_designator (int); | 97 static void output_pending_init_elements (int, struct obstack *); |
106 static void push_range_stack (tree); | 98 static int set_designator (int, struct obstack *); |
107 static void add_pending_init (tree, tree, tree, bool); | 99 static void push_range_stack (tree, struct obstack *); |
108 static void set_nonincremental_init (void); | 100 static void add_pending_init (tree, tree, tree, bool, struct obstack *); |
109 static void set_nonincremental_init_from_string (tree); | 101 static void set_nonincremental_init (struct obstack *); |
110 static tree find_init_member (tree); | 102 static void set_nonincremental_init_from_string (tree, struct obstack *); |
111 static void readonly_error (tree, enum lvalue_use); | 103 static tree find_init_member (tree, struct obstack *); |
112 static void readonly_warning (tree, enum lvalue_use); | 104 static void readonly_warning (tree, enum lvalue_use); |
113 static int lvalue_or_else (const_tree, enum lvalue_use); | 105 static int lvalue_or_else (location_t, const_tree, enum lvalue_use); |
114 static void record_maybe_used_decl (tree); | 106 static void record_maybe_used_decl (tree); |
115 static int comptypes_internal (const_tree, const_tree, bool *); | 107 static int comptypes_internal (const_tree, const_tree, bool *, bool *); |
116 | 108 |
117 /* Return true if EXP is a null pointer constant, false otherwise. */ | 109 /* Return true if EXP is a null pointer constant, false otherwise. */ |
118 | 110 |
119 static bool | 111 static bool |
120 null_pointer_constant_p (const_tree expr) | 112 null_pointer_constant_p (const_tree expr) |
491 If both do, merge the arg types. Also merge the return types. */ | 483 If both do, merge the arg types. Also merge the return types. */ |
492 { | 484 { |
493 #ifndef noCbC | 485 #ifndef noCbC |
494 int is_code_segment = CbC_IS_CODE_SEGMENT(t1); | 486 int is_code_segment = CbC_IS_CODE_SEGMENT(t1); |
495 #endif | 487 #endif |
496 tree valtype = composite_type (TREE_TYPE (t1), TREE_TYPE (t2)); | 488 tree valtype = composite_type (TREE_TYPE (t1), TREE_TYPE (t2)); |
497 tree p1 = TYPE_ARG_TYPES (t1); | 489 tree p1 = TYPE_ARG_TYPES (t1); |
498 tree p2 = TYPE_ARG_TYPES (t2); | 490 tree p2 = TYPE_ARG_TYPES (t2); |
499 int len; | 491 int len; |
500 tree newargs, n; | 492 tree newargs, n; |
501 int i; | 493 int i; |
502 | 494 |
503 /* Save space: see if the result is identical to one of the args. */ | 495 /* Save space: see if the result is identical to one of the args. */ |
504 if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2)) | 496 if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2)) |
505 return build_type_attribute_variant (t1, attributes); | 497 return build_type_attribute_variant (t1, attributes); |
506 if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1)) | 498 if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1)) |
507 return build_type_attribute_variant (t2, attributes); | 499 return build_type_attribute_variant (t2, attributes); |
508 | 500 |
509 /* Simple way if one arg fails to specify argument types. */ | 501 /* Simple way if one arg fails to specify argument types. */ |
510 if (TYPE_ARG_TYPES (t1) == 0) | 502 if (TYPE_ARG_TYPES (t1) == 0) |
511 { | 503 { |
512 #ifndef noCbC | 504 #ifndef noCbC |
513 if (is_code_segment) t1 = build_code_segment_type (valtype, TYPE_ARG_TYPES (t2)); | 505 if (is_code_segment) t1 = build_code_segment_type (valtype, TYPE_ARG_TYPES (t2)); |
514 else | 506 else |
515 #endif | 507 #endif |
516 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2)); | 508 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2)); |
517 t1 = build_type_attribute_variant (t1, attributes); | 509 t1 = build_type_attribute_variant (t1, attributes); |
518 return qualify_type (t1, t2); | 510 return qualify_type (t1, t2); |
519 } | 511 } |
520 if (TYPE_ARG_TYPES (t2) == 0) | 512 if (TYPE_ARG_TYPES (t2) == 0) |
521 { | 513 { |
522 #ifndef noCbC | 514 #ifndef noCbC |
523 if (is_code_segment) t1 = build_code_segment_type (valtype, TYPE_ARG_TYPES (t1)); | 515 if (is_code_segment) t1 = build_code_segment_type (valtype, TYPE_ARG_TYPES (t1)); |
524 else | 516 else |
525 #endif | 517 #endif |
526 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1)); | 518 t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1)); |
527 t1 = build_type_attribute_variant (t1, attributes); | 519 t1 = build_type_attribute_variant (t1, attributes); |
528 return qualify_type (t1, t2); | 520 return qualify_type (t1, t2); |
529 } | 521 } |
530 | 522 |
531 /* If both args specify argument types, we must merge the two | 523 /* If both args specify argument types, we must merge the two |
532 lists, argument by argument. */ | 524 lists, argument by argument. */ |
533 /* Tell global_bindings_p to return false so that variable_size | 525 /* Tell global_bindings_p to return false so that variable_size |
534 doesn't die on VLAs in parameter types. */ | 526 doesn't die on VLAs in parameter types. */ |
535 c_override_global_bindings_to_false = true; | 527 c_override_global_bindings_to_false = true; |
536 | 528 |
537 len = list_length (p1); | 529 len = list_length (p1); |
538 newargs = 0; | 530 newargs = 0; |
539 | 531 |
540 for (i = 0; i < len; i++) | 532 for (i = 0; i < len; i++) |
541 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs); | 533 newargs = tree_cons (NULL_TREE, NULL_TREE, newargs); |
542 | 534 |
543 n = newargs; | 535 n = newargs; |
544 | 536 |
545 for (; p1; | 537 for (; p1; |
546 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n)) | 538 p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n)) |
547 { | 539 { |
548 /* A null type means arg type is not specified. | 540 /* A null type means arg type is not specified. |
549 Take whatever the other function type has. */ | 541 Take whatever the other function type has. */ |
550 if (TREE_VALUE (p1) == 0) | 542 if (TREE_VALUE (p1) == 0) |
551 { | 543 { |
552 TREE_VALUE (n) = TREE_VALUE (p2); | 544 TREE_VALUE (n) = TREE_VALUE (p2); |
553 goto parm_done; | 545 goto parm_done; |
554 } | 546 } |
555 if (TREE_VALUE (p2) == 0) | 547 if (TREE_VALUE (p2) == 0) |
556 { | 548 { |
557 TREE_VALUE (n) = TREE_VALUE (p1); | 549 TREE_VALUE (n) = TREE_VALUE (p1); |
558 goto parm_done; | 550 goto parm_done; |
559 } | 551 } |
560 | 552 |
561 /* Given wait (union {union wait *u; int *i} *) | 553 /* Given wait (union {union wait *u; int *i} *) |
562 and wait (union wait *), | 554 and wait (union wait *), |
563 prefer union wait * as type of parm. */ | 555 prefer union wait * as type of parm. */ |
564 if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE | 556 if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE |
565 && TREE_VALUE (p1) != TREE_VALUE (p2)) | 557 && TREE_VALUE (p1) != TREE_VALUE (p2)) |
566 { | 558 { |
567 tree memb; | 559 tree memb; |
568 tree mv2 = TREE_VALUE (p2); | 560 tree mv2 = TREE_VALUE (p2); |
569 if (mv2 && mv2 != error_mark_node | 561 if (mv2 && mv2 != error_mark_node |
570 && TREE_CODE (mv2) != ARRAY_TYPE) | 562 && TREE_CODE (mv2) != ARRAY_TYPE) |
571 mv2 = TYPE_MAIN_VARIANT (mv2); | 563 mv2 = TYPE_MAIN_VARIANT (mv2); |
572 for (memb = TYPE_FIELDS (TREE_VALUE (p1)); | 564 for (memb = TYPE_FIELDS (TREE_VALUE (p1)); |
573 memb; memb = TREE_CHAIN (memb)) | 565 memb; memb = DECL_CHAIN (memb)) |
574 { | 566 { |
575 tree mv3 = TREE_TYPE (memb); | 567 tree mv3 = TREE_TYPE (memb); |
576 if (mv3 && mv3 != error_mark_node | 568 if (mv3 && mv3 != error_mark_node |
577 && TREE_CODE (mv3) != ARRAY_TYPE) | 569 && TREE_CODE (mv3) != ARRAY_TYPE) |
578 mv3 = TYPE_MAIN_VARIANT (mv3); | 570 mv3 = TYPE_MAIN_VARIANT (mv3); |
579 if (comptypes (mv3, mv2)) | 571 if (comptypes (mv3, mv2)) |
580 { | 572 { |
581 TREE_VALUE (n) = composite_type (TREE_TYPE (memb), | 573 TREE_VALUE (n) = composite_type (TREE_TYPE (memb), |
582 TREE_VALUE (p2)); | 574 TREE_VALUE (p2)); |
583 pedwarn (input_location, OPT_pedantic, | 575 pedwarn (input_location, OPT_pedantic, |
584 "function types not truly compatible in ISO C"); | 576 "function types not truly compatible in ISO C"); |
585 goto parm_done; | 577 goto parm_done; |
586 } | 578 } |
587 } | 579 } |
588 } | 580 } |
589 if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE | 581 if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE |
590 && TREE_VALUE (p2) != TREE_VALUE (p1)) | 582 && TREE_VALUE (p2) != TREE_VALUE (p1)) |
591 { | 583 { |
592 tree memb; | 584 tree memb; |
593 tree mv1 = TREE_VALUE (p1); | 585 tree mv1 = TREE_VALUE (p1); |
594 if (mv1 && mv1 != error_mark_node | 586 if (mv1 && mv1 != error_mark_node |
595 && TREE_CODE (mv1) != ARRAY_TYPE) | 587 && TREE_CODE (mv1) != ARRAY_TYPE) |
596 mv1 = TYPE_MAIN_VARIANT (mv1); | 588 mv1 = TYPE_MAIN_VARIANT (mv1); |
597 for (memb = TYPE_FIELDS (TREE_VALUE (p2)); | 589 for (memb = TYPE_FIELDS (TREE_VALUE (p2)); |
598 memb; memb = TREE_CHAIN (memb)) | 590 memb; memb = DECL_CHAIN (memb)) |
599 { | 591 { |
600 tree mv3 = TREE_TYPE (memb); | 592 tree mv3 = TREE_TYPE (memb); |
601 if (mv3 && mv3 != error_mark_node | 593 if (mv3 && mv3 != error_mark_node |
602 && TREE_CODE (mv3) != ARRAY_TYPE) | 594 && TREE_CODE (mv3) != ARRAY_TYPE) |
603 mv3 = TYPE_MAIN_VARIANT (mv3); | 595 mv3 = TYPE_MAIN_VARIANT (mv3); |
604 if (comptypes (mv3, mv1)) | 596 if (comptypes (mv3, mv1)) |
605 { | 597 { |
606 TREE_VALUE (n) = composite_type (TREE_TYPE (memb), | 598 TREE_VALUE (n) = composite_type (TREE_TYPE (memb), |
607 TREE_VALUE (p1)); | 599 TREE_VALUE (p1)); |
608 pedwarn (input_location, OPT_pedantic, | 600 pedwarn (input_location, OPT_pedantic, |
609 "function types not truly compatible in ISO C"); | 601 "function types not truly compatible in ISO C"); |
610 goto parm_done; | 602 goto parm_done; |
611 } | 603 } |
612 } | 604 } |
613 } | 605 } |
614 TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2)); | 606 TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2)); |
615 parm_done: ; | 607 parm_done: ; |
616 } | 608 } |
617 | 609 |
618 c_override_global_bindings_to_false = false; | 610 c_override_global_bindings_to_false = false; |
619 | 611 |
620 #ifndef noCbC | 612 #ifndef noCbC |
621 if (is_code_segment) t1 = build_code_segment_type (valtype, newargs); | 613 if (is_code_segment) t1 = build_code_segment_type (valtype, newargs); |
622 else | 614 else |
623 #endif | 615 #endif |
624 t1 = build_function_type (valtype, newargs); | 616 t1 = build_function_type (valtype, newargs); |
625 t1 = qualify_type (t1, t2); | 617 t1 = qualify_type (t1, t2); |
626 /* ... falls through ... */ | 618 /* ... falls through ... */ |
627 } | 619 } |
628 | |
629 default: | 620 default: |
630 return build_type_attribute_variant (t1, attributes); | 621 return build_type_attribute_variant (t1, attributes); |
631 } | 622 } |
632 | 623 |
633 } | 624 } |
992 comptypes (tree type1, tree type2) | 983 comptypes (tree type1, tree type2) |
993 { | 984 { |
994 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base; | 985 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base; |
995 int val; | 986 int val; |
996 | 987 |
997 val = comptypes_internal (type1, type2, NULL); | 988 val = comptypes_internal (type1, type2, NULL, NULL); |
998 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1); | 989 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1); |
999 | 990 |
1000 return val; | 991 return val; |
1001 } | 992 } |
1002 | 993 |
1007 comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p) | 998 comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p) |
1008 { | 999 { |
1009 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base; | 1000 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base; |
1010 int val; | 1001 int val; |
1011 | 1002 |
1012 val = comptypes_internal (type1, type2, enum_and_int_p); | 1003 val = comptypes_internal (type1, type2, enum_and_int_p, NULL); |
1004 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1); | |
1005 | |
1006 return val; | |
1007 } | |
1008 | |
1009 /* Like comptypes, but if it returns nonzero for different types, it | |
1010 sets *DIFFERENT_TYPES_P to true. */ | |
1011 | |
1012 int | |
1013 comptypes_check_different_types (tree type1, tree type2, | |
1014 bool *different_types_p) | |
1015 { | |
1016 const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base; | |
1017 int val; | |
1018 | |
1019 val = comptypes_internal (type1, type2, NULL, different_types_p); | |
1013 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1); | 1020 free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1); |
1014 | 1021 |
1015 return val; | 1022 return val; |
1016 } | 1023 } |
1017 | 1024 |
1018 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment | 1025 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment |
1019 or various other operations. Return 2 if they are compatible | 1026 or various other operations. Return 2 if they are compatible |
1020 but a warning may be needed if you use them together. If | 1027 but a warning may be needed if you use them together. If |
1021 ENUM_AND_INT_P is not NULL, and one type is an enum and the other a | 1028 ENUM_AND_INT_P is not NULL, and one type is an enum and the other a |
1022 compatible integer type, then this sets *ENUM_AND_INT_P to true; | 1029 compatible integer type, then this sets *ENUM_AND_INT_P to true; |
1023 *ENUM_AND_INT_P is never set to false. This differs from | 1030 *ENUM_AND_INT_P is never set to false. If DIFFERENT_TYPES_P is not |
1024 comptypes, in that we don't free the seen types. */ | 1031 NULL, and the types are compatible but different enough not to be |
1032 permitted in C1X typedef redeclarations, then this sets | |
1033 *DIFFERENT_TYPES_P to true; *DIFFERENT_TYPES_P is never set to | |
1034 false, but may or may not be set if the types are incompatible. | |
1035 This differs from comptypes, in that we don't free the seen | |
1036 types. */ | |
1025 | 1037 |
1026 static int | 1038 static int |
1027 comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p) | 1039 comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p, |
1040 bool *different_types_p) | |
1028 { | 1041 { |
1029 const_tree t1 = type1; | 1042 const_tree t1 = type1; |
1030 const_tree t2 = type2; | 1043 const_tree t2 = type2; |
1031 int attrval, val; | 1044 int attrval, val; |
1032 | 1045 |
1034 | 1047 |
1035 if (t1 == t2 || !t1 || !t2 | 1048 if (t1 == t2 || !t1 || !t2 |
1036 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK) | 1049 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK) |
1037 return 1; | 1050 return 1; |
1038 | 1051 |
1039 /* If either type is the internal version of sizetype, return the | |
1040 language version. */ | |
1041 if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1) | |
1042 && TYPE_ORIG_SIZE_TYPE (t1)) | |
1043 t1 = TYPE_ORIG_SIZE_TYPE (t1); | |
1044 | |
1045 if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2) | |
1046 && TYPE_ORIG_SIZE_TYPE (t2)) | |
1047 t2 = TYPE_ORIG_SIZE_TYPE (t2); | |
1048 | |
1049 | |
1050 /* Enumerated types are compatible with integer types, but this is | 1052 /* Enumerated types are compatible with integer types, but this is |
1051 not transitive: two enumerated types in the same translation unit | 1053 not transitive: two enumerated types in the same translation unit |
1052 are compatible with each other only if they are the same type. */ | 1054 are compatible with each other only if they are the same type. */ |
1053 | 1055 |
1054 if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE) | 1056 if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE) |
1055 { | 1057 { |
1056 t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1)); | 1058 t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1)); |
1057 if (enum_and_int_p != NULL && TREE_CODE (t2) != VOID_TYPE) | 1059 if (TREE_CODE (t2) != VOID_TYPE) |
1058 *enum_and_int_p = true; | 1060 { |
1061 if (enum_and_int_p != NULL) | |
1062 *enum_and_int_p = true; | |
1063 if (different_types_p != NULL) | |
1064 *different_types_p = true; | |
1065 } | |
1059 } | 1066 } |
1060 else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE) | 1067 else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE) |
1061 { | 1068 { |
1062 t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2)); | 1069 t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2)); |
1063 if (enum_and_int_p != NULL && TREE_CODE (t1) != VOID_TYPE) | 1070 if (TREE_CODE (t1) != VOID_TYPE) |
1064 *enum_and_int_p = true; | 1071 { |
1072 if (enum_and_int_p != NULL) | |
1073 *enum_and_int_p = true; | |
1074 if (different_types_p != NULL) | |
1075 *different_types_p = true; | |
1076 } | |
1065 } | 1077 } |
1066 | 1078 |
1067 if (t1 == t2) | 1079 if (t1 == t2) |
1068 return 1; | 1080 return 1; |
1069 | 1081 |
1098 /* Do not remove mode or aliasing information. */ | 1110 /* Do not remove mode or aliasing information. */ |
1099 if (TYPE_MODE (t1) != TYPE_MODE (t2) | 1111 if (TYPE_MODE (t1) != TYPE_MODE (t2) |
1100 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) | 1112 || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)) |
1101 break; | 1113 break; |
1102 val = (TREE_TYPE (t1) == TREE_TYPE (t2) | 1114 val = (TREE_TYPE (t1) == TREE_TYPE (t2) |
1103 ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), | 1115 ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), |
1104 enum_and_int_p)); | 1116 enum_and_int_p, different_types_p)); |
1105 break; | 1117 break; |
1106 | 1118 |
1107 case FUNCTION_TYPE: | 1119 case FUNCTION_TYPE: |
1108 val = function_types_compatible_p (t1, t2, enum_and_int_p); | 1120 val = function_types_compatible_p (t1, t2, enum_and_int_p, |
1121 different_types_p); | |
1109 break; | 1122 break; |
1110 | 1123 |
1111 case ARRAY_TYPE: | 1124 case ARRAY_TYPE: |
1112 { | 1125 { |
1113 tree d1 = TYPE_DOMAIN (t1); | 1126 tree d1 = TYPE_DOMAIN (t1); |
1114 tree d2 = TYPE_DOMAIN (t2); | 1127 tree d2 = TYPE_DOMAIN (t2); |
1115 bool d1_variable, d2_variable; | 1128 bool d1_variable, d2_variable; |
1116 bool d1_zero, d2_zero; | 1129 bool d1_zero, d2_zero; |
1117 val = 1; | 1130 val = 1; |
1118 | 1131 |
1119 /* Target types must match incl. qualifiers. */ | 1132 /* Target types must match incl. qualifiers. */ |
1120 if (TREE_TYPE (t1) != TREE_TYPE (t2) | 1133 if (TREE_TYPE (t1) != TREE_TYPE (t2) |
1121 && 0 == (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), | 1134 && 0 == (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), |
1122 enum_and_int_p))) | 1135 enum_and_int_p, |
1123 return 0; | 1136 different_types_p))) |
1124 | 1137 return 0; |
1125 /* Sizes must match unless one is missing or variable. */ | 1138 |
1126 if (d1 == 0 || d2 == 0 || d1 == d2) | 1139 if (different_types_p != NULL |
1127 break; | 1140 && (d1 == 0) != (d2 == 0)) |
1128 | 1141 *different_types_p = true; |
1129 d1_zero = !TYPE_MAX_VALUE (d1); | 1142 /* Sizes must match unless one is missing or variable. */ |
1130 d2_zero = !TYPE_MAX_VALUE (d2); | 1143 if (d1 == 0 || d2 == 0 || d1 == d2) |
1131 | 1144 break; |
1132 d1_variable = (!d1_zero | 1145 |
1133 && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST | 1146 d1_zero = !TYPE_MAX_VALUE (d1); |
1134 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST)); | 1147 d2_zero = !TYPE_MAX_VALUE (d2); |
1135 d2_variable = (!d2_zero | 1148 |
1136 && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST | 1149 d1_variable = (!d1_zero |
1137 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)); | 1150 && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST |
1138 d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1)); | 1151 || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST)); |
1139 d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2)); | 1152 d2_variable = (!d2_zero |
1140 | 1153 && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST |
1141 if (d1_variable || d2_variable) | 1154 || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)); |
1142 break; | 1155 d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1)); |
1143 if (d1_zero && d2_zero) | 1156 d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2)); |
1144 break; | 1157 |
1145 if (d1_zero || d2_zero | 1158 if (different_types_p != NULL |
1146 || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)) | 1159 && d1_variable != d2_variable) |
1147 || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2))) | 1160 *different_types_p = true; |
1148 val = 0; | 1161 if (d1_variable || d2_variable) |
1149 | 1162 break; |
1150 break; | 1163 if (d1_zero && d2_zero) |
1164 break; | |
1165 if (d1_zero || d2_zero | |
1166 || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)) | |
1167 || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2))) | |
1168 val = 0; | |
1169 | |
1170 break; | |
1151 } | 1171 } |
1152 | 1172 |
1153 case ENUMERAL_TYPE: | 1173 case ENUMERAL_TYPE: |
1154 case RECORD_TYPE: | 1174 case RECORD_TYPE: |
1155 case UNION_TYPE: | 1175 case UNION_TYPE: |
1156 if (val != 1 && !same_translation_unit_p (t1, t2)) | 1176 if (val != 1 && !same_translation_unit_p (t1, t2)) |
1157 { | 1177 { |
1158 tree a1 = TYPE_ATTRIBUTES (t1); | 1178 tree a1 = TYPE_ATTRIBUTES (t1); |
1159 tree a2 = TYPE_ATTRIBUTES (t2); | 1179 tree a2 = TYPE_ATTRIBUTES (t2); |
1160 | 1180 |
1161 if (! attribute_list_contained (a1, a2) | 1181 if (! attribute_list_contained (a1, a2) |
1162 && ! attribute_list_contained (a2, a1)) | 1182 && ! attribute_list_contained (a2, a1)) |
1163 break; | 1183 break; |
1164 | 1184 |
1165 if (attrval != 2) | 1185 if (attrval != 2) |
1166 return tagged_types_tu_compatible_p (t1, t2, enum_and_int_p); | 1186 return tagged_types_tu_compatible_p (t1, t2, enum_and_int_p, |
1167 val = tagged_types_tu_compatible_p (t1, t2, enum_and_int_p); | 1187 different_types_p); |
1168 } | 1188 val = tagged_types_tu_compatible_p (t1, t2, enum_and_int_p, |
1189 different_types_p); | |
1190 } | |
1169 break; | 1191 break; |
1170 | 1192 |
1171 case VECTOR_TYPE: | 1193 case VECTOR_TYPE: |
1172 val = (TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2) | 1194 val = (TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2) |
1173 && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), | 1195 && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), |
1174 enum_and_int_p)); | 1196 enum_and_int_p, different_types_p)); |
1175 break; | 1197 break; |
1176 | 1198 |
1177 default: | 1199 default: |
1178 break; | 1200 break; |
1179 } | 1201 } |
1301 | 1323 |
1302 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are | 1324 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are |
1303 compatible. If the two types are not the same (which has been | 1325 compatible. If the two types are not the same (which has been |
1304 checked earlier), this can only happen when multiple translation | 1326 checked earlier), this can only happen when multiple translation |
1305 units are being compiled. See C99 6.2.7 paragraph 1 for the exact | 1327 units are being compiled. See C99 6.2.7 paragraph 1 for the exact |
1306 rules. ENUM_AND_INT_P is as in comptypes_internal. */ | 1328 rules. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in |
1329 comptypes_internal. */ | |
1307 | 1330 |
1308 static int | 1331 static int |
1309 tagged_types_tu_compatible_p (const_tree t1, const_tree t2, | 1332 tagged_types_tu_compatible_p (const_tree t1, const_tree t2, |
1310 bool *enum_and_int_p) | 1333 bool *enum_and_int_p, bool *different_types_p) |
1311 { | 1334 { |
1312 tree s1, s2; | 1335 tree s1, s2; |
1313 bool needs_warning = false; | 1336 bool needs_warning = false; |
1314 | 1337 |
1315 /* We have to verify that the tags of the types are the same. This | 1338 /* We have to verify that the tags of the types are the same. This |
1400 return 1; | 1423 return 1; |
1401 } | 1424 } |
1402 | 1425 |
1403 case UNION_TYPE: | 1426 case UNION_TYPE: |
1404 { | 1427 { |
1405 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); | 1428 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); |
1406 if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2))) | 1429 if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2))) |
1407 { | 1430 { |
1408 tu->val = 0; | 1431 tu->val = 0; |
1409 return 0; | 1432 return 0; |
1410 } | 1433 } |
1411 | 1434 |
1412 /* Speed up the common case where the fields are in the same order. */ | 1435 /* Speed up the common case where the fields are in the same order. */ |
1413 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); s1 && s2; | 1436 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); s1 && s2; |
1414 s1 = TREE_CHAIN (s1), s2 = TREE_CHAIN (s2)) | 1437 s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2)) |
1415 { | 1438 { |
1416 int result; | 1439 int result; |
1417 | 1440 |
1418 if (DECL_NAME (s1) != DECL_NAME (s2)) | 1441 if (DECL_NAME (s1) != DECL_NAME (s2)) |
1419 break; | 1442 break; |
1420 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), | 1443 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), |
1421 enum_and_int_p); | 1444 enum_and_int_p, different_types_p); |
1422 | 1445 |
1423 if (result != 1 && !DECL_NAME (s1)) | 1446 if (result != 1 && !DECL_NAME (s1)) |
1424 break; | 1447 break; |
1425 if (result == 0) | 1448 if (result == 0) |
1426 { | 1449 { |
1427 tu->val = 0; | 1450 tu->val = 0; |
1428 return 0; | 1451 return 0; |
1429 } | 1452 } |
1430 if (result == 2) | 1453 if (result == 2) |
1431 needs_warning = true; | 1454 needs_warning = true; |
1432 | 1455 |
1433 if (TREE_CODE (s1) == FIELD_DECL | 1456 if (TREE_CODE (s1) == FIELD_DECL |
1434 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), | 1457 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), |
1435 DECL_FIELD_BIT_OFFSET (s2)) != 1) | 1458 DECL_FIELD_BIT_OFFSET (s2)) != 1) |
1436 { | 1459 { |
1437 tu->val = 0; | 1460 tu->val = 0; |
1438 return 0; | 1461 return 0; |
1439 } | 1462 } |
1440 } | 1463 } |
1441 if (!s1 && !s2) | 1464 if (!s1 && !s2) |
1442 { | 1465 { |
1443 tu->val = needs_warning ? 2 : 1; | 1466 tu->val = needs_warning ? 2 : 1; |
1444 return tu->val; | 1467 return tu->val; |
1445 } | 1468 } |
1446 | 1469 |
1447 for (s1 = TYPE_FIELDS (t1); s1; s1 = TREE_CHAIN (s1)) | 1470 for (s1 = TYPE_FIELDS (t1); s1; s1 = DECL_CHAIN (s1)) |
1448 { | 1471 { |
1449 bool ok = false; | 1472 bool ok = false; |
1450 | 1473 |
1451 for (s2 = TYPE_FIELDS (t2); s2; s2 = TREE_CHAIN (s2)) | 1474 for (s2 = TYPE_FIELDS (t2); s2; s2 = DECL_CHAIN (s2)) |
1452 if (DECL_NAME (s1) == DECL_NAME (s2)) | 1475 if (DECL_NAME (s1) == DECL_NAME (s2)) |
1453 { | 1476 { |
1454 int result; | 1477 int result; |
1455 | 1478 |
1456 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), | 1479 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), |
1457 enum_and_int_p); | 1480 enum_and_int_p, |
1458 | 1481 different_types_p); |
1459 if (result != 1 && !DECL_NAME (s1)) | 1482 |
1460 continue; | 1483 if (result != 1 && !DECL_NAME (s1)) |
1461 if (result == 0) | 1484 continue; |
1462 { | 1485 if (result == 0) |
1463 tu->val = 0; | 1486 { |
1464 return 0; | 1487 tu->val = 0; |
1465 } | 1488 return 0; |
1466 if (result == 2) | 1489 } |
1467 needs_warning = true; | 1490 if (result == 2) |
1468 | 1491 needs_warning = true; |
1469 if (TREE_CODE (s1) == FIELD_DECL | 1492 |
1470 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), | 1493 if (TREE_CODE (s1) == FIELD_DECL |
1471 DECL_FIELD_BIT_OFFSET (s2)) != 1) | 1494 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), |
1472 break; | 1495 DECL_FIELD_BIT_OFFSET (s2)) != 1) |
1473 | 1496 break; |
1474 ok = true; | 1497 |
1475 break; | 1498 ok = true; |
1476 } | 1499 break; |
1477 if (!ok) | 1500 } |
1478 { | 1501 if (!ok) |
1479 tu->val = 0; | 1502 { |
1480 return 0; | 1503 tu->val = 0; |
1481 } | 1504 return 0; |
1482 } | 1505 } |
1483 tu->val = needs_warning ? 2 : 10; | 1506 } |
1484 return tu->val; | 1507 tu->val = needs_warning ? 2 : 10; |
1508 return tu->val; | |
1485 } | 1509 } |
1486 | 1510 |
1487 case RECORD_TYPE: | 1511 case RECORD_TYPE: |
1488 { | 1512 { |
1489 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); | 1513 struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2); |
1490 | 1514 |
1491 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); | 1515 for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); |
1492 s1 && s2; | 1516 s1 && s2; |
1493 s1 = TREE_CHAIN (s1), s2 = TREE_CHAIN (s2)) | 1517 s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2)) |
1494 { | 1518 { |
1495 int result; | 1519 int result; |
1496 if (TREE_CODE (s1) != TREE_CODE (s2) | 1520 if (TREE_CODE (s1) != TREE_CODE (s2) |
1497 || DECL_NAME (s1) != DECL_NAME (s2)) | 1521 || DECL_NAME (s1) != DECL_NAME (s2)) |
1498 break; | 1522 break; |
1499 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), | 1523 result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), |
1500 enum_and_int_p); | 1524 enum_and_int_p, different_types_p); |
1501 if (result == 0) | 1525 if (result == 0) |
1502 break; | 1526 break; |
1503 if (result == 2) | 1527 if (result == 2) |
1504 needs_warning = true; | 1528 needs_warning = true; |
1505 | 1529 if (TREE_CODE (s1) == FIELD_DECL |
1506 if (TREE_CODE (s1) == FIELD_DECL | 1530 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), |
1507 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1), | 1531 DECL_FIELD_BIT_OFFSET (s2)) != 1) |
1508 DECL_FIELD_BIT_OFFSET (s2)) != 1) | 1532 break; |
1509 break; | 1533 } |
1510 } | 1534 if (s1 && s2) |
1511 if (s1 && s2) | 1535 tu->val = 0; |
1512 tu->val = 0; | 1536 else |
1513 else | 1537 tu->val = needs_warning ? 2 : 1; |
1514 tu->val = needs_warning ? 2 : 1; | 1538 return tu->val; |
1515 return tu->val; | |
1516 } | 1539 } |
1517 | 1540 |
1518 default: | 1541 default: |
1519 gcc_unreachable (); | 1542 gcc_unreachable (); |
1520 } | 1543 } |
1524 If either type specifies no argument types, | 1547 If either type specifies no argument types, |
1525 the other must specify a fixed number of self-promoting arg types. | 1548 the other must specify a fixed number of self-promoting arg types. |
1526 Otherwise, if one type specifies only the number of arguments, | 1549 Otherwise, if one type specifies only the number of arguments, |
1527 the other must specify that number of self-promoting arg types. | 1550 the other must specify that number of self-promoting arg types. |
1528 Otherwise, the argument types must match. | 1551 Otherwise, the argument types must match. |
1529 ENUM_AND_INT_P is as in comptypes_internal. */ | 1552 ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in comptypes_internal. */ |
1530 | 1553 |
1531 static int | 1554 static int |
1532 function_types_compatible_p (const_tree f1, const_tree f2, | 1555 function_types_compatible_p (const_tree f1, const_tree f2, |
1533 bool *enum_and_int_p) | 1556 bool *enum_and_int_p, bool *different_types_p) |
1534 { | 1557 { |
1535 tree args1, args2; | 1558 tree args1, args2; |
1536 /* 1 if no need for warning yet, 2 if warning cause has been seen. */ | 1559 /* 1 if no need for warning yet, 2 if warning cause has been seen. */ |
1537 int val = 1; | 1560 int val = 1; |
1538 int val1; | 1561 int val1; |
1548 if (TYPE_VOLATILE (ret1)) | 1571 if (TYPE_VOLATILE (ret1)) |
1549 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1), | 1572 ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1), |
1550 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE); | 1573 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE); |
1551 if (TYPE_VOLATILE (ret2)) | 1574 if (TYPE_VOLATILE (ret2)) |
1552 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2), | 1575 ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2), |
1553 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE); | 1576 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE); |
1554 val = comptypes_internal (ret1, ret2, enum_and_int_p); | 1577 val = comptypes_internal (ret1, ret2, enum_and_int_p, different_types_p); |
1555 if (val == 0) | 1578 if (val == 0) |
1556 return 0; | 1579 return 0; |
1557 | 1580 |
1558 args1 = TYPE_ARG_TYPES (f1); | 1581 args1 = TYPE_ARG_TYPES (f1); |
1559 args2 = TYPE_ARG_TYPES (f2); | 1582 args2 = TYPE_ARG_TYPES (f2); |
1583 | |
1584 if (different_types_p != NULL | |
1585 && (args1 == 0) != (args2 == 0)) | |
1586 *different_types_p = true; | |
1560 | 1587 |
1561 /* An unspecified parmlist matches any specified parmlist | 1588 /* An unspecified parmlist matches any specified parmlist |
1562 whose argument types don't need default promotions. */ | 1589 whose argument types don't need default promotions. */ |
1563 | 1590 |
1564 if (args1 == 0) | 1591 if (args1 == 0) |
1567 return 0; | 1594 return 0; |
1568 /* If one of these types comes from a non-prototype fn definition, | 1595 /* If one of these types comes from a non-prototype fn definition, |
1569 compare that with the other type's arglist. | 1596 compare that with the other type's arglist. |
1570 If they don't match, ask for a warning (but no error). */ | 1597 If they don't match, ask for a warning (but no error). */ |
1571 if (TYPE_ACTUAL_ARG_TYPES (f1) | 1598 if (TYPE_ACTUAL_ARG_TYPES (f1) |
1572 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), | 1599 && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), |
1573 enum_and_int_p)) | 1600 enum_and_int_p, different_types_p)) |
1574 val = 2; | 1601 val = 2; |
1575 return val; | 1602 return val; |
1576 } | 1603 } |
1577 if (args2 == 0) | 1604 if (args2 == 0) |
1578 { | 1605 { |
1579 if (!self_promoting_args_p (args1)) | 1606 if (!self_promoting_args_p (args1)) |
1580 return 0; | 1607 return 0; |
1581 if (TYPE_ACTUAL_ARG_TYPES (f2) | 1608 if (TYPE_ACTUAL_ARG_TYPES (f2) |
1582 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), | 1609 && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), |
1583 enum_and_int_p)) | 1610 enum_and_int_p, different_types_p)) |
1584 val = 2; | 1611 val = 2; |
1585 return val; | 1612 return val; |
1586 } | 1613 } |
1587 | 1614 |
1588 /* Both types have argument lists: compare them and propagate results. */ | 1615 /* Both types have argument lists: compare them and propagate results. */ |
1589 val1 = type_lists_compatible_p (args1, args2, enum_and_int_p); | 1616 val1 = type_lists_compatible_p (args1, args2, enum_and_int_p, |
1617 different_types_p); | |
1590 return val1 != 1 ? val1 : val; | 1618 return val1 != 1 ? val1 : val; |
1591 } | 1619 } |
1592 | 1620 |
1593 /* Check two lists of types for compatibility, returning 0 for | 1621 /* Check two lists of types for compatibility, returning 0 for |
1594 incompatible, 1 for compatible, or 2 for compatible with | 1622 incompatible, 1 for compatible, or 2 for compatible with |
1595 warning. ENUM_AND_INT_P is as in comptypes_internal. */ | 1623 warning. ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in |
1624 comptypes_internal. */ | |
1596 | 1625 |
1597 static int | 1626 static int |
1598 type_lists_compatible_p (const_tree args1, const_tree args2, | 1627 type_lists_compatible_p (const_tree args1, const_tree args2, |
1599 bool *enum_and_int_p) | 1628 bool *enum_and_int_p, bool *different_types_p) |
1600 { | 1629 { |
1601 /* 1 if no need for warning yet, 2 if warning cause has been seen. */ | 1630 /* 1 if no need for warning yet, 2 if warning cause has been seen. */ |
1602 int val = 1; | 1631 int val = 1; |
1603 int newval = 0; | 1632 int newval = 0; |
1604 | 1633 |
1616 if (mv1 && mv1 != error_mark_node && TREE_CODE (mv1) != ARRAY_TYPE) | 1645 if (mv1 && mv1 != error_mark_node && TREE_CODE (mv1) != ARRAY_TYPE) |
1617 mv1 = TYPE_MAIN_VARIANT (mv1); | 1646 mv1 = TYPE_MAIN_VARIANT (mv1); |
1618 if (mv2 && mv2 != error_mark_node && TREE_CODE (mv2) != ARRAY_TYPE) | 1647 if (mv2 && mv2 != error_mark_node && TREE_CODE (mv2) != ARRAY_TYPE) |
1619 mv2 = TYPE_MAIN_VARIANT (mv2); | 1648 mv2 = TYPE_MAIN_VARIANT (mv2); |
1620 /* A null pointer instead of a type | 1649 /* A null pointer instead of a type |
1621 means there is supposed to be an argument | 1650 means there is supposed to be an argument |
1622 but nothing is specified about what type it has. | 1651 but nothing is specified about what type it has. |
1623 So match anything that self-promotes. */ | 1652 So match anything that self-promotes. */ |
1653 if (different_types_p != NULL | |
1654 && (a1 == 0) != (a2 == 0)) | |
1655 *different_types_p = true; | |
1624 if (a1 == 0) | 1656 if (a1 == 0) |
1625 { | 1657 { |
1626 if (c_type_promotes_to (a2) != a2) | 1658 if (c_type_promotes_to (a2) != a2) |
1627 return 0; | 1659 return 0; |
1628 } | 1660 } |
1631 if (c_type_promotes_to (a1) != a1) | 1663 if (c_type_promotes_to (a1) != a1) |
1632 return 0; | 1664 return 0; |
1633 } | 1665 } |
1634 /* If one of the lists has an error marker, ignore this arg. */ | 1666 /* If one of the lists has an error marker, ignore this arg. */ |
1635 else if (TREE_CODE (a1) == ERROR_MARK | 1667 else if (TREE_CODE (a1) == ERROR_MARK |
1636 || TREE_CODE (a2) == ERROR_MARK) | 1668 || TREE_CODE (a2) == ERROR_MARK) |
1637 ; | 1669 ; |
1638 else if (!(newval = comptypes_internal (mv1, mv2, enum_and_int_p))) | 1670 else if (!(newval = comptypes_internal (mv1, mv2, enum_and_int_p, |
1639 { | 1671 different_types_p))) |
1640 /* Allow wait (union {union wait *u; int *i} *) | 1672 { |
1641 and wait (union wait *) to be compatible. */ | 1673 if (different_types_p != NULL) |
1642 if (TREE_CODE (a1) == UNION_TYPE | 1674 *different_types_p = true; |
1643 && (TYPE_NAME (a1) == 0 | 1675 /* Allow wait (union {union wait *u; int *i} *) |
1644 || TYPE_TRANSPARENT_UNION (a1)) | 1676 and wait (union wait *) to be compatible. */ |
1645 && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST | 1677 if (TREE_CODE (a1) == UNION_TYPE |
1646 && tree_int_cst_equal (TYPE_SIZE (a1), | 1678 && (TYPE_NAME (a1) == 0 |
1647 TYPE_SIZE (a2))) | 1679 || TYPE_TRANSPARENT_AGGR (a1)) |
1648 { | 1680 && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST |
1649 tree memb; | 1681 && tree_int_cst_equal (TYPE_SIZE (a1), |
1650 for (memb = TYPE_FIELDS (a1); | 1682 TYPE_SIZE (a2))) |
1651 memb; memb = TREE_CHAIN (memb)) | 1683 { |
1652 { | 1684 tree memb; |
1653 tree mv3 = TREE_TYPE (memb); | 1685 for (memb = TYPE_FIELDS (a1); |
1654 if (mv3 && mv3 != error_mark_node | 1686 memb; memb = DECL_CHAIN (memb)) |
1655 && TREE_CODE (mv3) != ARRAY_TYPE) | 1687 { |
1656 mv3 = TYPE_MAIN_VARIANT (mv3); | 1688 tree mv3 = TREE_TYPE (memb); |
1657 if (comptypes_internal (mv3, mv2, enum_and_int_p)) | 1689 if (mv3 && mv3 != error_mark_node |
1658 break; | 1690 && TREE_CODE (mv3) != ARRAY_TYPE) |
1659 } | 1691 mv3 = TYPE_MAIN_VARIANT (mv3); |
1660 if (memb == 0) | 1692 if (comptypes_internal (mv3, mv2, enum_and_int_p, |
1661 return 0; | 1693 different_types_p)) |
1662 } | 1694 break; |
1663 else if (TREE_CODE (a2) == UNION_TYPE | 1695 } |
1664 && (TYPE_NAME (a2) == 0 | 1696 if (memb == 0) |
1665 || TYPE_TRANSPARENT_UNION (a2)) | 1697 return 0; |
1666 && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST | 1698 } |
1667 && tree_int_cst_equal (TYPE_SIZE (a2), | 1699 else if (TREE_CODE (a2) == UNION_TYPE |
1668 TYPE_SIZE (a1))) | 1700 && (TYPE_NAME (a2) == 0 |
1669 { | 1701 || TYPE_TRANSPARENT_AGGR (a2)) |
1670 tree memb; | 1702 && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST |
1671 for (memb = TYPE_FIELDS (a2); | 1703 && tree_int_cst_equal (TYPE_SIZE (a2), |
1672 memb; memb = TREE_CHAIN (memb)) | 1704 TYPE_SIZE (a1))) |
1673 { | 1705 { |
1674 tree mv3 = TREE_TYPE (memb); | 1706 tree memb; |
1675 if (mv3 && mv3 != error_mark_node | 1707 for (memb = TYPE_FIELDS (a2); |
1676 && TREE_CODE (mv3) != ARRAY_TYPE) | 1708 memb; memb = DECL_CHAIN (memb)) |
1677 mv3 = TYPE_MAIN_VARIANT (mv3); | 1709 { |
1678 if (comptypes_internal (mv3, mv1, enum_and_int_p)) | 1710 tree mv3 = TREE_TYPE (memb); |
1679 break; | 1711 if (mv3 && mv3 != error_mark_node |
1680 } | 1712 && TREE_CODE (mv3) != ARRAY_TYPE) |
1681 if (memb == 0) | 1713 mv3 = TYPE_MAIN_VARIANT (mv3); |
1682 return 0; | 1714 if (comptypes_internal (mv3, mv1, enum_and_int_p, |
1683 } | 1715 different_types_p)) |
1684 else | 1716 break; |
1685 return 0; | 1717 } |
1686 } | 1718 if (memb == 0) |
1719 return 0; | |
1720 } | |
1721 else | |
1722 return 0; | |
1723 } | |
1687 | 1724 |
1688 /* comptypes said ok, but record if it said to warn. */ | 1725 /* comptypes said ok, but record if it said to warn. */ |
1689 if (newval > val) | 1726 if (newval > val) |
1690 val = newval; | 1727 val = newval; |
1691 | 1728 |
1780 TREE_NO_WARNING (exp) = 1; | 1817 TREE_NO_WARNING (exp) = 1; |
1781 | 1818 |
1782 return build_unary_op (loc, ADDR_EXPR, exp, 0); | 1819 return build_unary_op (loc, ADDR_EXPR, exp, 0); |
1783 } | 1820 } |
1784 | 1821 |
1822 /* Mark EXP as read, not just set, for set but not used -Wunused | |
1823 warning purposes. */ | |
1824 | |
1825 void | |
1826 mark_exp_read (tree exp) | |
1827 { | |
1828 switch (TREE_CODE (exp)) | |
1829 { | |
1830 case VAR_DECL: | |
1831 case PARM_DECL: | |
1832 DECL_READ_P (exp) = 1; | |
1833 break; | |
1834 case ARRAY_REF: | |
1835 case COMPONENT_REF: | |
1836 case MODIFY_EXPR: | |
1837 case REALPART_EXPR: | |
1838 case IMAGPART_EXPR: | |
1839 CASE_CONVERT: | |
1840 case ADDR_EXPR: | |
1841 mark_exp_read (TREE_OPERAND (exp, 0)); | |
1842 break; | |
1843 case COMPOUND_EXPR: | |
1844 case C_MAYBE_CONST_EXPR: | |
1845 mark_exp_read (TREE_OPERAND (exp, 1)); | |
1846 break; | |
1847 default: | |
1848 break; | |
1849 } | |
1850 } | |
1851 | |
1785 /* Perform the default conversion of arrays and functions to pointers. | 1852 /* Perform the default conversion of arrays and functions to pointers. |
1786 Return the result of converting EXP. For any other expression, just | 1853 Return the result of converting EXP. For any other expression, just |
1787 return EXP. | 1854 return EXP. |
1788 | 1855 |
1789 LOC is the location of the expression. */ | 1856 LOC is the location of the expression. */ |
1835 } | 1902 } |
1836 | 1903 |
1837 return exp; | 1904 return exp; |
1838 } | 1905 } |
1839 | 1906 |
1907 struct c_expr | |
1908 default_function_array_read_conversion (location_t loc, struct c_expr exp) | |
1909 { | |
1910 mark_exp_read (exp.value); | |
1911 return default_function_array_conversion (loc, exp); | |
1912 } | |
1840 | 1913 |
1841 /* EXP is an expression of integer type. Apply the integer promotions | 1914 /* EXP is an expression of integer type. Apply the integer promotions |
1842 to it and return the promoted value. */ | 1915 to it and return the promoted value. */ |
1843 | 1916 |
1844 tree | 1917 tree |
1896 tree orig_exp; | 1969 tree orig_exp; |
1897 tree type = TREE_TYPE (exp); | 1970 tree type = TREE_TYPE (exp); |
1898 enum tree_code code = TREE_CODE (type); | 1971 enum tree_code code = TREE_CODE (type); |
1899 tree promoted_type; | 1972 tree promoted_type; |
1900 | 1973 |
1974 mark_exp_read (exp); | |
1975 | |
1901 /* Functions and arrays have been converted during parsing. */ | 1976 /* Functions and arrays have been converted during parsing. */ |
1902 gcc_assert (code != FUNCTION_TYPE); | 1977 gcc_assert (code != FUNCTION_TYPE); |
1903 if (code == ARRAY_TYPE) | 1978 if (code == ARRAY_TYPE) |
1904 return exp; | 1979 return exp; |
1905 | 1980 |
1932 return perform_integral_promotions (exp); | 2007 return perform_integral_promotions (exp); |
1933 | 2008 |
1934 return exp; | 2009 return exp; |
1935 } | 2010 } |
1936 | 2011 |
1937 /* Look up COMPONENT in a structure or union DECL. | 2012 /* Look up COMPONENT in a structure or union TYPE. |
1938 | 2013 |
1939 If the component name is not found, returns NULL_TREE. Otherwise, | 2014 If the component name is not found, returns NULL_TREE. Otherwise, |
1940 the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL | 2015 the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL |
1941 stepping down the chain to the component, which is in the last | 2016 stepping down the chain to the component, which is in the last |
1942 TREE_VALUE of the list. Normally the list is of length one, but if | 2017 TREE_VALUE of the list. Normally the list is of length one, but if |
1943 the component is embedded within (nested) anonymous structures or | 2018 the component is embedded within (nested) anonymous structures or |
1944 unions, the list steps down the chain to the component. */ | 2019 unions, the list steps down the chain to the component. */ |
1945 | 2020 |
1946 static tree | 2021 static tree |
1947 lookup_field (tree decl, tree component) | 2022 lookup_field (tree type, tree component) |
1948 { | 2023 { |
1949 tree type = TREE_TYPE (decl); | |
1950 tree field; | 2024 tree field; |
1951 | 2025 |
1952 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers | 2026 /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers |
1953 to the field elements. Use a binary search on this array to quickly | 2027 to the field elements. Use a binary search on this array to quickly |
1954 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC | 2028 find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC |
1961 | 2035 |
1962 field = TYPE_FIELDS (type); | 2036 field = TYPE_FIELDS (type); |
1963 bot = 0; | 2037 bot = 0; |
1964 top = TYPE_LANG_SPECIFIC (type)->s->len; | 2038 top = TYPE_LANG_SPECIFIC (type)->s->len; |
1965 while (top - bot > 1) | 2039 while (top - bot > 1) |
1966 { | 2040 { |
1967 half = (top - bot + 1) >> 1; | 2041 half = (top - bot + 1) >> 1; |
1968 field = field_array[bot+half]; | 2042 field = field_array[bot+half]; |
1969 | 2043 |
1970 if (DECL_NAME (field) == NULL_TREE) | 2044 if (DECL_NAME (field) == NULL_TREE) |
1971 { | 2045 { |
1972 /* Step through all anon unions in linear fashion. */ | 2046 /* Step through all anon unions in linear fashion. */ |
1973 while (DECL_NAME (field_array[bot]) == NULL_TREE) | 2047 while (DECL_NAME (field_array[bot]) == NULL_TREE) |
1974 { | 2048 { |
1975 field = field_array[bot++]; | 2049 field = field_array[bot++]; |
1976 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE | 2050 if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE |
1977 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) | 2051 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) |
1978 { | 2052 { |
1979 tree anon = lookup_field (field, component); | 2053 tree anon = lookup_field (TREE_TYPE (field), component); |
1980 | 2054 |
1981 if (anon) | 2055 if (anon) |
1982 return tree_cons (NULL_TREE, field, anon); | 2056 return tree_cons (NULL_TREE, field, anon); |
1983 } | 2057 |
1984 } | 2058 /* The Plan 9 compiler permits referring |
1985 | 2059 directly to an anonymous struct/union field |
1986 /* Entire record is only anon unions. */ | 2060 using a typedef name. */ |
1987 if (bot > top) | 2061 if (flag_plan9_extensions |
1988 return NULL_TREE; | 2062 && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE |
1989 | 2063 && (TREE_CODE (TYPE_NAME (TREE_TYPE (field))) |
1990 /* Restart the binary search, with new lower bound. */ | 2064 == TYPE_DECL) |
1991 continue; | 2065 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field))) |
1992 } | 2066 == component)) |
1993 | 2067 break; |
1994 if (DECL_NAME (field) == component) | 2068 } |
1995 break; | 2069 } |
1996 if (DECL_NAME (field) < component) | 2070 |
1997 bot += half; | 2071 /* Entire record is only anon unions. */ |
1998 else | 2072 if (bot > top) |
1999 top = bot + half; | 2073 return NULL_TREE; |
2000 } | 2074 |
2075 /* Restart the binary search, with new lower bound. */ | |
2076 continue; | |
2077 } | |
2078 | |
2079 if (DECL_NAME (field) == component) | |
2080 break; | |
2081 if (DECL_NAME (field) < component) | |
2082 bot += half; | |
2083 else | |
2084 top = bot + half; | |
2085 } | |
2001 | 2086 |
2002 if (DECL_NAME (field_array[bot]) == component) | 2087 if (DECL_NAME (field_array[bot]) == component) |
2003 field = field_array[bot]; | 2088 field = field_array[bot]; |
2004 else if (DECL_NAME (field) != component) | 2089 else if (DECL_NAME (field) != component) |
2005 return NULL_TREE; | 2090 return NULL_TREE; |
2006 } | 2091 } |
2007 else | 2092 else |
2008 { | 2093 { |
2009 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) | 2094 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
2010 { | 2095 { |
2011 if (DECL_NAME (field) == NULL_TREE | 2096 if (DECL_NAME (field) == NULL_TREE |
2012 && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE | 2097 && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE |
2013 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)) | 2098 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)) |
2014 { | 2099 { |
2015 tree anon = lookup_field (field, component); | 2100 tree anon = lookup_field (TREE_TYPE (field), component); |
2016 | 2101 |
2017 if (anon) | 2102 if (anon) |
2018 return tree_cons (NULL_TREE, field, anon); | 2103 return tree_cons (NULL_TREE, field, anon); |
2019 } | 2104 |
2020 | 2105 /* The Plan 9 compiler permits referring directly to an |
2021 if (DECL_NAME (field) == component) | 2106 anonymous struct/union field using a typedef |
2022 break; | 2107 name. */ |
2023 } | 2108 if (flag_plan9_extensions |
2109 && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE | |
2110 && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL | |
2111 && (DECL_NAME (TYPE_NAME (TREE_TYPE (field))) | |
2112 == component)) | |
2113 break; | |
2114 } | |
2115 | |
2116 if (DECL_NAME (field) == component) | |
2117 break; | |
2118 } | |
2024 | 2119 |
2025 if (field == NULL_TREE) | 2120 if (field == NULL_TREE) |
2026 return NULL_TREE; | 2121 return NULL_TREE; |
2027 } | 2122 } |
2028 | 2123 |
2043 bool datum_lvalue = lvalue_p (datum); | 2138 bool datum_lvalue = lvalue_p (datum); |
2044 | 2139 |
2045 if (!objc_is_public (datum, component)) | 2140 if (!objc_is_public (datum, component)) |
2046 return error_mark_node; | 2141 return error_mark_node; |
2047 | 2142 |
2143 /* Detect Objective-C property syntax object.property. */ | |
2144 if (c_dialect_objc () | |
2145 && (ref = objc_maybe_build_component_ref (datum, component))) | |
2146 return ref; | |
2147 | |
2048 /* See if there is a field or component with name COMPONENT. */ | 2148 /* See if there is a field or component with name COMPONENT. */ |
2049 | 2149 |
2050 if (code == RECORD_TYPE || code == UNION_TYPE) | 2150 if (code == RECORD_TYPE || code == UNION_TYPE) |
2051 { | 2151 { |
2052 if (!COMPLETE_TYPE_P (type)) | 2152 if (!COMPLETE_TYPE_P (type)) |
2053 { | 2153 { |
2054 c_incomplete_type_error (NULL_TREE, type); | 2154 c_incomplete_type_error (NULL_TREE, type); |
2055 return error_mark_node; | 2155 return error_mark_node; |
2056 } | 2156 } |
2057 | 2157 |
2058 field = lookup_field (datum, component); | 2158 field = lookup_field (type, component); |
2059 | 2159 |
2060 if (!field) | 2160 if (!field) |
2061 { | 2161 { |
2062 error_at (loc, "%qT has no member named %qE", type, component); | 2162 error_at (loc, "%qT has no member named %qE", type, component); |
2063 return error_mark_node; | 2163 return error_mark_node; |
2182 protected_set_expr_location (ref, loc); | 2282 protected_set_expr_location (ref, loc); |
2183 return ref; | 2283 return ref; |
2184 } | 2284 } |
2185 } | 2285 } |
2186 else if (TREE_CODE (pointer) != ERROR_MARK) | 2286 else if (TREE_CODE (pointer) != ERROR_MARK) |
2187 switch (errstring) | 2287 invalid_indirection_error (loc, type, errstring); |
2188 { | 2288 |
2189 case RO_ARRAY_INDEXING: | |
2190 error_at (loc, | |
2191 "invalid type argument of array indexing (have %qT)", | |
2192 type); | |
2193 break; | |
2194 case RO_UNARY_STAR: | |
2195 error_at (loc, | |
2196 "invalid type argument of unary %<*%> (have %qT)", | |
2197 type); | |
2198 break; | |
2199 case RO_ARROW: | |
2200 error_at (loc, | |
2201 "invalid type argument of %<->%> (have %qT)", | |
2202 type); | |
2203 break; | |
2204 default: | |
2205 gcc_unreachable (); | |
2206 } | |
2207 return error_mark_node; | 2289 return error_mark_node; |
2208 } | 2290 } |
2209 | 2291 |
2210 /* This handles expressions of the form "a[i]", which denotes | 2292 /* This handles expressions of the form "a[i]", which denotes |
2211 an array reference. | 2293 an array reference. |
2214 If A is a variable or a member, we generate a primitive ARRAY_REF. | 2296 If A is a variable or a member, we generate a primitive ARRAY_REF. |
2215 This avoids forcing the array out of registers, and can work on | 2297 This avoids forcing the array out of registers, and can work on |
2216 arrays that are not lvalues (for example, members of structures returned | 2298 arrays that are not lvalues (for example, members of structures returned |
2217 by functions). | 2299 by functions). |
2218 | 2300 |
2301 For vector types, allow vector[i] but not i[vector], and create | |
2302 *(((type*)&vectortype) + i) for the expression. | |
2303 | |
2219 LOC is the location to use for the returned expression. */ | 2304 LOC is the location to use for the returned expression. */ |
2220 | 2305 |
2221 tree | 2306 tree |
2222 build_array_ref (location_t loc, tree array, tree index) | 2307 build_array_ref (location_t loc, tree array, tree index) |
2223 { | 2308 { |
2226 if (TREE_TYPE (array) == error_mark_node | 2311 if (TREE_TYPE (array) == error_mark_node |
2227 || TREE_TYPE (index) == error_mark_node) | 2312 || TREE_TYPE (index) == error_mark_node) |
2228 return error_mark_node; | 2313 return error_mark_node; |
2229 | 2314 |
2230 if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE | 2315 if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE |
2231 && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE) | 2316 && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE |
2317 /* Allow vector[index] but not index[vector]. */ | |
2318 && TREE_CODE (TREE_TYPE (array)) != VECTOR_TYPE) | |
2232 { | 2319 { |
2233 tree temp; | 2320 tree temp; |
2234 if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE | 2321 if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE |
2235 && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE) | 2322 && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE) |
2236 { | 2323 { |
2237 error_at (loc, "subscripted value is neither array nor pointer"); | 2324 error_at (loc, |
2238 return error_mark_node; | 2325 "subscripted value is neither array nor pointer nor vector"); |
2239 } | 2326 |
2327 return error_mark_node; | |
2328 } | |
2240 temp = array; | 2329 temp = array; |
2241 array = index; | 2330 array = index; |
2242 index = temp; | 2331 index = temp; |
2243 swapped = true; | 2332 swapped = true; |
2244 } | 2333 } |
2262 | 2351 |
2263 /* Apply default promotions *after* noticing character types. */ | 2352 /* Apply default promotions *after* noticing character types. */ |
2264 index = default_conversion (index); | 2353 index = default_conversion (index); |
2265 | 2354 |
2266 gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE); | 2355 gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE); |
2356 | |
2357 /* For vector[index], convert the vector to a | |
2358 pointer of the underlying type. */ | |
2359 if (TREE_CODE (TREE_TYPE (array)) == VECTOR_TYPE) | |
2360 { | |
2361 tree type = TREE_TYPE (array); | |
2362 tree type1; | |
2363 | |
2364 if (TREE_CODE (index) == INTEGER_CST) | |
2365 if (!host_integerp (index, 1) | |
2366 || ((unsigned HOST_WIDE_INT) tree_low_cst (index, 1) | |
2367 >= TYPE_VECTOR_SUBPARTS (TREE_TYPE (array)))) | |
2368 warning_at (loc, OPT_Warray_bounds, "index value is out of bound"); | |
2369 | |
2370 c_common_mark_addressable_vec (array); | |
2371 type = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type)); | |
2372 type = build_pointer_type (type); | |
2373 type1 = build_pointer_type (TREE_TYPE (array)); | |
2374 array = build1 (ADDR_EXPR, type1, array); | |
2375 array = convert (type, array); | |
2376 } | |
2267 | 2377 |
2268 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE) | 2378 if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE) |
2269 { | 2379 { |
2270 tree rval, type; | 2380 tree rval, type; |
2271 | 2381 |
2697 pedwarn (loc, 0, | 2807 pedwarn (loc, 0, |
2698 "function with qualified void return type called"); | 2808 "function with qualified void return type called"); |
2699 return trap; | 2809 return trap; |
2700 } | 2810 } |
2701 else | 2811 else |
2702 { | 2812 { |
2703 tree rhs; | 2813 tree rhs; |
2704 | 2814 |
2705 if (AGGREGATE_TYPE_P (return_type)) | 2815 if (AGGREGATE_TYPE_P (return_type)) |
2706 rhs = build_compound_literal (loc, return_type, | 2816 rhs = build_compound_literal (loc, return_type, |
2707 build_constructor (return_type, 0), | 2817 build_constructor (return_type, 0), |
2708 false); | 2818 false); |
2709 else | 2819 else |
2710 rhs = fold_convert_loc (loc, return_type, integer_zero_node); | 2820 rhs = build_zero_cst (return_type); |
2711 | 2821 |
2712 return require_complete_type (build2 (COMPOUND_EXPR, return_type, | 2822 return require_complete_type (build2 (COMPOUND_EXPR, return_type, |
2713 trap, rhs)); | 2823 trap, rhs)); |
2714 } | 2824 } |
2715 } | 2825 } |
2716 | 2826 |
2717 argarray = VEC_address (tree, params); | 2827 argarray = VEC_address (tree, params); |
2718 | 2828 |
2719 /* Check that arguments to builtin functions match the expectations. */ | 2829 /* Check that arguments to builtin functions match the expectations. */ |
2834 bool excess_precision = false; | 2944 bool excess_precision = false; |
2835 bool npc; | 2945 bool npc; |
2836 tree parmval; | 2946 tree parmval; |
2837 | 2947 |
2838 if (type == void_type_node) | 2948 if (type == void_type_node) |
2839 { | 2949 { |
2840 error ("too many arguments to function %qE", function); | 2950 if (selector) |
2841 return parmnum; | 2951 error_at (input_location, |
2842 } | 2952 "too many arguments to method %qE", selector); |
2953 else | |
2954 error_at (input_location, | |
2955 "too many arguments to function %qE", function); | |
2956 | |
2957 if (fundecl && !DECL_BUILT_IN (fundecl)) | |
2958 inform (DECL_SOURCE_LOCATION (fundecl), "declared here"); | |
2959 return parmnum; | |
2960 } | |
2843 | 2961 |
2844 if (selector && argnum > 2) | 2962 if (selector && argnum > 2) |
2845 { | 2963 { |
2846 rname = selector; | 2964 rname = selector; |
2847 argnum -= 2; | 2965 argnum -= 2; |
3023 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) | 3141 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) |
3024 parmval = default_conversion (parmval); | 3142 parmval = default_conversion (parmval); |
3025 } | 3143 } |
3026 } | 3144 } |
3027 else if (TREE_CODE (valtype) == REAL_TYPE | 3145 else if (TREE_CODE (valtype) == REAL_TYPE |
3028 && (TYPE_PRECISION (valtype) | 3146 && (TYPE_PRECISION (valtype) |
3029 < TYPE_PRECISION (double_type_node)) | 3147 < TYPE_PRECISION (double_type_node)) |
3030 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype))) | 3148 && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype))) |
3031 { | 3149 { |
3032 if (type_generic) | 3150 if (type_generic) |
3033 parmval = val; | 3151 parmval = val; |
3034 else | 3152 else |
3035 /* Convert `float' to `double'. */ | 3153 { |
3036 parmval = convert (double_type_node, val); | 3154 /* Convert `float' to `double'. */ |
3037 } | 3155 if (warn_double_promotion && !c_inhibit_evaluation_warnings) |
3156 warning (OPT_Wdouble_promotion, | |
3157 "implicit conversion from %qT to %qT when passing " | |
3158 "argument to function", | |
3159 valtype, double_type_node); | |
3160 parmval = convert (double_type_node, val); | |
3161 } | |
3162 } | |
3038 else if (excess_precision && !type_generic) | 3163 else if (excess_precision && !type_generic) |
3039 /* A "double" argument with excess precision being passed | 3164 /* A "double" argument with excess precision being passed |
3040 without a prototype or in variable arguments. */ | 3165 without a prototype or in variable arguments. */ |
3041 parmval = convert (valtype, val); | 3166 parmval = convert (valtype, val); |
3042 else if ((invalid_func_diag = | 3167 else if ((invalid_func_diag = |
3065 && !(fundecl&&CbC_IS_CODE_SEGMENT(fundecl)) ) | 3190 && !(fundecl&&CbC_IS_CODE_SEGMENT(fundecl)) ) |
3066 #else | 3191 #else |
3067 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node) | 3192 if (typetail != 0 && TREE_VALUE (typetail) != void_type_node) |
3068 #endif | 3193 #endif |
3069 { | 3194 { |
3070 error ("too few arguments to function %qE", function); | 3195 error_at (input_location, |
3196 "too few arguments to function %qE", function); | |
3197 if (fundecl && !DECL_BUILT_IN (fundecl)) | |
3198 inform (DECL_SOURCE_LOCATION (fundecl), "declared here"); | |
3071 return -1; | 3199 return -1; |
3072 } | 3200 } |
3073 | 3201 |
3074 return error_args ? -1 : (int) parmnum; | 3202 return error_args ? -1 : (int) parmnum; |
3075 } | 3203 } |
3433 if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret)) | 3561 if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret)) |
3434 location = EXPR_LOCATION (ret); | 3562 location = EXPR_LOCATION (ret); |
3435 goto return_build_unary_op; | 3563 goto return_build_unary_op; |
3436 | 3564 |
3437 case REALPART_EXPR: | 3565 case REALPART_EXPR: |
3438 if (TREE_CODE (arg) == COMPLEX_CST) | |
3439 ret = TREE_REALPART (arg); | |
3440 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE) | |
3441 ret = fold_build1_loc (location, | |
3442 REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg); | |
3443 else | |
3444 ret = arg; | |
3445 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE) | |
3446 eptype = TREE_TYPE (eptype); | |
3447 goto return_build_unary_op; | |
3448 | |
3449 case IMAGPART_EXPR: | 3566 case IMAGPART_EXPR: |
3450 if (TREE_CODE (arg) == COMPLEX_CST) | 3567 ret = build_real_imag_expr (location, code, arg); |
3451 ret = TREE_IMAGPART (arg); | 3568 if (ret == error_mark_node) |
3452 else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE) | 3569 return error_mark_node; |
3453 ret = fold_build1_loc (location, | |
3454 IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg); | |
3455 else | |
3456 ret = omit_one_operand_loc (location, TREE_TYPE (arg), | |
3457 integer_zero_node, arg); | |
3458 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE) | 3570 if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE) |
3459 eptype = TREE_TYPE (eptype); | 3571 eptype = TREE_TYPE (eptype); |
3460 goto return_build_unary_op; | 3572 goto return_build_unary_op; |
3461 | 3573 |
3462 case PREINCREMENT_EXPR: | 3574 case PREINCREMENT_EXPR: |
3475 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg)); | 3587 gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg)); |
3476 C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1; | 3588 C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1; |
3477 goto return_build_unary_op; | 3589 goto return_build_unary_op; |
3478 } | 3590 } |
3479 | 3591 |
3480 /* Complain about anything that is not a true lvalue. */ | 3592 /* Complain about anything that is not a true lvalue. In |
3481 if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR | 3593 Objective-C, skip this check for property_refs. */ |
3482 || code == POSTINCREMENT_EXPR) | 3594 if (!objc_is_property_ref (arg) |
3483 ? lv_increment | 3595 && !lvalue_or_else (location, |
3484 : lv_decrement))) | 3596 arg, ((code == PREINCREMENT_EXPR |
3485 return error_mark_node; | 3597 || code == POSTINCREMENT_EXPR) |
3598 ? lv_increment | |
3599 : lv_decrement))) | |
3600 return error_mark_node; | |
3486 | 3601 |
3487 if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE) | 3602 if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE) |
3488 { | 3603 { |
3489 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) | 3604 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) |
3490 warning_at (location, OPT_Wc___compat, | 3605 warning_at (location, OPT_Wc___compat, |
3529 | 3644 |
3530 return error_mark_node; | 3645 return error_mark_node; |
3531 } | 3646 } |
3532 | 3647 |
3533 { | 3648 { |
3534 tree inc; | 3649 tree inc; |
3535 | 3650 |
3536 argtype = TREE_TYPE (arg); | 3651 argtype = TREE_TYPE (arg); |
3537 | 3652 |
3538 /* Compute the increment. */ | 3653 /* Compute the increment. */ |
3539 | 3654 |
3540 if (typecode == POINTER_TYPE) | 3655 if (typecode == POINTER_TYPE) |
3541 { | 3656 { |
3542 /* If pointer target is an undefined struct, | 3657 /* If pointer target is an undefined struct, |
3543 we just cannot know how to do the arithmetic. */ | 3658 we just cannot know how to do the arithmetic. */ |
3544 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype))) | 3659 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype))) |
3545 { | 3660 { |
3546 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) | 3661 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) |
3547 error_at (location, | 3662 error_at (location, |
3548 "increment of pointer to unknown structure"); | 3663 "increment of pointer to unknown structure"); |
3549 else | 3664 else |
3550 error_at (location, | 3665 error_at (location, |
3551 "decrement of pointer to unknown structure"); | 3666 "decrement of pointer to unknown structure"); |
3552 } | 3667 } |
3553 else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE | 3668 else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE |
3554 || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE) | 3669 || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE) |
3555 { | 3670 { |
3556 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) | 3671 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) |
3557 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, | 3672 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, |
3558 "wrong type argument to increment"); | 3673 "wrong type argument to increment"); |
3559 else | 3674 else |
3560 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, | 3675 pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, |
3561 "wrong type argument to decrement"); | 3676 "wrong type argument to decrement"); |
3562 } | 3677 } |
3563 | 3678 |
3564 inc = c_size_in_bytes (TREE_TYPE (argtype)); | 3679 inc = c_size_in_bytes (TREE_TYPE (argtype)); |
3565 inc = fold_convert_loc (location, sizetype, inc); | 3680 inc = fold_convert_loc (location, sizetype, inc); |
3566 } | 3681 } |
3567 else if (FRACT_MODE_P (TYPE_MODE (argtype))) | 3682 else if (FRACT_MODE_P (TYPE_MODE (argtype))) |
3568 { | 3683 { |
3569 /* For signed fract types, we invert ++ to -- or | 3684 /* For signed fract types, we invert ++ to -- or |
3570 -- to ++, and change inc from 1 to -1, because | 3685 -- to ++, and change inc from 1 to -1, because |
3571 it is not possible to represent 1 in signed fract constants. | 3686 it is not possible to represent 1 in signed fract constants. |
3572 For unsigned fract types, the result always overflows and | 3687 For unsigned fract types, the result always overflows and |
3573 we get an undefined (original) or the maximum value. */ | 3688 we get an undefined (original) or the maximum value. */ |
3574 if (code == PREINCREMENT_EXPR) | 3689 if (code == PREINCREMENT_EXPR) |
3575 code = PREDECREMENT_EXPR; | 3690 code = PREDECREMENT_EXPR; |
3576 else if (code == PREDECREMENT_EXPR) | 3691 else if (code == PREDECREMENT_EXPR) |
3577 code = PREINCREMENT_EXPR; | 3692 code = PREINCREMENT_EXPR; |
3578 else if (code == POSTINCREMENT_EXPR) | 3693 else if (code == POSTINCREMENT_EXPR) |
3579 code = POSTDECREMENT_EXPR; | 3694 code = POSTDECREMENT_EXPR; |
3580 else /* code == POSTDECREMENT_EXPR */ | 3695 else /* code == POSTDECREMENT_EXPR */ |
3581 code = POSTINCREMENT_EXPR; | 3696 code = POSTINCREMENT_EXPR; |
3582 | 3697 |
3583 inc = integer_minus_one_node; | 3698 inc = integer_minus_one_node; |
3584 inc = convert (argtype, inc); | 3699 inc = convert (argtype, inc); |
3585 } | 3700 } |
3586 else | 3701 else |
3587 { | 3702 { |
3588 inc = integer_one_node; | 3703 inc = integer_one_node; |
3589 inc = convert (argtype, inc); | 3704 inc = convert (argtype, inc); |
3590 } | 3705 } |
3591 | 3706 |
3592 /* Report a read-only lvalue. */ | 3707 /* If 'arg' is an Objective-C PROPERTY_REF expression, then we |
3593 if (TYPE_READONLY (argtype)) | 3708 need to ask Objective-C to build the increment or decrement |
3594 { | 3709 expression for it. */ |
3595 readonly_error (arg, | 3710 if (objc_is_property_ref (arg)) |
3596 ((code == PREINCREMENT_EXPR | 3711 return objc_build_incr_expr_for_property_ref (location, code, |
3597 || code == POSTINCREMENT_EXPR) | 3712 arg, inc); |
3598 ? lv_increment : lv_decrement)); | 3713 |
3599 return error_mark_node; | 3714 /* Report a read-only lvalue. */ |
3600 } | 3715 if (TYPE_READONLY (argtype)) |
3601 else if (TREE_READONLY (arg)) | 3716 { |
3602 readonly_warning (arg, | 3717 readonly_error (arg, |
3603 ((code == PREINCREMENT_EXPR | 3718 ((code == PREINCREMENT_EXPR |
3604 || code == POSTINCREMENT_EXPR) | 3719 || code == POSTINCREMENT_EXPR) |
3605 ? lv_increment : lv_decrement)); | 3720 ? lv_increment : lv_decrement)); |
3606 | 3721 return error_mark_node; |
3607 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE) | 3722 } |
3608 val = boolean_increment (code, arg); | 3723 else if (TREE_READONLY (arg)) |
3609 else | 3724 readonly_warning (arg, |
3610 val = build2 (code, TREE_TYPE (arg), arg, inc); | 3725 ((code == PREINCREMENT_EXPR |
3611 TREE_SIDE_EFFECTS (val) = 1; | 3726 || code == POSTINCREMENT_EXPR) |
3612 if (TREE_CODE (val) != code) | 3727 ? lv_increment : lv_decrement)); |
3613 TREE_NO_WARNING (val) = 1; | 3728 |
3614 ret = val; | 3729 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE) |
3615 goto return_build_unary_op; | 3730 val = boolean_increment (code, arg); |
3731 else | |
3732 val = build2 (code, TREE_TYPE (arg), arg, inc); | |
3733 TREE_SIDE_EFFECTS (val) = 1; | |
3734 if (TREE_CODE (val) != code) | |
3735 TREE_NO_WARNING (val) = 1; | |
3736 ret = val; | |
3737 goto return_build_unary_op; | |
3616 } | 3738 } |
3617 | 3739 |
3618 case ADDR_EXPR: | 3740 case ADDR_EXPR: |
3619 /* Note that this operation never does default_conversion. */ | 3741 /* Note that this operation never does default_conversion. */ |
3620 | 3742 |
3652 } | 3774 } |
3653 | 3775 |
3654 /* Anything not already handled and not a true memory reference | 3776 /* Anything not already handled and not a true memory reference |
3655 or a non-lvalue array is an error. */ | 3777 or a non-lvalue array is an error. */ |
3656 else if (typecode != FUNCTION_TYPE && !flag | 3778 else if (typecode != FUNCTION_TYPE && !flag |
3657 && !lvalue_or_else (arg, lv_addressof)) | 3779 && !lvalue_or_else (location, arg, lv_addressof)) |
3658 return error_mark_node; | 3780 return error_mark_node; |
3659 | 3781 |
3660 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify | 3782 /* Move address operations inside C_MAYBE_CONST_EXPR to simplify |
3661 folding later. */ | 3783 folding later. */ |
3662 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR) | 3784 if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR) |
3663 { | 3785 { |
3673 | 3795 |
3674 /* Ordinary case; arg is a COMPONENT_REF or a decl. */ | 3796 /* Ordinary case; arg is a COMPONENT_REF or a decl. */ |
3675 argtype = TREE_TYPE (arg); | 3797 argtype = TREE_TYPE (arg); |
3676 | 3798 |
3677 /* If the lvalue is const or volatile, merge that into the type | 3799 /* If the lvalue is const or volatile, merge that into the type |
3678 to which the address will point. Note that you can't get a | 3800 to which the address will point. This should only be needed |
3679 restricted pointer by taking the address of something, so we | 3801 for function types. */ |
3680 only have to deal with `const' and `volatile' here. */ | |
3681 if ((DECL_P (arg) || REFERENCE_CLASS_P (arg)) | 3802 if ((DECL_P (arg) || REFERENCE_CLASS_P (arg)) |
3682 && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))) | 3803 && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))) |
3683 argtype = c_build_type_variant (argtype, | 3804 { |
3684 TREE_READONLY (arg), | 3805 int orig_quals = TYPE_QUALS (strip_array_types (argtype)); |
3685 TREE_THIS_VOLATILE (arg)); | 3806 int quals = orig_quals; |
3807 | |
3808 if (TREE_READONLY (arg)) | |
3809 quals |= TYPE_QUAL_CONST; | |
3810 if (TREE_THIS_VOLATILE (arg)) | |
3811 quals |= TYPE_QUAL_VOLATILE; | |
3812 | |
3813 gcc_assert (quals == orig_quals | |
3814 || TREE_CODE (argtype) == FUNCTION_TYPE); | |
3815 | |
3816 argtype = c_build_qualified_type (argtype, quals); | |
3817 } | |
3686 | 3818 |
3687 if (!c_mark_addressable (arg)) | 3819 if (!c_mark_addressable (arg)) |
3688 return error_mark_node; | 3820 return error_mark_node; |
3689 | 3821 |
3690 gcc_assert (TREE_CODE (arg) != COMPONENT_REF | 3822 gcc_assert (TREE_CODE (arg) != COMPONENT_REF |
3773 | 3905 |
3774 default: | 3906 default: |
3775 return 0; | 3907 return 0; |
3776 } | 3908 } |
3777 } | 3909 } |
3778 | |
3779 /* Give an error for storing in something that is 'const'. */ | |
3780 | |
3781 static void | |
3782 readonly_error (tree arg, enum lvalue_use use) | |
3783 { | |
3784 gcc_assert (use == lv_assign || use == lv_increment || use == lv_decrement | |
3785 || use == lv_asm); | |
3786 /* Using this macro rather than (for example) arrays of messages | |
3787 ensures that all the format strings are checked at compile | |
3788 time. */ | |
3789 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \ | |
3790 : (use == lv_increment ? (I) \ | |
3791 : (use == lv_decrement ? (D) : (AS)))) | |
3792 if (TREE_CODE (arg) == COMPONENT_REF) | |
3793 { | |
3794 if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0)))) | |
3795 readonly_error (TREE_OPERAND (arg, 0), use); | |
3796 else | |
3797 error (READONLY_MSG (G_("assignment of read-only member %qD"), | |
3798 G_("increment of read-only member %qD"), | |
3799 G_("decrement of read-only member %qD"), | |
3800 G_("read-only member %qD used as %<asm%> output")), | |
3801 TREE_OPERAND (arg, 1)); | |
3802 } | |
3803 else if (TREE_CODE (arg) == VAR_DECL) | |
3804 error (READONLY_MSG (G_("assignment of read-only variable %qD"), | |
3805 G_("increment of read-only variable %qD"), | |
3806 G_("decrement of read-only variable %qD"), | |
3807 G_("read-only variable %qD used as %<asm%> output")), | |
3808 arg); | |
3809 else | |
3810 error (READONLY_MSG (G_("assignment of read-only location %qE"), | |
3811 G_("increment of read-only location %qE"), | |
3812 G_("decrement of read-only location %qE"), | |
3813 G_("read-only location %qE used as %<asm%> output")), | |
3814 arg); | |
3815 } | |
3816 | 3910 |
3817 /* Give a warning for storing in something that is read-only in GCC | 3911 /* Give a warning for storing in something that is read-only in GCC |
3818 terms but not const in ISO C terms. */ | 3912 terms but not const in ISO C terms. */ |
3819 | 3913 |
3820 static void | 3914 static void |
3838 } | 3932 } |
3839 | 3933 |
3840 | 3934 |
3841 /* Return nonzero if REF is an lvalue valid for this language; | 3935 /* Return nonzero if REF is an lvalue valid for this language; |
3842 otherwise, print an error message and return zero. USE says | 3936 otherwise, print an error message and return zero. USE says |
3843 how the lvalue is being used and so selects the error message. */ | 3937 how the lvalue is being used and so selects the error message. |
3938 LOCATION is the location at which any error should be reported. */ | |
3844 | 3939 |
3845 static int | 3940 static int |
3846 lvalue_or_else (const_tree ref, enum lvalue_use use) | 3941 lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use) |
3847 { | 3942 { |
3848 int win = lvalue_p (ref); | 3943 int win = lvalue_p (ref); |
3849 | 3944 |
3850 if (!win) | 3945 if (!win) |
3851 lvalue_error (use); | 3946 lvalue_error (loc, use); |
3852 | 3947 |
3853 return win; | 3948 return win; |
3854 } | 3949 } |
3855 | 3950 |
3856 /* Mark EXP saying that we need to be able to take the | 3951 /* Mark EXP saying that we need to be able to take the |
3918 default: | 4013 default: |
3919 return true; | 4014 return true; |
3920 } | 4015 } |
3921 } | 4016 } |
3922 | 4017 |
4018 /* Convert EXPR to TYPE, warning about conversion problems with | |
4019 constants. SEMANTIC_TYPE is the type this conversion would use | |
4020 without excess precision. If SEMANTIC_TYPE is NULL, this function | |
4021 is equivalent to convert_and_check. This function is a wrapper that | |
4022 handles conversions that may be different than | |
4023 the usual ones because of excess precision. */ | |
4024 | |
4025 static tree | |
4026 ep_convert_and_check (tree type, tree expr, tree semantic_type) | |
4027 { | |
4028 if (TREE_TYPE (expr) == type) | |
4029 return expr; | |
4030 | |
4031 if (!semantic_type) | |
4032 return convert_and_check (type, expr); | |
4033 | |
4034 if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE | |
4035 && TREE_TYPE (expr) != semantic_type) | |
4036 { | |
4037 /* For integers, we need to check the real conversion, not | |
4038 the conversion to the excess precision type. */ | |
4039 expr = convert_and_check (semantic_type, expr); | |
4040 } | |
4041 /* Result type is the excess precision type, which should be | |
4042 large enough, so do not check. */ | |
4043 return convert (type, expr); | |
4044 } | |
4045 | |
3923 /* Build and return a conditional expression IFEXP ? OP1 : OP2. If | 4046 /* Build and return a conditional expression IFEXP ? OP1 : OP2. If |
3924 IFEXP_BCP then the condition is a call to __builtin_constant_p, and | 4047 IFEXP_BCP then the condition is a call to __builtin_constant_p, and |
3925 if folded to an integer constant then the unselected half may | 4048 if folded to an integer constant then the unselected half may |
3926 contain arbitrary operations not normally permitted in constant | 4049 contain arbitrary operations not normally permitted in constant |
3927 expressions. Set the location of the expression to LOC. */ | 4050 expressions. Set the location of the expression to LOC. */ |
3934 tree type1; | 4057 tree type1; |
3935 tree type2; | 4058 tree type2; |
3936 enum tree_code code1; | 4059 enum tree_code code1; |
3937 enum tree_code code2; | 4060 enum tree_code code2; |
3938 tree result_type = NULL; | 4061 tree result_type = NULL; |
3939 tree ep_result_type = NULL; | 4062 tree semantic_result_type = NULL; |
3940 tree orig_op1 = op1, orig_op2 = op2; | 4063 tree orig_op1 = op1, orig_op2 = op2; |
3941 bool int_const, op1_int_operands, op2_int_operands, int_operands; | 4064 bool int_const, op1_int_operands, op2_int_operands, int_operands; |
3942 bool ifexp_int_operands; | 4065 bool ifexp_int_operands; |
3943 tree ret; | 4066 tree ret; |
3944 bool objc_ok; | |
3945 | 4067 |
3946 op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1); | 4068 op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1); |
3947 if (op1_int_operands) | 4069 if (op1_int_operands) |
3948 op1 = remove_c_maybe_const_expr (op1); | 4070 op1 = remove_c_maybe_const_expr (op1); |
3949 op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2); | 4071 op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2); |
3976 { | 4098 { |
3977 error_at (colon_loc, "non-lvalue array in conditional expression"); | 4099 error_at (colon_loc, "non-lvalue array in conditional expression"); |
3978 return error_mark_node; | 4100 return error_mark_node; |
3979 } | 4101 } |
3980 | 4102 |
3981 objc_ok = objc_compare_types (type1, type2, -3, NULL_TREE); | |
3982 | |
3983 if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR | 4103 if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR |
3984 || TREE_CODE (op2) == EXCESS_PRECISION_EXPR) | 4104 || TREE_CODE (op2) == EXCESS_PRECISION_EXPR) |
3985 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE | 4105 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE |
3986 || code1 == COMPLEX_TYPE) | 4106 || code1 == COMPLEX_TYPE) |
3987 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE | 4107 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE |
3988 || code2 == COMPLEX_TYPE)) | 4108 || code2 == COMPLEX_TYPE)) |
3989 { | 4109 { |
3990 ep_result_type = c_common_type (type1, type2); | 4110 semantic_result_type = c_common_type (type1, type2); |
3991 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR) | 4111 if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR) |
3992 { | 4112 { |
3993 op1 = TREE_OPERAND (op1, 0); | 4113 op1 = TREE_OPERAND (op1, 0); |
3994 type1 = TREE_TYPE (op1); | 4114 type1 = TREE_TYPE (op1); |
3995 gcc_assert (TREE_CODE (type1) == code1); | 4115 gcc_assert (TREE_CODE (type1) == code1); |
4029 || code1 == COMPLEX_TYPE) | 4149 || code1 == COMPLEX_TYPE) |
4030 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE | 4150 && (code2 == INTEGER_TYPE || code2 == REAL_TYPE |
4031 || code2 == COMPLEX_TYPE)) | 4151 || code2 == COMPLEX_TYPE)) |
4032 { | 4152 { |
4033 result_type = c_common_type (type1, type2); | 4153 result_type = c_common_type (type1, type2); |
4154 do_warn_double_promotion (result_type, type1, type2, | |
4155 "implicit conversion from %qT to %qT to " | |
4156 "match other result of conditional", | |
4157 colon_loc); | |
4034 | 4158 |
4035 /* If -Wsign-compare, warn here if type1 and type2 have | 4159 /* If -Wsign-compare, warn here if type1 and type2 have |
4036 different signedness. We'll promote the signed to unsigned | 4160 different signedness. We'll promote the signed to unsigned |
4037 and later code won't know it used to be different. | 4161 and later code won't know it used to be different. |
4038 Do this check on the original types, so that explicit casts | 4162 Do this check on the original types, so that explicit casts |
4131 "%<void *%> and function pointer"); | 4255 "%<void *%> and function pointer"); |
4132 result_type = build_pointer_type (qualify_type (TREE_TYPE (type1), | 4256 result_type = build_pointer_type (qualify_type (TREE_TYPE (type1), |
4133 TREE_TYPE (type2))); | 4257 TREE_TYPE (type2))); |
4134 } | 4258 } |
4135 else if (VOID_TYPE_P (TREE_TYPE (type2))) | 4259 else if (VOID_TYPE_P (TREE_TYPE (type2))) |
4136 { | 4260 { |
4137 if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE) | 4261 if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE) |
4138 pedwarn (colon_loc, OPT_pedantic, | 4262 pedwarn (colon_loc, OPT_pedantic, |
4139 "ISO C forbids conditional expr between " | 4263 "ISO C forbids conditional expr between " |
4140 "%<void *%> and function pointer"); | 4264 "%<void *%> and function pointer"); |
4141 result_type = build_pointer_type (qualify_type (TREE_TYPE (type2), | 4265 result_type = build_pointer_type (qualify_type (TREE_TYPE (type2), |
4142 TREE_TYPE (type1))); | 4266 TREE_TYPE (type1))); |
4143 } | 4267 } |
4268 /* Objective-C pointer comparisons are a bit more lenient. */ | |
4269 else if (objc_have_common_type (type1, type2, -3, NULL_TREE)) | |
4270 result_type = objc_common_type (type1, type2); | |
4144 else | 4271 else |
4145 { | 4272 { |
4146 int qual = ENCODE_QUAL_ADDR_SPACE (as_common); | 4273 int qual = ENCODE_QUAL_ADDR_SPACE (as_common); |
4147 | 4274 |
4148 if (!objc_ok) | 4275 pedwarn (colon_loc, 0, |
4149 pedwarn (colon_loc, 0, | 4276 "pointer type mismatch in conditional expression"); |
4150 "pointer type mismatch in conditional expression"); | 4277 result_type = build_pointer_type |
4151 result_type = build_pointer_type | 4278 (build_qualified_type (void_type_node, qual)); |
4152 (build_qualified_type (void_type_node, qual)); | 4279 } |
4153 } | |
4154 } | 4280 } |
4155 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE) | 4281 else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE) |
4156 { | 4282 { |
4157 if (!null_pointer_constant_p (orig_op2)) | 4283 if (!null_pointer_constant_p (orig_op2)) |
4158 pedwarn (colon_loc, 0, | 4284 pedwarn (colon_loc, 0, |
4190 result_type | 4316 result_type |
4191 = build_type_variant (result_type, | 4317 = build_type_variant (result_type, |
4192 TYPE_READONLY (type1) || TYPE_READONLY (type2), | 4318 TYPE_READONLY (type1) || TYPE_READONLY (type2), |
4193 TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2)); | 4319 TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2)); |
4194 | 4320 |
4195 if (result_type != type1) | 4321 op1 = ep_convert_and_check (result_type, op1, semantic_result_type); |
4196 op1 = convert_and_check (result_type, op1); | 4322 op2 = ep_convert_and_check (result_type, op2, semantic_result_type); |
4197 if (result_type != type2) | |
4198 op2 = convert_and_check (result_type, op2); | |
4199 | 4323 |
4200 if (ifexp_bcp && ifexp == truthvalue_true_node) | 4324 if (ifexp_bcp && ifexp == truthvalue_true_node) |
4201 { | 4325 { |
4202 op2_int_operands = true; | 4326 op2_int_operands = true; |
4203 op1 = c_fully_fold (op1, require_constant_value, NULL); | 4327 op1 = c_fully_fold (op1, require_constant_value, NULL); |
4225 { | 4349 { |
4226 ret = build3 (COND_EXPR, result_type, ifexp, op1, op2); | 4350 ret = build3 (COND_EXPR, result_type, ifexp, op1, op2); |
4227 if (int_operands) | 4351 if (int_operands) |
4228 ret = note_integer_operands (ret); | 4352 ret = note_integer_operands (ret); |
4229 } | 4353 } |
4230 if (ep_result_type) | 4354 if (semantic_result_type) |
4231 ret = build1 (EXCESS_PRECISION_EXPR, ep_result_type, ret); | 4355 ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret); |
4232 | 4356 |
4233 protected_set_expr_location (ret, colon_loc); | 4357 protected_set_expr_location (ret, colon_loc); |
4234 return ret; | 4358 return ret; |
4235 } | 4359 } |
4236 | 4360 |
4305 return ret; | 4429 return ret; |
4306 } | 4430 } |
4307 | 4431 |
4308 /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to | 4432 /* Issue -Wcast-qual warnings when appropriate. TYPE is the type to |
4309 which we are casting. OTYPE is the type of the expression being | 4433 which we are casting. OTYPE is the type of the expression being |
4310 cast. Both TYPE and OTYPE are pointer types. -Wcast-qual appeared | 4434 cast. Both TYPE and OTYPE are pointer types. LOC is the location |
4311 on the command line. Named address space qualifiers are not handled | 4435 of the cast. -Wcast-qual appeared on the command line. Named |
4312 here, because they result in different warnings. */ | 4436 address space qualifiers are not handled here, because they result |
4437 in different warnings. */ | |
4313 | 4438 |
4314 static void | 4439 static void |
4315 handle_warn_cast_qual (tree type, tree otype) | 4440 handle_warn_cast_qual (location_t loc, tree type, tree otype) |
4316 { | 4441 { |
4317 tree in_type = type; | 4442 tree in_type = type; |
4318 tree in_otype = otype; | 4443 tree in_otype = otype; |
4319 int added = 0; | 4444 int added = 0; |
4320 int discarded = 0; | 4445 int discarded = 0; |
4343 } | 4468 } |
4344 while (TREE_CODE (in_type) == POINTER_TYPE | 4469 while (TREE_CODE (in_type) == POINTER_TYPE |
4345 && TREE_CODE (in_otype) == POINTER_TYPE); | 4470 && TREE_CODE (in_otype) == POINTER_TYPE); |
4346 | 4471 |
4347 if (added) | 4472 if (added) |
4348 warning (OPT_Wcast_qual, "cast adds new qualifiers to function type"); | 4473 warning_at (loc, OPT_Wcast_qual, |
4474 "cast adds %q#v qualifier to function type", added); | |
4349 | 4475 |
4350 if (discarded) | 4476 if (discarded) |
4351 /* There are qualifiers present in IN_OTYPE that are not present | 4477 /* There are qualifiers present in IN_OTYPE that are not present |
4352 in IN_TYPE. */ | 4478 in IN_TYPE. */ |
4353 warning (OPT_Wcast_qual, | 4479 warning_at (loc, OPT_Wcast_qual, |
4354 "cast discards qualifiers from pointer target type"); | 4480 "cast discards %q#v qualifier from pointer target type", |
4481 discarded); | |
4355 | 4482 |
4356 if (added || discarded) | 4483 if (added || discarded) |
4357 return; | 4484 return; |
4358 | 4485 |
4359 /* A cast from **T to const **T is unsafe, because it can cause a | 4486 /* A cast from **T to const **T is unsafe, because it can cause a |
4380 do | 4507 do |
4381 { | 4508 { |
4382 in_type = TREE_TYPE (in_type); | 4509 in_type = TREE_TYPE (in_type); |
4383 in_otype = TREE_TYPE (in_otype); | 4510 in_otype = TREE_TYPE (in_otype); |
4384 if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0 | 4511 if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0 |
4385 && !is_const) | 4512 && !is_const) |
4386 { | 4513 { |
4387 warning (OPT_Wcast_qual, | 4514 warning_at (loc, OPT_Wcast_qual, |
4388 ("new qualifiers in middle of multi-level non-const cast " | 4515 "to be safe all intermediate pointers in cast from " |
4389 "are unsafe")); | 4516 "%qT to %qT must be %<const%> qualified", |
4390 break; | 4517 otype, type); |
4391 } | 4518 break; |
4519 } | |
4392 if (is_const) | 4520 if (is_const) |
4393 is_const = TYPE_READONLY (in_type); | 4521 is_const = TYPE_READONLY (in_type); |
4394 } | 4522 } |
4395 while (TREE_CODE (in_type) == POINTER_TYPE); | 4523 while (TREE_CODE (in_type) == POINTER_TYPE); |
4396 } | 4524 } |
4447 } | 4575 } |
4448 else if (TREE_CODE (type) == UNION_TYPE) | 4576 else if (TREE_CODE (type) == UNION_TYPE) |
4449 { | 4577 { |
4450 tree field; | 4578 tree field; |
4451 | 4579 |
4452 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) | 4580 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
4453 if (TREE_TYPE (field) != error_mark_node | 4581 if (TREE_TYPE (field) != error_mark_node |
4454 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)), | 4582 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)), |
4455 TYPE_MAIN_VARIANT (TREE_TYPE (value)))) | 4583 TYPE_MAIN_VARIANT (TREE_TYPE (value)))) |
4456 break; | 4584 break; |
4457 | 4585 |
4458 if (field) | 4586 if (field) |
4459 { | 4587 { |
4460 tree t; | 4588 tree t; |
4461 | 4589 bool maybe_const = true; |
4462 pedwarn (loc, OPT_pedantic, "ISO C forbids casts to union type"); | 4590 |
4463 t = digest_init (loc, type, | 4591 pedwarn (loc, OPT_pedantic, "ISO C forbids casts to union type"); |
4464 build_constructor_single (type, field, value), | 4592 t = c_fully_fold (value, false, &maybe_const); |
4465 NULL_TREE, false, true, 0); | 4593 t = build_constructor_single (type, field, t); |
4466 TREE_CONSTANT (t) = TREE_CONSTANT (value); | 4594 if (!maybe_const) |
4467 return t; | 4595 t = c_wrap_maybe_const (t, true); |
4468 } | 4596 t = digest_init (loc, type, t, |
4597 NULL_TREE, false, true, 0); | |
4598 TREE_CONSTANT (t) = TREE_CONSTANT (value); | |
4599 return t; | |
4600 } | |
4469 error_at (loc, "cast to union type from type not present in union"); | 4601 error_at (loc, "cast to union type from type not present in union"); |
4470 return error_mark_node; | 4602 return error_mark_node; |
4471 } | 4603 } |
4472 else | 4604 else |
4473 { | 4605 { |
4482 | 4614 |
4483 otype = TREE_TYPE (value); | 4615 otype = TREE_TYPE (value); |
4484 | 4616 |
4485 /* Optionally warn about potentially worrisome casts. */ | 4617 /* Optionally warn about potentially worrisome casts. */ |
4486 if (warn_cast_qual | 4618 if (warn_cast_qual |
4487 && TREE_CODE (type) == POINTER_TYPE | 4619 && TREE_CODE (type) == POINTER_TYPE |
4488 && TREE_CODE (otype) == POINTER_TYPE) | 4620 && TREE_CODE (otype) == POINTER_TYPE) |
4489 handle_warn_cast_qual (type, otype); | 4621 handle_warn_cast_qual (loc, type, otype); |
4490 | 4622 |
4491 /* Warn about conversions between pointers to disjoint | 4623 /* Warn about conversions between pointers to disjoint |
4492 address spaces. */ | 4624 address spaces. */ |
4493 if (TREE_CODE (type) == POINTER_TYPE | 4625 if (TREE_CODE (type) == POINTER_TYPE |
4494 && TREE_CODE (otype) == POINTER_TYPE | 4626 && TREE_CODE (otype) == POINTER_TYPE |
4656 } | 4788 } |
4657 | 4789 |
4658 if (CAN_HAVE_LOCATION_P (ret) && !EXPR_HAS_LOCATION (ret)) | 4790 if (CAN_HAVE_LOCATION_P (ret) && !EXPR_HAS_LOCATION (ret)) |
4659 SET_EXPR_LOCATION (ret, loc); | 4791 SET_EXPR_LOCATION (ret, loc); |
4660 | 4792 |
4661 /* C++ does not permits types to be defined in a cast. */ | 4793 /* C++ does not permits types to be defined in a cast, but it |
4662 if (warn_cxx_compat && type_name->specs->tag_defined_p) | 4794 allows references to incomplete types. */ |
4795 if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef) | |
4663 warning_at (loc, OPT_Wc___compat, | 4796 warning_at (loc, OPT_Wc___compat, |
4664 "defining a type in a cast is invalid in C++"); | 4797 "defining a type in a cast is invalid in C++"); |
4665 | 4798 |
4666 return ret; | 4799 return ret; |
4667 } | 4800 } |
4695 | 4828 |
4696 /* Avoid duplicate error messages from operands that had errors. */ | 4829 /* Avoid duplicate error messages from operands that had errors. */ |
4697 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK) | 4830 if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK) |
4698 return error_mark_node; | 4831 return error_mark_node; |
4699 | 4832 |
4700 if (!lvalue_or_else (lhs, lv_assign)) | 4833 /* For ObjC properties, defer this check. */ |
4834 if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign)) | |
4701 return error_mark_node; | 4835 return error_mark_node; |
4702 | 4836 |
4703 if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR) | 4837 if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR) |
4704 { | 4838 { |
4705 rhs_semantic_type = TREE_TYPE (rhs); | 4839 rhs_semantic_type = TREE_TYPE (rhs); |
4736 /* The original type of the right hand side is no longer | 4870 /* The original type of the right hand side is no longer |
4737 meaningful. */ | 4871 meaningful. */ |
4738 rhs_origtype = NULL_TREE; | 4872 rhs_origtype = NULL_TREE; |
4739 } | 4873 } |
4740 | 4874 |
4875 if (c_dialect_objc ()) | |
4876 { | |
4877 /* Check if we are modifying an Objective-C property reference; | |
4878 if so, we need to generate setter calls. */ | |
4879 result = objc_maybe_build_modify_expr (lhs, newrhs); | |
4880 if (result) | |
4881 return result; | |
4882 | |
4883 /* Else, do the check that we postponed for Objective-C. */ | |
4884 if (!lvalue_or_else (location, lhs, lv_assign)) | |
4885 return error_mark_node; | |
4886 } | |
4887 | |
4741 /* Give an error for storing in something that is 'const'. */ | 4888 /* Give an error for storing in something that is 'const'. */ |
4742 | 4889 |
4743 if (TYPE_READONLY (lhstype) | 4890 if (TYPE_READONLY (lhstype) |
4744 || ((TREE_CODE (lhstype) == RECORD_TYPE | 4891 || ((TREE_CODE (lhstype) == RECORD_TYPE |
4745 || TREE_CODE (lhstype) == UNION_TYPE) | 4892 || TREE_CODE (lhstype) == UNION_TYPE) |
4831 ic_assign, false, NULL_TREE, NULL_TREE, 0); | 4978 ic_assign, false, NULL_TREE, NULL_TREE, 0); |
4832 protected_set_expr_location (result, location); | 4979 protected_set_expr_location (result, location); |
4833 return result; | 4980 return result; |
4834 } | 4981 } |
4835 | 4982 |
4983 /* Return whether STRUCT_TYPE has an anonymous field with type TYPE. | |
4984 This is used to implement -fplan9-extensions. */ | |
4985 | |
4986 static bool | |
4987 find_anonymous_field_with_type (tree struct_type, tree type) | |
4988 { | |
4989 tree field; | |
4990 bool found; | |
4991 | |
4992 gcc_assert (TREE_CODE (struct_type) == RECORD_TYPE | |
4993 || TREE_CODE (struct_type) == UNION_TYPE); | |
4994 found = false; | |
4995 for (field = TYPE_FIELDS (struct_type); | |
4996 field != NULL_TREE; | |
4997 field = TREE_CHAIN (field)) | |
4998 { | |
4999 if (DECL_NAME (field) == NULL | |
5000 && comptypes (type, TYPE_MAIN_VARIANT (TREE_TYPE (field)))) | |
5001 { | |
5002 if (found) | |
5003 return false; | |
5004 found = true; | |
5005 } | |
5006 else if (DECL_NAME (field) == NULL | |
5007 && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE | |
5008 || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) | |
5009 && find_anonymous_field_with_type (TREE_TYPE (field), type)) | |
5010 { | |
5011 if (found) | |
5012 return false; | |
5013 found = true; | |
5014 } | |
5015 } | |
5016 return found; | |
5017 } | |
5018 | |
5019 /* RHS is an expression whose type is pointer to struct. If there is | |
5020 an anonymous field in RHS with type TYPE, then return a pointer to | |
5021 that field in RHS. This is used with -fplan9-extensions. This | |
5022 returns NULL if no conversion could be found. */ | |
5023 | |
5024 static tree | |
5025 convert_to_anonymous_field (location_t location, tree type, tree rhs) | |
5026 { | |
5027 tree rhs_struct_type, lhs_main_type; | |
5028 tree field, found_field; | |
5029 bool found_sub_field; | |
5030 tree ret; | |
5031 | |
5032 gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs))); | |
5033 rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs)); | |
5034 gcc_assert (TREE_CODE (rhs_struct_type) == RECORD_TYPE | |
5035 || TREE_CODE (rhs_struct_type) == UNION_TYPE); | |
5036 | |
5037 gcc_assert (POINTER_TYPE_P (type)); | |
5038 lhs_main_type = TYPE_MAIN_VARIANT (TREE_TYPE (type)); | |
5039 | |
5040 found_field = NULL_TREE; | |
5041 found_sub_field = false; | |
5042 for (field = TYPE_FIELDS (rhs_struct_type); | |
5043 field != NULL_TREE; | |
5044 field = TREE_CHAIN (field)) | |
5045 { | |
5046 if (DECL_NAME (field) != NULL_TREE | |
5047 || (TREE_CODE (TREE_TYPE (field)) != RECORD_TYPE | |
5048 && TREE_CODE (TREE_TYPE (field)) != UNION_TYPE)) | |
5049 continue; | |
5050 if (comptypes (lhs_main_type, TYPE_MAIN_VARIANT (TREE_TYPE (field)))) | |
5051 { | |
5052 if (found_field != NULL_TREE) | |
5053 return NULL_TREE; | |
5054 found_field = field; | |
5055 } | |
5056 else if (find_anonymous_field_with_type (TREE_TYPE (field), | |
5057 lhs_main_type)) | |
5058 { | |
5059 if (found_field != NULL_TREE) | |
5060 return NULL_TREE; | |
5061 found_field = field; | |
5062 found_sub_field = true; | |
5063 } | |
5064 } | |
5065 | |
5066 if (found_field == NULL_TREE) | |
5067 return NULL_TREE; | |
5068 | |
5069 ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field), | |
5070 build_fold_indirect_ref (rhs), found_field, | |
5071 NULL_TREE); | |
5072 ret = build_fold_addr_expr_loc (location, ret); | |
5073 | |
5074 if (found_sub_field) | |
5075 { | |
5076 ret = convert_to_anonymous_field (location, type, ret); | |
5077 gcc_assert (ret != NULL_TREE); | |
5078 } | |
5079 | |
5080 return ret; | |
5081 } | |
5082 | |
4836 /* Convert value RHS to type TYPE as preparation for an assignment to | 5083 /* Convert value RHS to type TYPE as preparation for an assignment to |
4837 an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the | 5084 an lvalue of type TYPE. If ORIGTYPE is not NULL_TREE, it is the |
4838 original type of RHS; this differs from TREE_TYPE (RHS) for enum | 5085 original type of RHS; this differs from TREE_TYPE (RHS) for enum |
4839 types. NULL_POINTER_CONSTANT says whether RHS was a null pointer | 5086 types. NULL_POINTER_CONSTANT says whether RHS was a null pointer |
4840 constant before any folding. | 5087 constant before any folding. |
4896 break; \ | 5143 break; \ |
4897 case ic_assign: \ | 5144 case ic_assign: \ |
4898 pedwarn (LOCATION, OPT, AS); \ | 5145 pedwarn (LOCATION, OPT, AS); \ |
4899 break; \ | 5146 break; \ |
4900 case ic_init: \ | 5147 case ic_init: \ |
4901 pedwarn (LOCATION, OPT, IN); \ | 5148 pedwarn_init (LOCATION, OPT, IN); \ |
4902 break; \ | 5149 break; \ |
4903 case ic_return: \ | 5150 case ic_return: \ |
4904 pedwarn (LOCATION, OPT, RE); \ | 5151 pedwarn (LOCATION, OPT, RE); \ |
5152 break; \ | |
5153 default: \ | |
5154 gcc_unreachable (); \ | |
5155 } \ | |
5156 } while (0) | |
5157 | |
5158 /* This macro is used to emit diagnostics to ensure that all format | |
5159 strings are complete sentences, visible to gettext and checked at | |
5160 compile time. It is the same as WARN_FOR_ASSIGNMENT but with an | |
5161 extra parameter to enumerate qualifiers. */ | |
5162 | |
5163 #define WARN_FOR_QUALIFIERS(LOCATION, OPT, AR, AS, IN, RE, QUALS) \ | |
5164 do { \ | |
5165 switch (errtype) \ | |
5166 { \ | |
5167 case ic_argpass: \ | |
5168 if (pedwarn (LOCATION, OPT, AR, parmnum, rname, QUALS)) \ | |
5169 inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \ | |
5170 ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \ | |
5171 "expected %qT but argument is of type %qT", \ | |
5172 type, rhstype); \ | |
5173 break; \ | |
5174 case ic_assign: \ | |
5175 pedwarn (LOCATION, OPT, AS, QUALS); \ | |
5176 break; \ | |
5177 case ic_init: \ | |
5178 pedwarn (LOCATION, OPT, IN, QUALS); \ | |
5179 break; \ | |
5180 case ic_return: \ | |
5181 pedwarn (LOCATION, OPT, RE, QUALS); \ | |
4905 break; \ | 5182 break; \ |
4906 default: \ | 5183 default: \ |
4907 gcc_unreachable (); \ | 5184 gcc_unreachable (); \ |
4908 } \ | 5185 } \ |
4909 } while (0) | 5186 } while (0) |
5023 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE | 5300 || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE |
5024 || coder == BOOLEAN_TYPE)) | 5301 || coder == BOOLEAN_TYPE)) |
5025 { | 5302 { |
5026 tree ret; | 5303 tree ret; |
5027 bool save = in_late_binary_op; | 5304 bool save = in_late_binary_op; |
5028 if (codel == BOOLEAN_TYPE) | 5305 if (codel == BOOLEAN_TYPE || codel == COMPLEX_TYPE) |
5029 in_late_binary_op = true; | 5306 in_late_binary_op = true; |
5030 ret = convert_and_check (type, orig_rhs); | 5307 ret = convert_and_check (type, orig_rhs); |
5031 if (codel == BOOLEAN_TYPE) | 5308 if (codel == BOOLEAN_TYPE || codel == COMPLEX_TYPE) |
5032 in_late_binary_op = save; | 5309 in_late_binary_op = save; |
5033 return ret; | 5310 return ret; |
5034 } | 5311 } |
5035 | 5312 |
5036 /* Aggregates in different TUs might need conversion. */ | 5313 /* Aggregates in different TUs might need conversion. */ |
5037 if ((codel == RECORD_TYPE || codel == UNION_TYPE) | 5314 if ((codel == RECORD_TYPE || codel == UNION_TYPE) |
5038 && codel == coder | 5315 && codel == coder |
5039 && comptypes (type, rhstype)) | 5316 && comptypes (type, rhstype)) |
5040 return convert_and_check (type, rhs); | 5317 return convert_and_check (type, rhs); |
5041 | 5318 |
5042 /* Conversion to a transparent union from its member types. | 5319 /* Conversion to a transparent union or record from its member types. |
5043 This applies only to function arguments. */ | 5320 This applies only to function arguments. */ |
5044 if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type) | 5321 if (((codel == UNION_TYPE || codel == RECORD_TYPE) |
5322 && TYPE_TRANSPARENT_AGGR (type)) | |
5045 && errtype == ic_argpass) | 5323 && errtype == ic_argpass) |
5046 { | 5324 { |
5047 tree memb, marginal_memb = NULL_TREE; | 5325 tree memb, marginal_memb = NULL_TREE; |
5048 | 5326 |
5049 for (memb = TYPE_FIELDS (type); memb ; memb = TREE_CHAIN (memb)) | 5327 for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb)) |
5050 { | 5328 { |
5051 tree memb_type = TREE_TYPE (memb); | 5329 tree memb_type = TREE_TYPE (memb); |
5052 | 5330 |
5053 if (comptypes (TYPE_MAIN_VARIANT (memb_type), | 5331 if (comptypes (TYPE_MAIN_VARIANT (memb_type), |
5054 TYPE_MAIN_VARIANT (rhstype))) | 5332 TYPE_MAIN_VARIANT (rhstype))) |
5055 break; | 5333 break; |
5056 | 5334 |
5057 if (TREE_CODE (memb_type) != POINTER_TYPE) | 5335 if (TREE_CODE (memb_type) != POINTER_TYPE) |
5058 continue; | 5336 continue; |
5059 | 5337 |
5060 if (coder == POINTER_TYPE) | 5338 if (coder == POINTER_TYPE) |
5061 { | 5339 { |
5062 tree ttl = TREE_TYPE (memb_type); | 5340 tree ttl = TREE_TYPE (memb_type); |
5063 tree ttr = TREE_TYPE (rhstype); | 5341 tree ttr = TREE_TYPE (rhstype); |
5064 | 5342 |
5065 /* Any non-function converts to a [const][volatile] void * | 5343 /* Any non-function converts to a [const][volatile] void * |
5066 and vice versa; otherwise, targets must be the same. | 5344 and vice versa; otherwise, targets must be the same. |
5067 Meanwhile, the lhs target must have all the qualifiers of | 5345 Meanwhile, the lhs target must have all the qualifiers of |
5068 the rhs. */ | 5346 the rhs. */ |
5069 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) | 5347 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) |
5070 || comp_target_types (location, memb_type, rhstype)) | 5348 || comp_target_types (location, memb_type, rhstype)) |
5071 { | 5349 { |
5072 /* If this type won't generate any warnings, use it. */ | 5350 /* If this type won't generate any warnings, use it. */ |
5073 if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr) | 5351 if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr) |
5074 || ((TREE_CODE (ttr) == FUNCTION_TYPE | 5352 || ((TREE_CODE (ttr) == FUNCTION_TYPE |
5075 && TREE_CODE (ttl) == FUNCTION_TYPE) | 5353 && TREE_CODE (ttl) == FUNCTION_TYPE) |
5076 ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr)) | 5354 ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr)) |
5077 == TYPE_QUALS (ttr)) | 5355 == TYPE_QUALS (ttr)) |
5078 : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr)) | 5356 : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr)) |
5079 == TYPE_QUALS (ttl)))) | 5357 == TYPE_QUALS (ttl)))) |
5080 break; | 5358 break; |
5081 | 5359 |
5082 /* Keep looking for a better type, but remember this one. */ | 5360 /* Keep looking for a better type, but remember this one. */ |
5083 if (!marginal_memb) | 5361 if (!marginal_memb) |
5084 marginal_memb = memb; | 5362 marginal_memb = memb; |
5085 } | 5363 } |
5086 } | 5364 } |
5087 | 5365 |
5088 /* Can convert integer zero to any pointer type. */ | 5366 /* Can convert integer zero to any pointer type. */ |
5089 if (null_pointer_constant) | 5367 if (null_pointer_constant) |
5090 { | 5368 { |
5091 rhs = null_pointer_node; | 5369 rhs = null_pointer_node; |
5092 break; | 5370 break; |
5093 } | 5371 } |
5094 } | 5372 } |
5095 | 5373 |
5096 if (memb || marginal_memb) | 5374 if (memb || marginal_memb) |
5097 { | 5375 { |
5098 if (!memb) | 5376 if (!memb) |
5099 { | 5377 { |
5100 /* We have only a marginally acceptable member type; | 5378 /* We have only a marginally acceptable member type; |
5101 it needs a warning. */ | 5379 it needs a warning. */ |
5102 tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb)); | 5380 tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb)); |
5103 tree ttr = TREE_TYPE (rhstype); | 5381 tree ttr = TREE_TYPE (rhstype); |
5104 | 5382 |
5105 /* Const and volatile mean something different for function | 5383 /* Const and volatile mean something different for function |
5106 types, so the usual warnings are not appropriate. */ | 5384 types, so the usual warnings are not appropriate. */ |
5107 if (TREE_CODE (ttr) == FUNCTION_TYPE | 5385 if (TREE_CODE (ttr) == FUNCTION_TYPE |
5108 && TREE_CODE (ttl) == FUNCTION_TYPE) | 5386 && TREE_CODE (ttl) == FUNCTION_TYPE) |
5109 { | 5387 { |
5110 /* Because const and volatile on functions are | 5388 /* Because const and volatile on functions are |
5111 restrictions that say the function will not do | 5389 restrictions that say the function will not do |
5112 certain things, it is okay to use a const or volatile | 5390 certain things, it is okay to use a const or volatile |
5113 function where an ordinary one is wanted, but not | 5391 function where an ordinary one is wanted, but not |
5114 vice-versa. */ | 5392 vice-versa. */ |
5115 if (TYPE_QUALS_NO_ADDR_SPACE (ttl) | 5393 if (TYPE_QUALS_NO_ADDR_SPACE (ttl) |
5116 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr)) | 5394 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr)) |
5117 WARN_FOR_ASSIGNMENT (location, 0, | 5395 WARN_FOR_QUALIFIERS (location, 0, |
5118 G_("passing argument %d of %qE " | 5396 G_("passing argument %d of %qE " |
5119 "makes qualified function " | 5397 "makes %q#v qualified function " |
5120 "pointer from unqualified"), | 5398 "pointer from unqualified"), |
5121 G_("assignment makes qualified " | 5399 G_("assignment makes %q#v qualified " |
5122 "function pointer from " | 5400 "function pointer from " |
5123 "unqualified"), | 5401 "unqualified"), |
5124 G_("initialization makes qualified " | 5402 G_("initialization makes %q#v qualified " |
5125 "function pointer from " | 5403 "function pointer from " |
5126 "unqualified"), | 5404 "unqualified"), |
5127 G_("return makes qualified function " | 5405 G_("return makes %q#v qualified function " |
5128 "pointer from unqualified")); | 5406 "pointer from unqualified"), |
5129 } | 5407 TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr)); |
5130 else if (TYPE_QUALS_NO_ADDR_SPACE (ttr) | 5408 } |
5131 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl)) | 5409 else if (TYPE_QUALS_NO_ADDR_SPACE (ttr) |
5132 WARN_FOR_ASSIGNMENT (location, 0, | 5410 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl)) |
5133 G_("passing argument %d of %qE discards " | 5411 WARN_FOR_QUALIFIERS (location, 0, |
5134 "qualifiers from pointer target type"), | 5412 G_("passing argument %d of %qE discards " |
5135 G_("assignment discards qualifiers " | 5413 "%qv qualifier from pointer target type"), |
5136 "from pointer target type"), | 5414 G_("assignment discards %qv qualifier " |
5137 G_("initialization discards qualifiers " | 5415 "from pointer target type"), |
5138 "from pointer target type"), | 5416 G_("initialization discards %qv qualifier " |
5139 G_("return discards qualifiers from " | 5417 "from pointer target type"), |
5140 "pointer target type")); | 5418 G_("return discards %qv qualifier from " |
5141 | 5419 "pointer target type"), |
5142 memb = marginal_memb; | 5420 TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl)); |
5143 } | 5421 memb = marginal_memb; |
5144 | 5422 } |
5145 if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)) | 5423 |
5146 pedwarn (location, OPT_pedantic, | 5424 if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)) |
5147 "ISO C prohibits argument conversion to union type"); | 5425 pedwarn (location, OPT_pedantic, |
5148 | 5426 "ISO C prohibits argument conversion to union type"); |
5149 rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs); | 5427 |
5150 return build_constructor_single (type, memb, rhs); | 5428 rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs); |
5151 } | 5429 return build_constructor_single (type, memb, rhs); |
5430 } | |
5152 } | 5431 } |
5153 | 5432 |
5154 /* Conversions among pointers */ | 5433 /* Conversions among pointers */ |
5155 else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE) | 5434 else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE) |
5156 && (coder == codel)) | 5435 && (coder == codel)) |
5168 mvl = TYPE_MAIN_VARIANT (mvl); | 5447 mvl = TYPE_MAIN_VARIANT (mvl); |
5169 if (TREE_CODE (mvr) != ARRAY_TYPE) | 5448 if (TREE_CODE (mvr) != ARRAY_TYPE) |
5170 mvr = TYPE_MAIN_VARIANT (mvr); | 5449 mvr = TYPE_MAIN_VARIANT (mvr); |
5171 /* Opaque pointers are treated like void pointers. */ | 5450 /* Opaque pointers are treated like void pointers. */ |
5172 is_opaque_pointer = vector_targets_convertible_p (ttl, ttr); | 5451 is_opaque_pointer = vector_targets_convertible_p (ttl, ttr); |
5452 | |
5453 /* The Plan 9 compiler permits a pointer to a struct to be | |
5454 automatically converted into a pointer to an anonymous field | |
5455 within the struct. */ | |
5456 if (flag_plan9_extensions | |
5457 && (TREE_CODE (mvl) == RECORD_TYPE || TREE_CODE(mvl) == UNION_TYPE) | |
5458 && (TREE_CODE (mvr) == RECORD_TYPE || TREE_CODE(mvr) == UNION_TYPE) | |
5459 && mvl != mvr) | |
5460 { | |
5461 tree new_rhs = convert_to_anonymous_field (location, type, rhs); | |
5462 if (new_rhs != NULL_TREE) | |
5463 { | |
5464 rhs = new_rhs; | |
5465 rhstype = TREE_TYPE (rhs); | |
5466 coder = TREE_CODE (rhstype); | |
5467 ttr = TREE_TYPE (rhstype); | |
5468 mvr = TYPE_MAIN_VARIANT (ttr); | |
5469 } | |
5470 } | |
5173 | 5471 |
5174 /* C++ does not allow the implicit conversion void* -> T*. However, | 5472 /* C++ does not allow the implicit conversion void* -> T*. However, |
5175 for the purpose of reducing the number of false positives, we | 5473 for the purpose of reducing the number of false positives, we |
5176 tolerate the special case of | 5474 tolerate the special case of |
5177 | 5475 |
5248 | 5546 |
5249 /* Any non-function converts to a [const][volatile] void * | 5547 /* Any non-function converts to a [const][volatile] void * |
5250 and vice versa; otherwise, targets must be the same. | 5548 and vice versa; otherwise, targets must be the same. |
5251 Meanwhile, the lhs target must have all the qualifiers of the rhs. */ | 5549 Meanwhile, the lhs target must have all the qualifiers of the rhs. */ |
5252 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) | 5550 if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) |
5253 || (target_cmp = comp_target_types (location, type, rhstype)) | 5551 || (target_cmp = comp_target_types (location, type, rhstype)) |
5254 || is_opaque_pointer | 5552 || is_opaque_pointer |
5255 || (c_common_unsigned_type (mvl) | 5553 || (c_common_unsigned_type (mvl) |
5256 == c_common_unsigned_type (mvr))) | 5554 == c_common_unsigned_type (mvr))) |
5257 { | 5555 { |
5258 if (pedantic | 5556 if (pedantic |
5259 && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE) | 5557 && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE) |
5260 || | 5558 || |
5261 (VOID_TYPE_P (ttr) | 5559 (VOID_TYPE_P (ttr) |
5262 && !null_pointer_constant | 5560 && !null_pointer_constant |
5263 && TREE_CODE (ttl) == FUNCTION_TYPE))) | 5561 && TREE_CODE (ttl) == FUNCTION_TYPE))) |
5264 WARN_FOR_ASSIGNMENT (location, OPT_pedantic, | 5562 WARN_FOR_ASSIGNMENT (location, OPT_pedantic, |
5265 G_("ISO C forbids passing argument %d of " | 5563 G_("ISO C forbids passing argument %d of " |
5266 "%qE between function pointer " | 5564 "%qE between function pointer " |
5267 "and %<void *%>"), | 5565 "and %<void *%>"), |
5268 G_("ISO C forbids assignment between " | 5566 G_("ISO C forbids assignment between " |
5269 "function pointer and %<void *%>"), | 5567 "function pointer and %<void *%>"), |
5270 G_("ISO C forbids initialization between " | 5568 G_("ISO C forbids initialization between " |
5271 "function pointer and %<void *%>"), | 5569 "function pointer and %<void *%>"), |
5272 G_("ISO C forbids return between function " | 5570 G_("ISO C forbids return between function " |
5273 "pointer and %<void *%>")); | 5571 "pointer and %<void *%>")); |
5274 /* Const and volatile mean something different for function types, | 5572 /* Const and volatile mean something different for function types, |
5275 so the usual warnings are not appropriate. */ | 5573 so the usual warnings are not appropriate. */ |
5276 else if (TREE_CODE (ttr) != FUNCTION_TYPE | 5574 else if (TREE_CODE (ttr) != FUNCTION_TYPE |
5277 && TREE_CODE (ttl) != FUNCTION_TYPE) | 5575 && TREE_CODE (ttl) != FUNCTION_TYPE) |
5278 { | 5576 { |
5279 if (TYPE_QUALS_NO_ADDR_SPACE (ttr) | 5577 if (TYPE_QUALS_NO_ADDR_SPACE (ttr) |
5280 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl)) | 5578 & ~TYPE_QUALS_NO_ADDR_SPACE (ttl)) |
5281 { | 5579 { |
5282 /* Types differing only by the presence of the 'volatile' | 5580 WARN_FOR_QUALIFIERS (location, 0, |
5283 qualifier are acceptable if the 'volatile' has been added | 5581 G_("passing argument %d of %qE discards " |
5284 in by the Objective-C EH machinery. */ | 5582 "%qv qualifier from pointer target type"), |
5285 if (!objc_type_quals_match (ttl, ttr)) | 5583 G_("assignment discards %qv qualifier " |
5286 WARN_FOR_ASSIGNMENT (location, 0, | 5584 "from pointer target type"), |
5287 G_("passing argument %d of %qE discards " | 5585 G_("initialization discards %qv qualifier " |
5288 "qualifiers from pointer target type"), | 5586 "from pointer target type"), |
5289 G_("assignment discards qualifiers " | 5587 G_("return discards %qv qualifier from " |
5290 "from pointer target type"), | 5588 "pointer target type"), |
5291 G_("initialization discards qualifiers " | 5589 TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl)); |
5292 "from pointer target type"), | 5590 } |
5293 G_("return discards qualifiers from " | 5591 /* If this is not a case of ignoring a mismatch in signedness, |
5294 "pointer target type")); | 5592 no warning. */ |
5295 } | 5593 else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) |
5296 /* If this is not a case of ignoring a mismatch in signedness, | 5594 || target_cmp) |
5297 no warning. */ | 5595 ; |
5298 else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr) | 5596 /* If there is a mismatch, do warn. */ |
5299 || target_cmp) | 5597 else if (warn_pointer_sign) |
5300 ; | 5598 WARN_FOR_ASSIGNMENT (location, OPT_Wpointer_sign, |
5301 /* If there is a mismatch, do warn. */ | 5599 G_("pointer targets in passing argument " |
5302 else if (warn_pointer_sign) | 5600 "%d of %qE differ in signedness"), |
5303 WARN_FOR_ASSIGNMENT (location, OPT_Wpointer_sign, | 5601 G_("pointer targets in assignment " |
5304 G_("pointer targets in passing argument " | 5602 "differ in signedness"), |
5305 "%d of %qE differ in signedness"), | 5603 G_("pointer targets in initialization " |
5306 G_("pointer targets in assignment " | 5604 "differ in signedness"), |
5307 "differ in signedness"), | 5605 G_("pointer targets in return differ " |
5308 G_("pointer targets in initialization " | 5606 "in signedness")); |
5309 "differ in signedness"), | 5607 } |
5310 G_("pointer targets in return differ " | 5608 else if (TREE_CODE (ttl) == FUNCTION_TYPE |
5311 "in signedness")); | 5609 && TREE_CODE (ttr) == FUNCTION_TYPE) |
5312 } | 5610 { |
5313 else if (TREE_CODE (ttl) == FUNCTION_TYPE | 5611 /* Because const and volatile on functions are restrictions |
5314 && TREE_CODE (ttr) == FUNCTION_TYPE) | 5612 that say the function will not do certain things, |
5315 { | 5613 it is okay to use a const or volatile function |
5316 /* Because const and volatile on functions are restrictions | 5614 where an ordinary one is wanted, but not vice-versa. */ |
5317 that say the function will not do certain things, | 5615 if (TYPE_QUALS_NO_ADDR_SPACE (ttl) |
5318 it is okay to use a const or volatile function | 5616 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr)) |
5319 where an ordinary one is wanted, but not vice-versa. */ | 5617 WARN_FOR_QUALIFIERS (location, 0, |
5320 if (TYPE_QUALS_NO_ADDR_SPACE (ttl) | 5618 G_("passing argument %d of %qE makes " |
5321 & ~TYPE_QUALS_NO_ADDR_SPACE (ttr)) | 5619 "%q#v qualified function pointer " |
5322 WARN_FOR_ASSIGNMENT (location, 0, | 5620 "from unqualified"), |
5323 G_("passing argument %d of %qE makes " | 5621 G_("assignment makes %q#v qualified function " |
5324 "qualified function pointer " | 5622 "pointer from unqualified"), |
5325 "from unqualified"), | 5623 G_("initialization makes %q#v qualified " |
5326 G_("assignment makes qualified function " | 5624 "function pointer from unqualified"), |
5327 "pointer from unqualified"), | 5625 G_("return makes %q#v qualified function " |
5328 G_("initialization makes qualified " | 5626 "pointer from unqualified"), |
5329 "function pointer from unqualified"), | 5627 TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr)); |
5330 G_("return makes qualified function " | 5628 } |
5331 "pointer from unqualified")); | 5629 } |
5332 } | |
5333 } | |
5334 else | 5630 else |
5335 /* Avoid warning about the volatile ObjC EH puts on decls. */ | 5631 /* Avoid warning about the volatile ObjC EH puts on decls. */ |
5336 if (!objc_ok) | 5632 if (!objc_ok) |
5337 WARN_FOR_ASSIGNMENT (location, 0, | 5633 WARN_FOR_ASSIGNMENT (location, 0, |
5338 G_("passing argument %d of %qE from " | 5634 G_("passing argument %d of %qE from " |
5635 *d++ = '\0'; | 5931 *d++ = '\0'; |
5636 return buffer; | 5932 return buffer; |
5637 } | 5933 } |
5638 | 5934 |
5639 /* Issue an error message for a bad initializer component. | 5935 /* Issue an error message for a bad initializer component. |
5640 MSGID identifies the message. | 5936 GMSGID identifies the message. |
5641 The component name is taken from the spelling stack. */ | 5937 The component name is taken from the spelling stack. */ |
5642 | 5938 |
5643 void | 5939 void |
5644 error_init (const char *msgid) | 5940 error_init (const char *gmsgid) |
5645 { | 5941 { |
5646 char *ofwhat; | 5942 char *ofwhat; |
5647 | 5943 |
5648 error ("%s", _(msgid)); | 5944 /* The gmsgid may be a format string with %< and %>. */ |
5945 error (gmsgid); | |
5649 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); | 5946 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); |
5650 if (*ofwhat) | 5947 if (*ofwhat) |
5651 error ("(near initialization for %qs)", ofwhat); | 5948 error ("(near initialization for %qs)", ofwhat); |
5652 } | 5949 } |
5653 | 5950 |
5654 /* Issue a pedantic warning for a bad initializer component. OPT is | 5951 /* Issue a pedantic warning for a bad initializer component. OPT is |
5655 the option OPT_* (from options.h) controlling this warning or 0 if | 5952 the option OPT_* (from options.h) controlling this warning or 0 if |
5656 it is unconditionally given. MSGID identifies the message. The | 5953 it is unconditionally given. GMSGID identifies the message. The |
5657 component name is taken from the spelling stack. */ | 5954 component name is taken from the spelling stack. */ |
5658 | 5955 |
5659 void | 5956 void |
5660 pedwarn_init (location_t location, int opt, const char *msgid) | 5957 pedwarn_init (location_t location, int opt, const char *gmsgid) |
5661 { | 5958 { |
5662 char *ofwhat; | 5959 char *ofwhat; |
5663 | 5960 |
5664 pedwarn (location, opt, "%s", _(msgid)); | 5961 /* The gmsgid may be a format string with %< and %>. */ |
5962 pedwarn (location, opt, gmsgid); | |
5665 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); | 5963 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); |
5666 if (*ofwhat) | 5964 if (*ofwhat) |
5667 pedwarn (location, opt, "(near initialization for %qs)", ofwhat); | 5965 pedwarn (location, opt, "(near initialization for %qs)", ofwhat); |
5668 } | 5966 } |
5669 | 5967 |
5670 /* Issue a warning for a bad initializer component. | 5968 /* Issue a warning for a bad initializer component. |
5671 | 5969 |
5672 OPT is the OPT_W* value corresponding to the warning option that | 5970 OPT is the OPT_W* value corresponding to the warning option that |
5673 controls this warning. MSGID identifies the message. The | 5971 controls this warning. GMSGID identifies the message. The |
5674 component name is taken from the spelling stack. */ | 5972 component name is taken from the spelling stack. */ |
5675 | 5973 |
5676 static void | 5974 static void |
5677 warning_init (int opt, const char *msgid) | 5975 warning_init (int opt, const char *gmsgid) |
5678 { | 5976 { |
5679 char *ofwhat; | 5977 char *ofwhat; |
5680 | 5978 |
5681 warning (opt, "%s", _(msgid)); | 5979 /* The gmsgid may be a format string with %< and %>. */ |
5980 warning (opt, gmsgid); | |
5682 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); | 5981 ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); |
5683 if (*ofwhat) | 5982 if (*ofwhat) |
5684 warning (opt, "(near initialization for %qs)", ofwhat); | 5983 warning (opt, "(near initialization for %qs)", ofwhat); |
5685 } | 5984 } |
5686 | 5985 |
6327 || TREE_CODE (constructor_type) == UNION_TYPE) | 6626 || TREE_CODE (constructor_type) == UNION_TYPE) |
6328 { | 6627 { |
6329 constructor_fields = TYPE_FIELDS (constructor_type); | 6628 constructor_fields = TYPE_FIELDS (constructor_type); |
6330 /* Skip any nameless bit fields at the beginning. */ | 6629 /* Skip any nameless bit fields at the beginning. */ |
6331 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields) | 6630 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields) |
6332 && DECL_NAME (constructor_fields) == 0) | 6631 && DECL_NAME (constructor_fields) == 0) |
6333 constructor_fields = TREE_CHAIN (constructor_fields); | 6632 constructor_fields = DECL_CHAIN (constructor_fields); |
6334 | 6633 |
6335 constructor_unfilled_fields = constructor_fields; | 6634 constructor_unfilled_fields = constructor_fields; |
6336 constructor_bit_index = bitsize_zero_node; | 6635 constructor_bit_index = bitsize_zero_node; |
6337 } | 6636 } |
6338 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 6637 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
6339 { | 6638 { |
6340 if (TYPE_DOMAIN (constructor_type)) | 6639 if (TYPE_DOMAIN (constructor_type)) |
6341 { | 6640 { |
6342 constructor_max_index | 6641 constructor_max_index |
6343 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)); | 6642 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)); |
6344 | 6643 |
6345 /* Detect non-empty initializations of zero-length arrays. */ | 6644 /* Detect non-empty initializations of zero-length arrays. */ |
6346 if (constructor_max_index == NULL_TREE | 6645 if (constructor_max_index == NULL_TREE |
6347 && TYPE_SIZE (constructor_type)) | 6646 && TYPE_SIZE (constructor_type)) |
6348 constructor_max_index = build_int_cst (NULL_TREE, -1); | 6647 constructor_max_index = integer_minus_one_node; |
6349 | 6648 |
6350 /* constructor_max_index needs to be an INTEGER_CST. Attempts | 6649 /* constructor_max_index needs to be an INTEGER_CST. Attempts |
6351 to initialize VLAs will cause a proper error; avoid tree | 6650 to initialize VLAs will cause a proper error; avoid tree |
6352 checking errors as well by setting a safe value. */ | 6651 checking errors as well by setting a safe value. */ |
6353 if (constructor_max_index | 6652 if (constructor_max_index |
6354 && TREE_CODE (constructor_max_index) != INTEGER_CST) | 6653 && TREE_CODE (constructor_max_index) != INTEGER_CST) |
6355 constructor_max_index = build_int_cst (NULL_TREE, -1); | 6654 constructor_max_index = integer_minus_one_node; |
6356 | 6655 |
6357 constructor_index | 6656 constructor_index |
6358 = convert (bitsizetype, | 6657 = convert (bitsizetype, |
6359 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); | 6658 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); |
6360 } | 6659 } |
6361 else | 6660 else |
6362 { | 6661 { |
6363 constructor_index = bitsize_zero_node; | 6662 constructor_index = bitsize_zero_node; |
6364 constructor_max_index = NULL_TREE; | 6663 constructor_max_index = NULL_TREE; |
6365 } | 6664 } |
6386 If this is for an explicit set of braces, IMPLICIT is 0. | 6685 If this is for an explicit set of braces, IMPLICIT is 0. |
6387 If it is because the next element belongs at a lower level, | 6686 If it is because the next element belongs at a lower level, |
6388 IMPLICIT is 1 (or 2 if the push is because of designator list). */ | 6687 IMPLICIT is 1 (or 2 if the push is because of designator list). */ |
6389 | 6688 |
6390 void | 6689 void |
6391 push_init_level (int implicit) | 6690 push_init_level (int implicit, struct obstack * braced_init_obstack) |
6392 { | 6691 { |
6393 struct constructor_stack *p; | 6692 struct constructor_stack *p; |
6394 tree value = NULL_TREE; | 6693 tree value = NULL_TREE; |
6395 | 6694 |
6396 /* If we've exhausted any levels that didn't have braces, | 6695 /* If we've exhausted any levels that didn't have braces, |
6400 infinite cycle of popping a level and immediately recreating | 6699 infinite cycle of popping a level and immediately recreating |
6401 it. */ | 6700 it. */ |
6402 if (implicit != 1) | 6701 if (implicit != 1) |
6403 { | 6702 { |
6404 while (constructor_stack->implicit) | 6703 while (constructor_stack->implicit) |
6405 { | 6704 { |
6406 if ((TREE_CODE (constructor_type) == RECORD_TYPE | 6705 if ((TREE_CODE (constructor_type) == RECORD_TYPE |
6407 || TREE_CODE (constructor_type) == UNION_TYPE) | 6706 || TREE_CODE (constructor_type) == UNION_TYPE) |
6408 && constructor_fields == 0) | 6707 && constructor_fields == 0) |
6409 process_init_element (pop_init_level (1), true); | 6708 process_init_element (pop_init_level (1, braced_init_obstack), |
6410 else if (TREE_CODE (constructor_type) == ARRAY_TYPE | 6709 true, braced_init_obstack); |
6411 && constructor_max_index | 6710 else if (TREE_CODE (constructor_type) == ARRAY_TYPE |
6412 && tree_int_cst_lt (constructor_max_index, | 6711 && constructor_max_index |
6413 constructor_index)) | 6712 && tree_int_cst_lt (constructor_max_index, |
6414 process_init_element (pop_init_level (1), true); | 6713 constructor_index)) |
6415 else | 6714 process_init_element (pop_init_level (1, braced_init_obstack), |
6416 break; | 6715 true, braced_init_obstack); |
6417 } | 6716 else |
6717 break; | |
6718 } | |
6418 } | 6719 } |
6419 | 6720 |
6420 /* Unless this is an explicit brace, we need to preserve previous | 6721 /* Unless this is an explicit brace, we need to preserve previous |
6421 content if any. */ | 6722 content if any. */ |
6422 if (implicit) | 6723 if (implicit) |
6423 { | 6724 { |
6424 if ((TREE_CODE (constructor_type) == RECORD_TYPE | 6725 if ((TREE_CODE (constructor_type) == RECORD_TYPE |
6425 || TREE_CODE (constructor_type) == UNION_TYPE) | 6726 || TREE_CODE (constructor_type) == UNION_TYPE) |
6426 && constructor_fields) | 6727 && constructor_fields) |
6427 value = find_init_member (constructor_fields); | 6728 value = find_init_member (constructor_fields, braced_init_obstack); |
6428 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 6729 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
6429 value = find_init_member (constructor_index); | 6730 value = find_init_member (constructor_index, braced_init_obstack); |
6430 } | 6731 } |
6431 | 6732 |
6432 p = XNEW (struct constructor_stack); | 6733 p = XNEW (struct constructor_stack); |
6433 p->type = constructor_type; | 6734 p->type = constructor_type; |
6434 p->fields = constructor_fields; | 6735 p->fields = constructor_fields; |
6508 constructor_constant = TREE_CONSTANT (value); | 6809 constructor_constant = TREE_CONSTANT (value); |
6509 constructor_simple = TREE_STATIC (value); | 6810 constructor_simple = TREE_STATIC (value); |
6510 constructor_nonconst = CONSTRUCTOR_NON_CONST (value); | 6811 constructor_nonconst = CONSTRUCTOR_NON_CONST (value); |
6511 constructor_elements = CONSTRUCTOR_ELTS (value); | 6812 constructor_elements = CONSTRUCTOR_ELTS (value); |
6512 if (!VEC_empty (constructor_elt, constructor_elements) | 6813 if (!VEC_empty (constructor_elt, constructor_elements) |
6513 && (TREE_CODE (constructor_type) == RECORD_TYPE | 6814 && (TREE_CODE (constructor_type) == RECORD_TYPE |
6514 || TREE_CODE (constructor_type) == ARRAY_TYPE)) | 6815 || TREE_CODE (constructor_type) == ARRAY_TYPE)) |
6515 set_nonincremental_init (); | 6816 set_nonincremental_init (braced_init_obstack); |
6516 } | 6817 } |
6517 | 6818 |
6518 if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned) | 6819 if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned) |
6519 { | 6820 { |
6520 missing_braces_mentioned = 1; | 6821 missing_braces_mentioned = 1; |
6525 || TREE_CODE (constructor_type) == UNION_TYPE) | 6826 || TREE_CODE (constructor_type) == UNION_TYPE) |
6526 { | 6827 { |
6527 constructor_fields = TYPE_FIELDS (constructor_type); | 6828 constructor_fields = TYPE_FIELDS (constructor_type); |
6528 /* Skip any nameless bit fields at the beginning. */ | 6829 /* Skip any nameless bit fields at the beginning. */ |
6529 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields) | 6830 while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields) |
6530 && DECL_NAME (constructor_fields) == 0) | 6831 && DECL_NAME (constructor_fields) == 0) |
6531 constructor_fields = TREE_CHAIN (constructor_fields); | 6832 constructor_fields = DECL_CHAIN (constructor_fields); |
6532 | 6833 |
6533 constructor_unfilled_fields = constructor_fields; | 6834 constructor_unfilled_fields = constructor_fields; |
6534 constructor_bit_index = bitsize_zero_node; | 6835 constructor_bit_index = bitsize_zero_node; |
6535 } | 6836 } |
6536 else if (TREE_CODE (constructor_type) == VECTOR_TYPE) | 6837 else if (TREE_CODE (constructor_type) == VECTOR_TYPE) |
6542 constructor_unfilled_index = constructor_index; | 6843 constructor_unfilled_index = constructor_index; |
6543 } | 6844 } |
6544 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 6845 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
6545 { | 6846 { |
6546 if (TYPE_DOMAIN (constructor_type)) | 6847 if (TYPE_DOMAIN (constructor_type)) |
6547 { | 6848 { |
6548 constructor_max_index | 6849 constructor_max_index |
6549 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)); | 6850 = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)); |
6550 | 6851 |
6551 /* Detect non-empty initializations of zero-length arrays. */ | 6852 /* Detect non-empty initializations of zero-length arrays. */ |
6552 if (constructor_max_index == NULL_TREE | 6853 if (constructor_max_index == NULL_TREE |
6553 && TYPE_SIZE (constructor_type)) | 6854 && TYPE_SIZE (constructor_type)) |
6554 constructor_max_index = build_int_cst (NULL_TREE, -1); | 6855 constructor_max_index = integer_minus_one_node; |
6555 | 6856 |
6556 /* constructor_max_index needs to be an INTEGER_CST. Attempts | 6857 /* constructor_max_index needs to be an INTEGER_CST. Attempts |
6557 to initialize VLAs will cause a proper error; avoid tree | 6858 to initialize VLAs will cause a proper error; avoid tree |
6558 checking errors as well by setting a safe value. */ | 6859 checking errors as well by setting a safe value. */ |
6559 if (constructor_max_index | 6860 if (constructor_max_index |
6560 && TREE_CODE (constructor_max_index) != INTEGER_CST) | 6861 && TREE_CODE (constructor_max_index) != INTEGER_CST) |
6561 constructor_max_index = build_int_cst (NULL_TREE, -1); | 6862 constructor_max_index = integer_minus_one_node; |
6562 | 6863 |
6563 constructor_index | 6864 constructor_index |
6564 = convert (bitsizetype, | 6865 = convert (bitsizetype, |
6565 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); | 6866 TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); |
6566 } | 6867 } |
6567 else | 6868 else |
6568 constructor_index = bitsize_zero_node; | 6869 constructor_index = bitsize_zero_node; |
6569 | 6870 |
6570 constructor_unfilled_index = constructor_index; | 6871 constructor_unfilled_index = constructor_index; |
6571 if (value && TREE_CODE (value) == STRING_CST) | 6872 if (value && TREE_CODE (value) == STRING_CST) |
6572 { | 6873 { |
6573 /* We need to split the char/wchar array into individual | 6874 /* We need to split the char/wchar array into individual |
6574 characters, so that we don't have to special case it | 6875 characters, so that we don't have to special case it |
6575 everywhere. */ | 6876 everywhere. */ |
6576 set_nonincremental_init_from_string (value); | 6877 set_nonincremental_init_from_string (value, braced_init_obstack); |
6577 } | 6878 } |
6578 } | 6879 } |
6579 else | 6880 else |
6580 { | 6881 { |
6581 if (constructor_type != error_mark_node) | 6882 if (constructor_type != error_mark_node) |
6582 warning_init (0, "braces around scalar initializer"); | 6883 warning_init (0, "braces around scalar initializer"); |
6595 but return error_mark_node as the value from the outermost level | 6896 but return error_mark_node as the value from the outermost level |
6596 (that's what we want to put in DECL_INITIAL). | 6897 (that's what we want to put in DECL_INITIAL). |
6597 Otherwise, return a CONSTRUCTOR expression as the value. */ | 6898 Otherwise, return a CONSTRUCTOR expression as the value. */ |
6598 | 6899 |
6599 struct c_expr | 6900 struct c_expr |
6600 pop_init_level (int implicit) | 6901 pop_init_level (int implicit, struct obstack * braced_init_obstack) |
6601 { | 6902 { |
6602 struct constructor_stack *p; | 6903 struct constructor_stack *p; |
6603 struct c_expr ret; | 6904 struct c_expr ret; |
6604 ret.value = 0; | 6905 ret.value = 0; |
6605 ret.original_code = ERROR_MARK; | 6906 ret.original_code = ERROR_MARK; |
6608 if (implicit == 0) | 6909 if (implicit == 0) |
6609 { | 6910 { |
6610 /* When we come to an explicit close brace, | 6911 /* When we come to an explicit close brace, |
6611 pop any inner levels that didn't have explicit braces. */ | 6912 pop any inner levels that didn't have explicit braces. */ |
6612 while (constructor_stack->implicit) | 6913 while (constructor_stack->implicit) |
6613 process_init_element (pop_init_level (1), true); | 6914 { |
6614 | 6915 process_init_element (pop_init_level (1, braced_init_obstack), |
6916 true, braced_init_obstack); | |
6917 } | |
6615 gcc_assert (!constructor_range_stack); | 6918 gcc_assert (!constructor_range_stack); |
6616 } | 6919 } |
6617 | 6920 |
6618 /* Now output all pending elements. */ | 6921 /* Now output all pending elements. */ |
6619 constructor_incremental = 1; | 6922 constructor_incremental = 1; |
6620 output_pending_init_elements (1); | 6923 output_pending_init_elements (1, braced_init_obstack); |
6621 | 6924 |
6622 p = constructor_stack; | 6925 p = constructor_stack; |
6623 | 6926 |
6624 /* Error for initializing a flexible array member, or a zero-length | 6927 /* Error for initializing a flexible array member, or a zero-length |
6625 array member in an inappropriate context. */ | 6928 array member in an inappropriate context. */ |
6631 /* Silently discard empty initializations. The parser will | 6934 /* Silently discard empty initializations. The parser will |
6632 already have pedwarned for empty brackets. */ | 6935 already have pedwarned for empty brackets. */ |
6633 if (integer_zerop (constructor_unfilled_index)) | 6936 if (integer_zerop (constructor_unfilled_index)) |
6634 constructor_type = NULL_TREE; | 6937 constructor_type = NULL_TREE; |
6635 else | 6938 else |
6636 { | 6939 { |
6637 gcc_assert (!TYPE_SIZE (constructor_type)); | 6940 gcc_assert (!TYPE_SIZE (constructor_type)); |
6638 | 6941 |
6639 if (constructor_depth > 2) | 6942 if (constructor_depth > 2) |
6640 error_init ("initialization of flexible array member in a nested context"); | 6943 error_init ("initialization of flexible array member in a nested context"); |
6641 else | 6944 else |
6642 pedwarn_init (input_location, OPT_pedantic, | 6945 pedwarn_init (input_location, OPT_pedantic, |
6643 "initialization of a flexible array member"); | 6946 "initialization of a flexible array member"); |
6644 | 6947 |
6645 /* We have already issued an error message for the existence | 6948 |
6646 of a flexible array member not at the end of the structure. | 6949 /* We have already issued an error message for the existence |
6647 Discard the initializer so that we do not die later. */ | 6950 of a flexible array member not at the end of the structure. |
6648 if (TREE_CHAIN (constructor_fields) != NULL_TREE) | 6951 Discard the initializer so that we do not die later. */ |
6649 constructor_type = NULL_TREE; | 6952 if (DECL_CHAIN (constructor_fields) != NULL_TREE) |
6650 } | 6953 constructor_type = NULL_TREE; |
6954 } | |
6651 } | 6955 } |
6652 | 6956 |
6653 /* Warn when some struct elements are implicitly initialized to zero. */ | 6957 /* Warn when some struct elements are implicitly initialized to zero. */ |
6654 if (warn_missing_field_initializers | 6958 if (warn_missing_field_initializers |
6655 && constructor_type | 6959 && constructor_type |
6656 && TREE_CODE (constructor_type) == RECORD_TYPE | 6960 && TREE_CODE (constructor_type) == RECORD_TYPE |
6657 && constructor_unfilled_fields) | 6961 && constructor_unfilled_fields) |
6658 { | 6962 { |
6659 /* Do not warn for flexible array members or zero-length arrays. */ | 6963 /* Do not warn for flexible array members or zero-length arrays. */ |
6660 while (constructor_unfilled_fields | 6964 while (constructor_unfilled_fields |
6661 && (!DECL_SIZE (constructor_unfilled_fields) | 6965 && (!DECL_SIZE (constructor_unfilled_fields) |
6662 || integer_zerop (DECL_SIZE (constructor_unfilled_fields)))) | 6966 || integer_zerop (DECL_SIZE (constructor_unfilled_fields)))) |
6663 constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields); | 6967 constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields); |
6664 | 6968 |
6665 /* Do not warn if this level of the initializer uses member | 6969 /* Do not warn if this level of the initializer uses member |
6666 designators; it is likely to be deliberate. */ | 6970 designators; it is likely to be deliberate. */ |
6667 if (constructor_unfilled_fields && !constructor_designated) | 6971 if (constructor_unfilled_fields && !constructor_designated) |
6668 { | 6972 { |
6669 push_member_name (constructor_unfilled_fields); | 6973 push_member_name (constructor_unfilled_fields); |
6670 warning_init (OPT_Wmissing_field_initializers, | 6974 warning_init (OPT_Wmissing_field_initializers, |
6671 "missing initializer"); | 6975 "missing initializer"); |
6672 RESTORE_SPELLING_DEPTH (constructor_depth); | 6976 RESTORE_SPELLING_DEPTH (constructor_depth); |
6673 } | 6977 } |
6674 } | 6978 } |
6675 | 6979 |
6756 | 7060 |
6757 /* Common handling for both array range and field name designators. | 7061 /* Common handling for both array range and field name designators. |
6758 ARRAY argument is nonzero for array ranges. Returns zero for success. */ | 7062 ARRAY argument is nonzero for array ranges. Returns zero for success. */ |
6759 | 7063 |
6760 static int | 7064 static int |
6761 set_designator (int array) | 7065 set_designator (int array, struct obstack * braced_init_obstack) |
6762 { | 7066 { |
6763 tree subtype; | 7067 tree subtype; |
6764 enum tree_code subcode; | 7068 enum tree_code subcode; |
6765 | 7069 |
6766 /* Don't die if an entire brace-pair level is superfluous | 7070 /* Don't die if an entire brace-pair level is superfluous |
6778 gcc_assert (!constructor_range_stack); | 7082 gcc_assert (!constructor_range_stack); |
6779 | 7083 |
6780 /* Designator list starts at the level of closest explicit | 7084 /* Designator list starts at the level of closest explicit |
6781 braces. */ | 7085 braces. */ |
6782 while (constructor_stack->implicit) | 7086 while (constructor_stack->implicit) |
6783 process_init_element (pop_init_level (1), true); | 7087 { |
7088 process_init_element (pop_init_level (1, braced_init_obstack), | |
7089 true, braced_init_obstack); | |
7090 } | |
6784 constructor_designated = 1; | 7091 constructor_designated = 1; |
6785 return 0; | 7092 return 0; |
6786 } | 7093 } |
6787 | 7094 |
6788 switch (TREE_CODE (constructor_type)) | 7095 switch (TREE_CODE (constructor_type)) |
6811 error_init ("field name not in record or union initializer"); | 7118 error_init ("field name not in record or union initializer"); |
6812 return 1; | 7119 return 1; |
6813 } | 7120 } |
6814 | 7121 |
6815 constructor_designated = 1; | 7122 constructor_designated = 1; |
6816 push_init_level (2); | 7123 push_init_level (2, braced_init_obstack); |
6817 return 0; | 7124 return 0; |
6818 } | 7125 } |
6819 | 7126 |
6820 /* If there are range designators in designator list, push a new designator | 7127 /* If there are range designators in designator list, push a new designator |
6821 to constructor_range_stack. RANGE_END is end of such stack range or | 7128 to constructor_range_stack. RANGE_END is end of such stack range or |
6822 NULL_TREE if there is no range designator at this level. */ | 7129 NULL_TREE if there is no range designator at this level. */ |
6823 | 7130 |
6824 static void | 7131 static void |
6825 push_range_stack (tree range_end) | 7132 push_range_stack (tree range_end, struct obstack * braced_init_obstack) |
6826 { | 7133 { |
6827 struct constructor_range_stack *p; | 7134 struct constructor_range_stack *p; |
6828 | 7135 |
6829 p = GGC_NEW (struct constructor_range_stack); | 7136 p = (struct constructor_range_stack *) |
7137 obstack_alloc (braced_init_obstack, | |
7138 sizeof (struct constructor_range_stack)); | |
6830 p->prev = constructor_range_stack; | 7139 p->prev = constructor_range_stack; |
6831 p->next = 0; | 7140 p->next = 0; |
6832 p->fields = constructor_fields; | 7141 p->fields = constructor_fields; |
6833 p->range_start = constructor_index; | 7142 p->range_start = constructor_index; |
6834 p->index = constructor_index; | 7143 p->index = constructor_index; |
6842 /* Within an array initializer, specify the next index to be initialized. | 7151 /* Within an array initializer, specify the next index to be initialized. |
6843 FIRST is that index. If LAST is nonzero, then initialize a range | 7152 FIRST is that index. If LAST is nonzero, then initialize a range |
6844 of indices, running from FIRST through LAST. */ | 7153 of indices, running from FIRST through LAST. */ |
6845 | 7154 |
6846 void | 7155 void |
6847 set_init_index (tree first, tree last) | 7156 set_init_index (tree first, tree last, |
6848 { | 7157 struct obstack * braced_init_obstack) |
6849 if (set_designator (1)) | 7158 { |
7159 if (set_designator (1, braced_init_obstack)) | |
6850 return; | 7160 return; |
6851 | 7161 |
6852 designator_erroneous = 1; | 7162 designator_erroneous = 1; |
6853 | 7163 |
6854 if (!INTEGRAL_TYPE_P (TREE_TYPE (first)) | 7164 if (!INTEGRAL_TYPE_P (TREE_TYPE (first)) |
6916 } | 7226 } |
6917 | 7227 |
6918 designator_depth++; | 7228 designator_depth++; |
6919 designator_erroneous = 0; | 7229 designator_erroneous = 0; |
6920 if (constructor_range_stack || last) | 7230 if (constructor_range_stack || last) |
6921 push_range_stack (last); | 7231 push_range_stack (last, braced_init_obstack); |
6922 } | 7232 } |
6923 } | 7233 } |
6924 | 7234 |
6925 /* Within a struct initializer, specify the next field to be initialized. */ | 7235 /* Within a struct initializer, specify the next field to be initialized. */ |
6926 | 7236 |
6927 void | 7237 void |
6928 set_init_label (tree fieldname) | 7238 set_init_label (tree fieldname, struct obstack * braced_init_obstack) |
6929 { | 7239 { |
6930 tree tail; | 7240 tree field; |
6931 | 7241 |
6932 if (set_designator (0)) | 7242 if (set_designator (0, braced_init_obstack)) |
6933 return; | 7243 return; |
6934 | 7244 |
6935 designator_erroneous = 1; | 7245 designator_erroneous = 1; |
6936 | 7246 |
6937 if (TREE_CODE (constructor_type) != RECORD_TYPE | 7247 if (TREE_CODE (constructor_type) != RECORD_TYPE |
6939 { | 7249 { |
6940 error_init ("field name not in record or union initializer"); | 7250 error_init ("field name not in record or union initializer"); |
6941 return; | 7251 return; |
6942 } | 7252 } |
6943 | 7253 |
6944 for (tail = TYPE_FIELDS (constructor_type); tail; | 7254 field = lookup_field (constructor_type, fieldname); |
6945 tail = TREE_CHAIN (tail)) | 7255 |
6946 { | 7256 if (field == 0) |
6947 if (DECL_NAME (tail) == fieldname) | |
6948 break; | |
6949 } | |
6950 | |
6951 if (tail == 0) | |
6952 error ("unknown field %qE specified in initializer", fieldname); | 7257 error ("unknown field %qE specified in initializer", fieldname); |
6953 else | 7258 else |
6954 { | 7259 do |
6955 constructor_fields = tail; | 7260 { |
6956 designator_depth++; | 7261 constructor_fields = TREE_VALUE (field); |
6957 designator_erroneous = 0; | 7262 designator_depth++; |
6958 if (constructor_range_stack) | 7263 designator_erroneous = 0; |
6959 push_range_stack (NULL_TREE); | 7264 if (constructor_range_stack) |
6960 } | 7265 push_range_stack (NULL_TREE, braced_init_obstack); |
6961 } | 7266 field = TREE_CHAIN (field); |
6962 | 7267 if (field) |
7268 { | |
7269 if (set_designator (0, braced_init_obstack)) | |
7270 return; | |
7271 } | |
7272 } | |
7273 while (field != NULL_TREE); | |
7274 | |
7275 } | |
7276 | |
6963 /* Add a new initializer to the tree of pending initializers. PURPOSE | 7277 /* Add a new initializer to the tree of pending initializers. PURPOSE |
6964 identifies the initializer, either array index or field in a structure. | 7278 identifies the initializer, either array index or field in a structure. |
6965 VALUE is the value of that index or field. If ORIGTYPE is not | 7279 VALUE is the value of that index or field. If ORIGTYPE is not |
6966 NULL_TREE, it is the original type of VALUE. | 7280 NULL_TREE, it is the original type of VALUE. |
6967 | 7281 |
6969 the new initializer has been merged with the existing one | 7283 the new initializer has been merged with the existing one |
6970 and thus no warnings should be emitted about overriding an | 7284 and thus no warnings should be emitted about overriding an |
6971 existing initializer. */ | 7285 existing initializer. */ |
6972 | 7286 |
6973 static void | 7287 static void |
6974 add_pending_init (tree purpose, tree value, tree origtype, bool implicit) | 7288 add_pending_init (tree purpose, tree value, tree origtype, bool implicit, |
7289 struct obstack * braced_init_obstack) | |
6975 { | 7290 { |
6976 struct init_node *p, **q, *r; | 7291 struct init_node *p, **q, *r; |
6977 | 7292 |
6978 q = &constructor_pending_elts; | 7293 q = &constructor_pending_elts; |
6979 p = 0; | 7294 p = 0; |
7028 return; | 7343 return; |
7029 } | 7344 } |
7030 } | 7345 } |
7031 } | 7346 } |
7032 | 7347 |
7033 r = GGC_NEW (struct init_node); | 7348 r = (struct init_node *) obstack_alloc (braced_init_obstack, |
7349 sizeof (struct init_node)); | |
7034 r->purpose = purpose; | 7350 r->purpose = purpose; |
7035 r->value = value; | 7351 r->value = value; |
7036 r->origtype = origtype; | 7352 r->origtype = origtype; |
7037 | 7353 |
7038 *q = r; | 7354 *q = r; |
7197 } | 7513 } |
7198 | 7514 |
7199 /* Build AVL tree from a sorted chain. */ | 7515 /* Build AVL tree from a sorted chain. */ |
7200 | 7516 |
7201 static void | 7517 static void |
7202 set_nonincremental_init (void) | 7518 set_nonincremental_init (struct obstack * braced_init_obstack) |
7203 { | 7519 { |
7204 unsigned HOST_WIDE_INT ix; | 7520 unsigned HOST_WIDE_INT ix; |
7205 tree index, value; | 7521 tree index, value; |
7206 | 7522 |
7207 if (TREE_CODE (constructor_type) != RECORD_TYPE | 7523 if (TREE_CODE (constructor_type) != RECORD_TYPE |
7208 && TREE_CODE (constructor_type) != ARRAY_TYPE) | 7524 && TREE_CODE (constructor_type) != ARRAY_TYPE) |
7209 return; | 7525 return; |
7210 | 7526 |
7211 FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value) | 7527 FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value) |
7212 add_pending_init (index, value, NULL_TREE, false); | 7528 { |
7529 add_pending_init (index, value, NULL_TREE, false, | |
7530 braced_init_obstack); | |
7531 } | |
7213 constructor_elements = 0; | 7532 constructor_elements = 0; |
7214 if (TREE_CODE (constructor_type) == RECORD_TYPE) | 7533 if (TREE_CODE (constructor_type) == RECORD_TYPE) |
7215 { | 7534 { |
7216 constructor_unfilled_fields = TYPE_FIELDS (constructor_type); | 7535 constructor_unfilled_fields = TYPE_FIELDS (constructor_type); |
7217 /* Skip any nameless bit fields at the beginning. */ | 7536 /* Skip any nameless bit fields at the beginning. */ |
7234 } | 7553 } |
7235 | 7554 |
7236 /* Build AVL tree from a string constant. */ | 7555 /* Build AVL tree from a string constant. */ |
7237 | 7556 |
7238 static void | 7557 static void |
7239 set_nonincremental_init_from_string (tree str) | 7558 set_nonincremental_init_from_string (tree str, |
7559 struct obstack * braced_init_obstack) | |
7240 { | 7560 { |
7241 tree value, purpose, type; | 7561 tree value, purpose, type; |
7242 HOST_WIDE_INT val[2]; | 7562 HOST_WIDE_INT val[2]; |
7243 const char *p, *end; | 7563 const char *p, *end; |
7244 int byte, wchar_bytes, charwidth, bitpos; | 7564 int byte, wchar_bytes, charwidth, bitpos; |
7297 val[0] |= ((HOST_WIDE_INT) -1) | 7617 val[0] |= ((HOST_WIDE_INT) -1) |
7298 << (bitpos - HOST_BITS_PER_WIDE_INT); | 7618 << (bitpos - HOST_BITS_PER_WIDE_INT); |
7299 } | 7619 } |
7300 | 7620 |
7301 value = build_int_cst_wide (type, val[1], val[0]); | 7621 value = build_int_cst_wide (type, val[1], val[0]); |
7302 add_pending_init (purpose, value, NULL_TREE, false); | 7622 add_pending_init (purpose, value, NULL_TREE, false, |
7623 braced_init_obstack); | |
7303 } | 7624 } |
7304 | 7625 |
7305 constructor_incremental = 0; | 7626 constructor_incremental = 0; |
7306 } | 7627 } |
7307 | 7628 |
7308 /* Return value of FIELD in pending initializer or zero if the field was | 7629 /* Return value of FIELD in pending initializer or zero if the field was |
7309 not initialized yet. */ | 7630 not initialized yet. */ |
7310 | 7631 |
7311 static tree | 7632 static tree |
7312 find_init_member (tree field) | 7633 find_init_member (tree field, struct obstack * braced_init_obstack) |
7313 { | 7634 { |
7314 struct init_node *p; | 7635 struct init_node *p; |
7315 | 7636 |
7316 if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 7637 if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
7317 { | 7638 { |
7318 if (constructor_incremental | 7639 if (constructor_incremental |
7319 && tree_int_cst_lt (field, constructor_unfilled_index)) | 7640 && tree_int_cst_lt (field, constructor_unfilled_index)) |
7320 set_nonincremental_init (); | 7641 set_nonincremental_init (braced_init_obstack); |
7321 | 7642 |
7322 p = constructor_pending_elts; | 7643 p = constructor_pending_elts; |
7323 while (p) | 7644 while (p) |
7324 { | 7645 { |
7325 if (tree_int_cst_lt (field, p->purpose)) | 7646 if (tree_int_cst_lt (field, p->purpose)) |
7333 else if (TREE_CODE (constructor_type) == RECORD_TYPE) | 7654 else if (TREE_CODE (constructor_type) == RECORD_TYPE) |
7334 { | 7655 { |
7335 tree bitpos = bit_position (field); | 7656 tree bitpos = bit_position (field); |
7336 | 7657 |
7337 if (constructor_incremental | 7658 if (constructor_incremental |
7338 && (!constructor_unfilled_fields | 7659 && (!constructor_unfilled_fields |
7339 || tree_int_cst_lt (bitpos, | 7660 || tree_int_cst_lt (bitpos, |
7340 bit_position (constructor_unfilled_fields)))) | 7661 bit_position (constructor_unfilled_fields)))) |
7341 set_nonincremental_init (); | 7662 set_nonincremental_init (braced_init_obstack); |
7342 | 7663 |
7343 p = constructor_pending_elts; | 7664 p = constructor_pending_elts; |
7344 while (p) | 7665 while (p) |
7345 { | 7666 { |
7346 if (field == p->purpose) | 7667 if (field == p->purpose) |
7380 and thus no warnings should be emitted about overriding an | 7701 and thus no warnings should be emitted about overriding an |
7381 existing initializer. */ | 7702 existing initializer. */ |
7382 | 7703 |
7383 static void | 7704 static void |
7384 output_init_element (tree value, tree origtype, bool strict_string, tree type, | 7705 output_init_element (tree value, tree origtype, bool strict_string, tree type, |
7385 tree field, int pending, bool implicit) | 7706 tree field, int pending, bool implicit, |
7707 struct obstack * braced_init_obstack) | |
7386 { | 7708 { |
7387 tree semantic_type = NULL_TREE; | 7709 tree semantic_type = NULL_TREE; |
7388 constructor_elt *celt; | 7710 constructor_elt *celt; |
7389 bool maybe_const = true; | 7711 bool maybe_const = true; |
7390 bool npc; | 7712 bool npc; |
7471 | 7793 |
7472 /* If this field is empty (and not at the end of structure), | 7794 /* If this field is empty (and not at the end of structure), |
7473 don't do anything other than checking the initializer. */ | 7795 don't do anything other than checking the initializer. */ |
7474 if (field | 7796 if (field |
7475 && (TREE_TYPE (field) == error_mark_node | 7797 && (TREE_TYPE (field) == error_mark_node |
7476 || (COMPLETE_TYPE_P (TREE_TYPE (field)) | 7798 || (COMPLETE_TYPE_P (TREE_TYPE (field)) |
7477 && integer_zerop (TYPE_SIZE (TREE_TYPE (field))) | 7799 && integer_zerop (TYPE_SIZE (TREE_TYPE (field))) |
7478 && (TREE_CODE (constructor_type) == ARRAY_TYPE | 7800 && (TREE_CODE (constructor_type) == ARRAY_TYPE |
7479 || TREE_CHAIN (field))))) | 7801 || DECL_CHAIN (field))))) |
7480 return; | 7802 return; |
7481 | 7803 |
7482 if (semantic_type) | 7804 if (semantic_type) |
7483 value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value); | 7805 value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value); |
7484 value = digest_init (input_location, type, value, origtype, npc, | 7806 value = digest_init (input_location, type, value, origtype, npc, |
7496 if (TREE_CODE (constructor_type) == ARRAY_TYPE | 7818 if (TREE_CODE (constructor_type) == ARRAY_TYPE |
7497 && (!constructor_incremental | 7819 && (!constructor_incremental |
7498 || !tree_int_cst_equal (field, constructor_unfilled_index))) | 7820 || !tree_int_cst_equal (field, constructor_unfilled_index))) |
7499 { | 7821 { |
7500 if (constructor_incremental | 7822 if (constructor_incremental |
7501 && tree_int_cst_lt (field, constructor_unfilled_index)) | 7823 && tree_int_cst_lt (field, constructor_unfilled_index)) |
7502 set_nonincremental_init (); | 7824 set_nonincremental_init (braced_init_obstack); |
7503 | 7825 |
7504 add_pending_init (field, value, origtype, implicit); | 7826 add_pending_init (field, value, origtype, implicit, |
7827 braced_init_obstack); | |
7505 return; | 7828 return; |
7506 } | 7829 } |
7507 else if (TREE_CODE (constructor_type) == RECORD_TYPE | 7830 else if (TREE_CODE (constructor_type) == RECORD_TYPE |
7508 && (!constructor_incremental | 7831 && (!constructor_incremental |
7509 || field != constructor_unfilled_fields)) | 7832 || field != constructor_unfilled_fields)) |
7510 { | 7833 { |
7511 /* We do this for records but not for unions. In a union, | 7834 /* We do this for records but not for unions. In a union, |
7512 no matter which field is specified, it can be initialized | 7835 no matter which field is specified, it can be initialized |
7513 right away since it starts at the beginning of the union. */ | 7836 right away since it starts at the beginning of the union. */ |
7514 if (constructor_incremental) | 7837 if (constructor_incremental) |
7515 { | 7838 { |
7516 if (!constructor_unfilled_fields) | 7839 if (!constructor_unfilled_fields) |
7517 set_nonincremental_init (); | 7840 set_nonincremental_init (braced_init_obstack); |
7518 else | 7841 else |
7519 { | 7842 { |
7520 tree bitpos, unfillpos; | 7843 tree bitpos, unfillpos; |
7521 | 7844 |
7522 bitpos = bit_position (field); | 7845 bitpos = bit_position (field); |
7523 unfillpos = bit_position (constructor_unfilled_fields); | 7846 unfillpos = bit_position (constructor_unfilled_fields); |
7524 | 7847 |
7525 if (tree_int_cst_lt (bitpos, unfillpos)) | 7848 if (tree_int_cst_lt (bitpos, unfillpos)) |
7526 set_nonincremental_init (); | 7849 set_nonincremental_init (braced_init_obstack); |
7527 } | 7850 } |
7528 } | 7851 } |
7529 | 7852 |
7530 add_pending_init (field, value, origtype, implicit); | 7853 add_pending_init (field, value, origtype, implicit, |
7854 braced_init_obstack); | |
7531 return; | 7855 return; |
7532 } | 7856 } |
7533 else if (TREE_CODE (constructor_type) == UNION_TYPE | 7857 else if (TREE_CODE (constructor_type) == UNION_TYPE |
7534 && !VEC_empty (constructor_elt, constructor_elements)) | 7858 && !VEC_empty (constructor_elt, constructor_elements)) |
7535 { | 7859 { |
7560 = size_binop_loc (input_location, PLUS_EXPR, constructor_unfilled_index, | 7884 = size_binop_loc (input_location, PLUS_EXPR, constructor_unfilled_index, |
7561 bitsize_one_node); | 7885 bitsize_one_node); |
7562 else if (TREE_CODE (constructor_type) == RECORD_TYPE) | 7886 else if (TREE_CODE (constructor_type) == RECORD_TYPE) |
7563 { | 7887 { |
7564 constructor_unfilled_fields | 7888 constructor_unfilled_fields |
7565 = TREE_CHAIN (constructor_unfilled_fields); | 7889 = DECL_CHAIN (constructor_unfilled_fields); |
7566 | 7890 |
7567 /* Skip any nameless bit fields. */ | 7891 /* Skip any nameless bit fields. */ |
7568 while (constructor_unfilled_fields != 0 | 7892 while (constructor_unfilled_fields != 0 |
7569 && DECL_C_BIT_FIELD (constructor_unfilled_fields) | 7893 && DECL_C_BIT_FIELD (constructor_unfilled_fields) |
7570 && DECL_NAME (constructor_unfilled_fields) == 0) | 7894 && DECL_NAME (constructor_unfilled_fields) == 0) |
7571 constructor_unfilled_fields = | 7895 constructor_unfilled_fields = |
7572 TREE_CHAIN (constructor_unfilled_fields); | 7896 DECL_CHAIN (constructor_unfilled_fields); |
7573 } | 7897 } |
7574 else if (TREE_CODE (constructor_type) == UNION_TYPE) | 7898 else if (TREE_CODE (constructor_type) == UNION_TYPE) |
7575 constructor_unfilled_fields = 0; | 7899 constructor_unfilled_fields = 0; |
7576 | 7900 |
7577 /* Now output any pending elements which have become next. */ | 7901 /* Now output any pending elements which have become next. */ |
7578 if (pending) | 7902 if (pending) |
7579 output_pending_init_elements (0); | 7903 output_pending_init_elements (0, braced_init_obstack); |
7580 } | 7904 } |
7581 | 7905 |
7582 /* Output any pending elements which have become next. | 7906 /* Output any pending elements which have become next. |
7583 As we output elements, constructor_unfilled_{fields,index} | 7907 As we output elements, constructor_unfilled_{fields,index} |
7584 advances, which may cause other elements to become next; | 7908 advances, which may cause other elements to become next; |
7587 If ALL is 0, we return when there are | 7911 If ALL is 0, we return when there are |
7588 no more pending elements to output now. | 7912 no more pending elements to output now. |
7589 | 7913 |
7590 If ALL is 1, we output space as necessary so that | 7914 If ALL is 1, we output space as necessary so that |
7591 we can output all the pending elements. */ | 7915 we can output all the pending elements. */ |
7592 | |
7593 static void | 7916 static void |
7594 output_pending_init_elements (int all) | 7917 output_pending_init_elements (int all, struct obstack * braced_init_obstack) |
7595 { | 7918 { |
7596 struct init_node *elt = constructor_pending_elts; | 7919 struct init_node *elt = constructor_pending_elts; |
7597 tree next; | 7920 tree next; |
7598 | 7921 |
7599 retry: | 7922 retry: |
7605 | 7928 |
7606 next = 0; | 7929 next = 0; |
7607 while (elt) | 7930 while (elt) |
7608 { | 7931 { |
7609 if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 7932 if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
7610 { | 7933 { |
7611 if (tree_int_cst_equal (elt->purpose, | 7934 if (tree_int_cst_equal (elt->purpose, |
7612 constructor_unfilled_index)) | 7935 constructor_unfilled_index)) |
7613 output_init_element (elt->value, elt->origtype, true, | 7936 output_init_element (elt->value, elt->origtype, true, |
7614 TREE_TYPE (constructor_type), | 7937 TREE_TYPE (constructor_type), |
7615 constructor_unfilled_index, 0, false); | 7938 constructor_unfilled_index, 0, false, |
7616 else if (tree_int_cst_lt (constructor_unfilled_index, | 7939 braced_init_obstack); |
7617 elt->purpose)) | 7940 else if (tree_int_cst_lt (constructor_unfilled_index, |
7618 { | 7941 elt->purpose)) |
7619 /* Advance to the next smaller node. */ | 7942 { |
7620 if (elt->left) | 7943 /* Advance to the next smaller node. */ |
7621 elt = elt->left; | 7944 if (elt->left) |
7622 else | 7945 elt = elt->left; |
7623 { | 7946 else |
7624 /* We have reached the smallest node bigger than the | 7947 { |
7625 current unfilled index. Fill the space first. */ | 7948 /* We have reached the smallest node bigger than the |
7626 next = elt->purpose; | 7949 current unfilled index. Fill the space first. */ |
7627 break; | 7950 next = elt->purpose; |
7628 } | 7951 break; |
7629 } | 7952 } |
7630 else | 7953 } |
7631 { | 7954 else |
7632 /* Advance to the next bigger node. */ | 7955 { |
7633 if (elt->right) | 7956 /* Advance to the next bigger node. */ |
7634 elt = elt->right; | 7957 if (elt->right) |
7635 else | 7958 elt = elt->right; |
7636 { | 7959 else |
7637 /* We have reached the biggest node in a subtree. Find | 7960 { |
7638 the parent of it, which is the next bigger node. */ | 7961 /* We have reached the biggest node in a subtree. Find |
7639 while (elt->parent && elt->parent->right == elt) | 7962 the parent of it, which is the next bigger node. */ |
7640 elt = elt->parent; | 7963 while (elt->parent && elt->parent->right == elt) |
7641 elt = elt->parent; | 7964 elt = elt->parent; |
7642 if (elt && tree_int_cst_lt (constructor_unfilled_index, | 7965 elt = elt->parent; |
7643 elt->purpose)) | 7966 if (elt && tree_int_cst_lt (constructor_unfilled_index, |
7644 { | 7967 elt->purpose)) |
7645 next = elt->purpose; | 7968 { |
7646 break; | 7969 next = elt->purpose; |
7647 } | 7970 break; |
7648 } | 7971 } |
7649 } | 7972 } |
7650 } | 7973 } |
7974 } | |
7651 else if (TREE_CODE (constructor_type) == RECORD_TYPE | 7975 else if (TREE_CODE (constructor_type) == RECORD_TYPE |
7652 || TREE_CODE (constructor_type) == UNION_TYPE) | 7976 || TREE_CODE (constructor_type) == UNION_TYPE) |
7653 { | 7977 { |
7654 tree ctor_unfilled_bitpos, elt_bitpos; | 7978 tree ctor_unfilled_bitpos, elt_bitpos; |
7655 | 7979 |
7656 /* If the current record is complete we are done. */ | 7980 /* If the current record is complete we are done. */ |
7657 if (constructor_unfilled_fields == 0) | 7981 if (constructor_unfilled_fields == 0) |
7658 break; | 7982 break; |
7659 | 7983 |
7660 ctor_unfilled_bitpos = bit_position (constructor_unfilled_fields); | 7984 ctor_unfilled_bitpos = bit_position (constructor_unfilled_fields); |
7661 elt_bitpos = bit_position (elt->purpose); | 7985 elt_bitpos = bit_position (elt->purpose); |
7662 /* We can't compare fields here because there might be empty | 7986 /* We can't compare fields here because there might be empty |
7663 fields in between. */ | 7987 fields in between. */ |
7664 if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos)) | 7988 if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos)) |
7665 { | 7989 { |
7666 constructor_unfilled_fields = elt->purpose; | 7990 constructor_unfilled_fields = elt->purpose; |
7667 output_init_element (elt->value, elt->origtype, true, | 7991 output_init_element (elt->value, elt->origtype, true, |
7668 TREE_TYPE (elt->purpose), | 7992 TREE_TYPE (elt->purpose), |
7669 elt->purpose, 0, false); | 7993 elt->purpose, 0, false, |
7670 } | 7994 braced_init_obstack); |
7671 else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos)) | 7995 } |
7672 { | 7996 else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos)) |
7673 /* Advance to the next smaller node. */ | 7997 { |
7674 if (elt->left) | 7998 /* Advance to the next smaller node. */ |
7675 elt = elt->left; | 7999 if (elt->left) |
7676 else | 8000 elt = elt->left; |
7677 { | 8001 else |
7678 /* We have reached the smallest node bigger than the | 8002 { |
7679 current unfilled field. Fill the space first. */ | 8003 /* We have reached the smallest node bigger than the |
7680 next = elt->purpose; | 8004 current unfilled field. Fill the space first. */ |
7681 break; | 8005 next = elt->purpose; |
7682 } | 8006 break; |
7683 } | 8007 } |
7684 else | 8008 } |
7685 { | 8009 else |
7686 /* Advance to the next bigger node. */ | 8010 { |
7687 if (elt->right) | 8011 /* Advance to the next bigger node. */ |
7688 elt = elt->right; | 8012 if (elt->right) |
7689 else | 8013 elt = elt->right; |
7690 { | 8014 else |
7691 /* We have reached the biggest node in a subtree. Find | 8015 { |
7692 the parent of it, which is the next bigger node. */ | 8016 /* We have reached the biggest node in a subtree. Find |
7693 while (elt->parent && elt->parent->right == elt) | 8017 the parent of it, which is the next bigger node. */ |
7694 elt = elt->parent; | 8018 while (elt->parent && elt->parent->right == elt) |
7695 elt = elt->parent; | 8019 elt = elt->parent; |
7696 if (elt | 8020 elt = elt->parent; |
7697 && (tree_int_cst_lt (ctor_unfilled_bitpos, | 8021 if (elt |
7698 bit_position (elt->purpose)))) | 8022 && (tree_int_cst_lt (ctor_unfilled_bitpos, |
7699 { | 8023 bit_position (elt->purpose)))) |
7700 next = elt->purpose; | 8024 { |
7701 break; | 8025 next = elt->purpose; |
7702 } | 8026 break; |
7703 } | 8027 } |
7704 } | 8028 } |
7705 } | 8029 } |
8030 } | |
7706 } | 8031 } |
7707 | 8032 |
7708 /* Ordinarily return, but not if we want to output all | 8033 /* Ordinarily return, but not if we want to output all |
7709 and there are elements left. */ | 8034 and there are elements left. */ |
7710 if (!(all && next != 0)) | 8035 if (!(all && next != 0)) |
7735 the new initializer has been merged with the existing one | 8060 the new initializer has been merged with the existing one |
7736 and thus no warnings should be emitted about overriding an | 8061 and thus no warnings should be emitted about overriding an |
7737 existing initializer. */ | 8062 existing initializer. */ |
7738 | 8063 |
7739 void | 8064 void |
7740 process_init_element (struct c_expr value, bool implicit) | 8065 process_init_element (struct c_expr value, bool implicit, |
8066 struct obstack * braced_init_obstack) | |
7741 { | 8067 { |
7742 tree orig_value = value.value; | 8068 tree orig_value = value.value; |
7743 int string_flag = orig_value != 0 && TREE_CODE (orig_value) == STRING_CST; | 8069 int string_flag = orig_value != 0 && TREE_CODE (orig_value) == STRING_CST; |
7744 bool strict_string = value.original_code == STRING_CST; | 8070 bool strict_string = value.original_code == STRING_CST; |
7745 | 8071 |
7774 /* If we've exhausted any levels that didn't have braces, | 8100 /* If we've exhausted any levels that didn't have braces, |
7775 pop them now. */ | 8101 pop them now. */ |
7776 while (constructor_stack->implicit) | 8102 while (constructor_stack->implicit) |
7777 { | 8103 { |
7778 if ((TREE_CODE (constructor_type) == RECORD_TYPE | 8104 if ((TREE_CODE (constructor_type) == RECORD_TYPE |
7779 || TREE_CODE (constructor_type) == UNION_TYPE) | 8105 || TREE_CODE (constructor_type) == UNION_TYPE) |
7780 && constructor_fields == 0) | 8106 && constructor_fields == 0) |
7781 process_init_element (pop_init_level (1), true); | 8107 process_init_element (pop_init_level (1, braced_init_obstack), |
8108 true, braced_init_obstack); | |
7782 else if ((TREE_CODE (constructor_type) == ARRAY_TYPE | 8109 else if ((TREE_CODE (constructor_type) == ARRAY_TYPE |
7783 || TREE_CODE (constructor_type) == VECTOR_TYPE) | 8110 || TREE_CODE (constructor_type) == VECTOR_TYPE) |
7784 && (constructor_max_index == 0 | 8111 && (constructor_max_index == 0 |
7785 || tree_int_cst_lt (constructor_max_index, | 8112 || tree_int_cst_lt (constructor_max_index, |
7786 constructor_index))) | 8113 constructor_index))) |
7787 process_init_element (pop_init_level (1), true); | 8114 process_init_element (pop_init_level (1, braced_init_obstack), |
8115 true, braced_init_obstack); | |
7788 else | 8116 else |
7789 break; | 8117 break; |
7790 } | 8118 } |
7791 | 8119 |
7792 /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */ | 8120 /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once. */ |
7812 } | 8140 } |
7813 | 8141 |
7814 while (1) | 8142 while (1) |
7815 { | 8143 { |
7816 if (TREE_CODE (constructor_type) == RECORD_TYPE) | 8144 if (TREE_CODE (constructor_type) == RECORD_TYPE) |
7817 { | 8145 { |
7818 tree fieldtype; | 8146 tree fieldtype; |
7819 enum tree_code fieldcode; | 8147 enum tree_code fieldcode; |
7820 | 8148 |
7821 if (constructor_fields == 0) | 8149 if (constructor_fields == 0) |
7822 { | 8150 { |
7823 pedwarn_init (input_location, 0, | 8151 pedwarn_init (input_location, 0, |
7824 "excess elements in struct initializer"); | 8152 "excess elements in struct initializer"); |
7825 break; | 8153 break; |
7826 } | 8154 } |
7827 | 8155 |
7828 fieldtype = TREE_TYPE (constructor_fields); | 8156 fieldtype = TREE_TYPE (constructor_fields); |
7829 if (fieldtype != error_mark_node) | 8157 if (fieldtype != error_mark_node) |
7830 fieldtype = TYPE_MAIN_VARIANT (fieldtype); | 8158 fieldtype = TYPE_MAIN_VARIANT (fieldtype); |
7831 fieldcode = TREE_CODE (fieldtype); | 8159 fieldcode = TREE_CODE (fieldtype); |
7832 | 8160 |
7833 /* Error for non-static initialization of a flexible array member. */ | 8161 /* Error for non-static initialization of a flexible array member. */ |
7834 if (fieldcode == ARRAY_TYPE | 8162 if (fieldcode == ARRAY_TYPE |
7835 && !require_constant_value | 8163 && !require_constant_value |
7836 && TYPE_SIZE (fieldtype) == NULL_TREE | 8164 && TYPE_SIZE (fieldtype) == NULL_TREE |
7837 && TREE_CHAIN (constructor_fields) == NULL_TREE) | 8165 && DECL_CHAIN (constructor_fields) == NULL_TREE) |
7838 { | 8166 { |
7839 error_init ("non-static initialization of a flexible array member"); | 8167 error_init ("non-static initialization of a flexible array member"); |
7840 break; | 8168 break; |
7841 } | 8169 } |
7842 | 8170 |
7843 /* Accept a string constant to initialize a subarray. */ | 8171 /* Accept a string constant to initialize a subarray. */ |
7844 if (value.value != 0 | 8172 if (value.value != 0 |
7845 && fieldcode == ARRAY_TYPE | 8173 && fieldcode == ARRAY_TYPE |
7846 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype)) | 8174 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype)) |
7847 && string_flag) | 8175 && string_flag) |
7848 value.value = orig_value; | 8176 value.value = orig_value; |
7849 /* Otherwise, if we have come to a subaggregate, | 8177 /* Otherwise, if we have come to a subaggregate, |
7850 and we don't have an element of its type, push into it. */ | 8178 and we don't have an element of its type, push into it. */ |
7851 else if (value.value != 0 | 8179 else if (value.value != 0 |
7852 && value.value != error_mark_node | 8180 && value.value != error_mark_node |
7853 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype | 8181 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype |
7854 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE | 8182 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE |
7855 || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE)) | 8183 || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE)) |
7856 { | 8184 { |
7857 push_init_level (1); | 8185 push_init_level (1, braced_init_obstack); |
7858 continue; | 8186 continue; |
7859 } | 8187 } |
7860 | 8188 |
7861 if (value.value) | 8189 if (value.value) |
7862 { | 8190 { |
7863 push_member_name (constructor_fields); | 8191 push_member_name (constructor_fields); |
7864 output_init_element (value.value, value.original_type, | 8192 output_init_element (value.value, value.original_type, |
7865 strict_string, fieldtype, | 8193 strict_string, fieldtype, |
7866 constructor_fields, 1, implicit); | 8194 constructor_fields, 1, implicit, |
7867 RESTORE_SPELLING_DEPTH (constructor_depth); | 8195 braced_init_obstack); |
7868 } | 8196 RESTORE_SPELLING_DEPTH (constructor_depth); |
7869 else | 8197 } |
7870 /* Do the bookkeeping for an element that was | 8198 else |
7871 directly output as a constructor. */ | 8199 /* Do the bookkeeping for an element that was |
7872 { | 8200 directly output as a constructor. */ |
7873 /* For a record, keep track of end position of last field. */ | 8201 { |
7874 if (DECL_SIZE (constructor_fields)) | 8202 /* For a record, keep track of end position of last field. */ |
7875 constructor_bit_index | 8203 if (DECL_SIZE (constructor_fields)) |
7876 = size_binop_loc (input_location, PLUS_EXPR, | 8204 constructor_bit_index |
7877 bit_position (constructor_fields), | 8205 = size_binop_loc (input_location, PLUS_EXPR, |
7878 DECL_SIZE (constructor_fields)); | 8206 bit_position (constructor_fields), |
7879 | 8207 DECL_SIZE (constructor_fields)); |
7880 /* If the current field was the first one not yet written out, | 8208 |
7881 it isn't now, so update. */ | 8209 /* If the current field was the first one not yet written out, |
7882 if (constructor_unfilled_fields == constructor_fields) | 8210 it isn't now, so update. */ |
7883 { | 8211 if (constructor_unfilled_fields == constructor_fields) |
7884 constructor_unfilled_fields = TREE_CHAIN (constructor_fields); | 8212 { |
7885 /* Skip any nameless bit fields. */ | 8213 constructor_unfilled_fields = DECL_CHAIN (constructor_fields); |
7886 while (constructor_unfilled_fields != 0 | 8214 /* Skip any nameless bit fields. */ |
7887 && DECL_C_BIT_FIELD (constructor_unfilled_fields) | 8215 while (constructor_unfilled_fields != 0 |
7888 && DECL_NAME (constructor_unfilled_fields) == 0) | 8216 && DECL_C_BIT_FIELD (constructor_unfilled_fields) |
7889 constructor_unfilled_fields = | 8217 && DECL_NAME (constructor_unfilled_fields) == 0) |
7890 TREE_CHAIN (constructor_unfilled_fields); | 8218 constructor_unfilled_fields = |
7891 } | 8219 DECL_CHAIN (constructor_unfilled_fields); |
7892 } | 8220 } |
7893 | 8221 } |
7894 constructor_fields = TREE_CHAIN (constructor_fields); | 8222 |
7895 /* Skip any nameless bit fields at the beginning. */ | 8223 constructor_fields = DECL_CHAIN (constructor_fields); |
7896 while (constructor_fields != 0 | 8224 /* Skip any nameless bit fields at the beginning. */ |
7897 && DECL_C_BIT_FIELD (constructor_fields) | 8225 while (constructor_fields != 0 |
7898 && DECL_NAME (constructor_fields) == 0) | 8226 && DECL_C_BIT_FIELD (constructor_fields) |
7899 constructor_fields = TREE_CHAIN (constructor_fields); | 8227 && DECL_NAME (constructor_fields) == 0) |
7900 } | 8228 constructor_fields = DECL_CHAIN (constructor_fields); |
8229 } | |
7901 else if (TREE_CODE (constructor_type) == UNION_TYPE) | 8230 else if (TREE_CODE (constructor_type) == UNION_TYPE) |
7902 { | 8231 { |
7903 tree fieldtype; | 8232 tree fieldtype; |
7904 enum tree_code fieldcode; | 8233 enum tree_code fieldcode; |
7905 | 8234 |
7906 if (constructor_fields == 0) | 8235 if (constructor_fields == 0) |
7907 { | 8236 { |
7908 pedwarn_init (input_location, 0, | 8237 pedwarn_init (input_location, 0, |
7909 "excess elements in union initializer"); | 8238 "excess elements in union initializer"); |
7910 break; | 8239 break; |
7911 } | 8240 } |
7912 | 8241 |
7913 fieldtype = TREE_TYPE (constructor_fields); | 8242 fieldtype = TREE_TYPE (constructor_fields); |
7914 if (fieldtype != error_mark_node) | 8243 if (fieldtype != error_mark_node) |
7915 fieldtype = TYPE_MAIN_VARIANT (fieldtype); | 8244 fieldtype = TYPE_MAIN_VARIANT (fieldtype); |
7916 fieldcode = TREE_CODE (fieldtype); | 8245 fieldcode = TREE_CODE (fieldtype); |
7917 | 8246 |
7918 /* Warn that traditional C rejects initialization of unions. | 8247 /* Warn that traditional C rejects initialization of unions. |
7919 We skip the warning if the value is zero. This is done | 8248 We skip the warning if the value is zero. This is done |
7920 under the assumption that the zero initializer in user | 8249 under the assumption that the zero initializer in user |
7921 code appears conditioned on e.g. __STDC__ to avoid | 8250 code appears conditioned on e.g. __STDC__ to avoid |
7922 "missing initializer" warnings and relies on default | 8251 "missing initializer" warnings and relies on default |
7923 initialization to zero in the traditional C case. | 8252 initialization to zero in the traditional C case. |
7924 We also skip the warning if the initializer is designated, | 8253 We also skip the warning if the initializer is designated, |
7925 again on the assumption that this must be conditional on | 8254 again on the assumption that this must be conditional on |
7926 __STDC__ anyway (and we've already complained about the | 8255 __STDC__ anyway (and we've already complained about the |
7927 member-designator already). */ | 8256 member-designator already). */ |
7928 if (!in_system_header && !constructor_designated | 8257 if (!in_system_header && !constructor_designated |
7929 && !(value.value && (integer_zerop (value.value) | 8258 && !(value.value && (integer_zerop (value.value) |
7930 || real_zerop (value.value)))) | 8259 || real_zerop (value.value)))) |
7931 warning (OPT_Wtraditional, "traditional C rejects initialization " | 8260 warning (OPT_Wtraditional, "traditional C rejects initialization " |
7932 "of unions"); | 8261 "of unions"); |
7933 | 8262 |
7934 /* Accept a string constant to initialize a subarray. */ | 8263 /* Accept a string constant to initialize a subarray. */ |
7935 if (value.value != 0 | 8264 if (value.value != 0 |
7936 && fieldcode == ARRAY_TYPE | 8265 && fieldcode == ARRAY_TYPE |
7937 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype)) | 8266 && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype)) |
7938 && string_flag) | 8267 && string_flag) |
7939 value.value = orig_value; | 8268 value.value = orig_value; |
7940 /* Otherwise, if we have come to a subaggregate, | 8269 /* Otherwise, if we have come to a subaggregate, |
7941 and we don't have an element of its type, push into it. */ | 8270 and we don't have an element of its type, push into it. */ |
7942 else if (value.value != 0 | 8271 else if (value.value != 0 |
7943 && value.value != error_mark_node | 8272 && value.value != error_mark_node |
7944 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype | 8273 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype |
7945 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE | 8274 && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE |
7946 || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE)) | 8275 || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE)) |
7947 { | 8276 { |
7948 push_init_level (1); | 8277 push_init_level (1, braced_init_obstack); |
7949 continue; | 8278 continue; |
7950 } | 8279 } |
7951 | 8280 |
7952 if (value.value) | 8281 if (value.value) |
7953 { | 8282 { |
7954 push_member_name (constructor_fields); | 8283 push_member_name (constructor_fields); |
7955 output_init_element (value.value, value.original_type, | 8284 output_init_element (value.value, value.original_type, |
7956 strict_string, fieldtype, | 8285 strict_string, fieldtype, |
7957 constructor_fields, 1, implicit); | 8286 constructor_fields, 1, implicit, |
7958 RESTORE_SPELLING_DEPTH (constructor_depth); | 8287 braced_init_obstack); |
7959 } | 8288 RESTORE_SPELLING_DEPTH (constructor_depth); |
7960 else | 8289 } |
7961 /* Do the bookkeeping for an element that was | 8290 else |
7962 directly output as a constructor. */ | 8291 /* Do the bookkeeping for an element that was |
7963 { | 8292 directly output as a constructor. */ |
7964 constructor_bit_index = DECL_SIZE (constructor_fields); | 8293 { |
7965 constructor_unfilled_fields = TREE_CHAIN (constructor_fields); | 8294 constructor_bit_index = DECL_SIZE (constructor_fields); |
7966 } | 8295 constructor_unfilled_fields = DECL_CHAIN (constructor_fields); |
7967 | 8296 } |
7968 constructor_fields = 0; | 8297 |
7969 } | 8298 constructor_fields = 0; |
8299 } | |
7970 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) | 8300 else if (TREE_CODE (constructor_type) == ARRAY_TYPE) |
7971 { | 8301 { |
7972 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type)); | 8302 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type)); |
7973 enum tree_code eltcode = TREE_CODE (elttype); | 8303 enum tree_code eltcode = TREE_CODE (elttype); |
7974 | 8304 |
7975 /* Accept a string constant to initialize a subarray. */ | 8305 /* Accept a string constant to initialize a subarray. */ |
7976 if (value.value != 0 | 8306 if (value.value != 0 |
7977 && eltcode == ARRAY_TYPE | 8307 && eltcode == ARRAY_TYPE |
7978 && INTEGRAL_TYPE_P (TREE_TYPE (elttype)) | 8308 && INTEGRAL_TYPE_P (TREE_TYPE (elttype)) |
7979 && string_flag) | 8309 && string_flag) |
7980 value.value = orig_value; | 8310 value.value = orig_value; |
7981 /* Otherwise, if we have come to a subaggregate, | 8311 /* Otherwise, if we have come to a subaggregate, |
7982 and we don't have an element of its type, push into it. */ | 8312 and we don't have an element of its type, push into it. */ |
7983 else if (value.value != 0 | 8313 else if (value.value != 0 |
7984 && value.value != error_mark_node | 8314 && value.value != error_mark_node |
7985 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != elttype | 8315 && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != elttype |
7986 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE | 8316 && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE |
7987 || eltcode == UNION_TYPE || eltcode == VECTOR_TYPE)) | 8317 || eltcode == UNION_TYPE || eltcode == VECTOR_TYPE)) |
7988 { | 8318 { |
7989 push_init_level (1); | 8319 push_init_level (1, braced_init_obstack); |
7990 continue; | 8320 continue; |
7991 } | 8321 } |
7992 | 8322 |
7993 if (constructor_max_index != 0 | 8323 if (constructor_max_index != 0 |
7994 && (tree_int_cst_lt (constructor_max_index, constructor_index) | 8324 && (tree_int_cst_lt (constructor_max_index, constructor_index) |
7995 || integer_all_onesp (constructor_max_index))) | 8325 || integer_all_onesp (constructor_max_index))) |
7996 { | 8326 { |
7997 pedwarn_init (input_location, 0, | 8327 pedwarn_init (input_location, 0, |
7998 "excess elements in array initializer"); | 8328 "excess elements in array initializer"); |
7999 break; | 8329 break; |
8000 } | 8330 } |
8001 | 8331 |
8002 /* Now output the actual element. */ | 8332 /* Now output the actual element. */ |
8003 if (value.value) | 8333 if (value.value) |
8004 { | 8334 { |
8005 push_array_bounds (tree_low_cst (constructor_index, 1)); | 8335 push_array_bounds (tree_low_cst (constructor_index, 1)); |
8006 output_init_element (value.value, value.original_type, | 8336 output_init_element (value.value, value.original_type, |
8007 strict_string, elttype, | 8337 strict_string, elttype, |
8008 constructor_index, 1, implicit); | 8338 constructor_index, 1, implicit, |
8009 RESTORE_SPELLING_DEPTH (constructor_depth); | 8339 braced_init_obstack); |
8010 } | 8340 RESTORE_SPELLING_DEPTH (constructor_depth); |
8011 | 8341 } |
8012 constructor_index | 8342 |
8013 = size_binop_loc (input_location, PLUS_EXPR, | 8343 constructor_index |
8014 constructor_index, bitsize_one_node); | 8344 = size_binop_loc (input_location, PLUS_EXPR, |
8015 | 8345 constructor_index, bitsize_one_node); |
8016 if (!value.value) | 8346 |
8017 /* If we are doing the bookkeeping for an element that was | 8347 if (!value.value) |
8018 directly output as a constructor, we must update | 8348 /* If we are doing the bookkeeping for an element that was |
8019 constructor_unfilled_index. */ | 8349 directly output as a constructor, we must update |
8020 constructor_unfilled_index = constructor_index; | 8350 constructor_unfilled_index. */ |
8021 } | 8351 constructor_unfilled_index = constructor_index; |
8352 } | |
8022 else if (TREE_CODE (constructor_type) == VECTOR_TYPE) | 8353 else if (TREE_CODE (constructor_type) == VECTOR_TYPE) |
8023 { | 8354 { |
8024 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type)); | 8355 tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type)); |
8025 | 8356 |
8026 /* Do a basic check of initializer size. Note that vectors | 8357 /* Do a basic check of initializer size. Note that vectors |
8027 always have a fixed size derived from their type. */ | 8358 always have a fixed size derived from their type. */ |
8028 if (tree_int_cst_lt (constructor_max_index, constructor_index)) | 8359 if (tree_int_cst_lt (constructor_max_index, constructor_index)) |
8029 { | 8360 { |
8030 pedwarn_init (input_location, 0, | 8361 pedwarn_init (input_location, 0, |
8031 "excess elements in vector initializer"); | 8362 "excess elements in vector initializer"); |
8032 break; | 8363 break; |
8033 } | 8364 } |
8034 | 8365 |
8035 /* Now output the actual element. */ | 8366 /* Now output the actual element. */ |
8036 if (value.value) | 8367 if (value.value) |
8037 { | 8368 { |
8038 if (TREE_CODE (value.value) == VECTOR_CST) | 8369 if (TREE_CODE (value.value) == VECTOR_CST) |
8039 elttype = TYPE_MAIN_VARIANT (constructor_type); | 8370 elttype = TYPE_MAIN_VARIANT (constructor_type); |
8040 output_init_element (value.value, value.original_type, | 8371 output_init_element (value.value, value.original_type, |
8041 strict_string, elttype, | 8372 strict_string, elttype, |
8042 constructor_index, 1, implicit); | 8373 constructor_index, 1, implicit, |
8043 } | 8374 braced_init_obstack); |
8044 | 8375 } |
8045 constructor_index | 8376 |
8046 = size_binop_loc (input_location, | 8377 constructor_index |
8047 PLUS_EXPR, constructor_index, bitsize_one_node); | 8378 = size_binop_loc (input_location, |
8048 | 8379 PLUS_EXPR, constructor_index, bitsize_one_node); |
8049 if (!value.value) | 8380 |
8050 /* If we are doing the bookkeeping for an element that was | 8381 if (!value.value) |
8051 directly output as a constructor, we must update | 8382 /* If we are doing the bookkeeping for an element that was |
8052 constructor_unfilled_index. */ | 8383 directly output as a constructor, we must update |
8053 constructor_unfilled_index = constructor_index; | 8384 constructor_unfilled_index. */ |
8054 } | 8385 constructor_unfilled_index = constructor_index; |
8386 } | |
8055 | 8387 |
8056 /* Handle the sole element allowed in a braced initializer | 8388 /* Handle the sole element allowed in a braced initializer |
8057 for a scalar variable. */ | 8389 for a scalar variable. */ |
8058 else if (constructor_type != error_mark_node | 8390 else if (constructor_type != error_mark_node |
8059 && constructor_fields == 0) | 8391 && constructor_fields == 0) |
8061 pedwarn_init (input_location, 0, | 8393 pedwarn_init (input_location, 0, |
8062 "excess elements in scalar initializer"); | 8394 "excess elements in scalar initializer"); |
8063 break; | 8395 break; |
8064 } | 8396 } |
8065 else | 8397 else |
8066 { | 8398 { |
8067 if (value.value) | 8399 if (value.value) |
8068 output_init_element (value.value, value.original_type, | 8400 output_init_element (value.value, value.original_type, |
8069 strict_string, constructor_type, | 8401 strict_string, constructor_type, |
8070 NULL_TREE, 1, implicit); | 8402 NULL_TREE, 1, implicit, |
8071 constructor_fields = 0; | 8403 braced_init_obstack); |
8072 } | 8404 constructor_fields = 0; |
8405 } | |
8073 | 8406 |
8074 /* Handle range initializers either at this level or anywhere higher | 8407 /* Handle range initializers either at this level or anywhere higher |
8075 in the designator stack. */ | 8408 in the designator stack. */ |
8076 if (constructor_range_stack) | 8409 if (constructor_range_stack) |
8077 { | 8410 { |
8078 struct constructor_range_stack *p, *range_stack; | 8411 struct constructor_range_stack *p, *range_stack; |
8079 int finish = 0; | 8412 int finish = 0; |
8080 | 8413 |
8081 range_stack = constructor_range_stack; | 8414 range_stack = constructor_range_stack; |
8082 constructor_range_stack = 0; | 8415 constructor_range_stack = 0; |
8083 while (constructor_stack != range_stack->stack) | 8416 while (constructor_stack != range_stack->stack) |
8084 { | 8417 { |
8085 gcc_assert (constructor_stack->implicit); | 8418 gcc_assert (constructor_stack->implicit); |
8086 process_init_element (pop_init_level (1), true); | 8419 process_init_element (pop_init_level (1, |
8087 } | 8420 braced_init_obstack), |
8088 for (p = range_stack; | 8421 true, braced_init_obstack); |
8089 !p->range_end || tree_int_cst_equal (p->index, p->range_end); | 8422 } |
8090 p = p->prev) | 8423 for (p = range_stack; |
8091 { | 8424 !p->range_end || tree_int_cst_equal (p->index, p->range_end); |
8092 gcc_assert (constructor_stack->implicit); | 8425 p = p->prev) |
8093 process_init_element (pop_init_level (1), true); | 8426 { |
8094 } | 8427 gcc_assert (constructor_stack->implicit); |
8095 | 8428 process_init_element (pop_init_level (1, braced_init_obstack), |
8096 p->index = size_binop_loc (input_location, | 8429 true, braced_init_obstack); |
8097 PLUS_EXPR, p->index, bitsize_one_node); | 8430 } |
8098 if (tree_int_cst_equal (p->index, p->range_end) && !p->prev) | 8431 |
8099 finish = 1; | 8432 p->index = size_binop_loc (input_location, |
8100 | 8433 PLUS_EXPR, p->index, bitsize_one_node); |
8101 while (1) | 8434 if (tree_int_cst_equal (p->index, p->range_end) && !p->prev) |
8102 { | 8435 finish = 1; |
8103 constructor_index = p->index; | 8436 |
8104 constructor_fields = p->fields; | 8437 while (1) |
8105 if (finish && p->range_end && p->index == p->range_start) | 8438 { |
8106 { | 8439 constructor_index = p->index; |
8107 finish = 0; | 8440 constructor_fields = p->fields; |
8108 p->prev = 0; | 8441 if (finish && p->range_end && p->index == p->range_start) |
8109 } | 8442 { |
8110 p = p->next; | 8443 finish = 0; |
8111 if (!p) | 8444 p->prev = 0; |
8112 break; | 8445 } |
8113 push_init_level (2); | 8446 p = p->next; |
8114 p->stack = constructor_stack; | 8447 if (!p) |
8115 if (p->range_end && tree_int_cst_equal (p->index, p->range_end)) | 8448 break; |
8116 p->index = p->range_start; | 8449 push_init_level (2, braced_init_obstack); |
8117 } | 8450 p->stack = constructor_stack; |
8118 | 8451 if (p->range_end && tree_int_cst_equal (p->index, p->range_end)) |
8119 if (!finish) | 8452 p->index = p->range_start; |
8120 constructor_range_stack = range_stack; | 8453 } |
8121 continue; | 8454 |
8122 } | 8455 if (!finish) |
8456 constructor_range_stack = range_stack; | |
8457 continue; | |
8458 } | |
8123 | 8459 |
8124 break; | 8460 break; |
8125 } | 8461 } |
8126 | 8462 |
8127 constructor_range_stack = 0; | 8463 constructor_range_stack = 0; |
8172 primitive form of typechecking -- if the cast can be removed, then | 8508 primitive form of typechecking -- if the cast can be removed, then |
8173 the output operand had a type of the proper width; otherwise we'll | 8509 the output operand had a type of the proper width; otherwise we'll |
8174 get an error. Gross, but ... */ | 8510 get an error. Gross, but ... */ |
8175 STRIP_NOPS (output); | 8511 STRIP_NOPS (output); |
8176 | 8512 |
8177 if (!lvalue_or_else (output, lv_asm)) | 8513 if (!lvalue_or_else (loc, output, lv_asm)) |
8178 output = error_mark_node; | 8514 output = error_mark_node; |
8179 | 8515 |
8180 if (output != error_mark_node | 8516 if (output != error_mark_node |
8181 && (TREE_READONLY (output) | 8517 && (TREE_READONLY (output) |
8182 || TYPE_READONLY (TREE_TYPE (output)) | 8518 || TYPE_READONLY (TREE_TYPE (output)) |
8183 || ((TREE_CODE (TREE_TYPE (output)) == RECORD_TYPE | 8519 || ((TREE_CODE (TREE_TYPE (output)) == RECORD_TYPE |
8759 statement. */ | 9095 statement. */ |
8760 | 9096 |
8761 tree | 9097 tree |
8762 c_process_expr_stmt (location_t loc, tree expr) | 9098 c_process_expr_stmt (location_t loc, tree expr) |
8763 { | 9099 { |
9100 tree exprv; | |
9101 | |
8764 if (!expr) | 9102 if (!expr) |
8765 return NULL_TREE; | 9103 return NULL_TREE; |
8766 | 9104 |
8767 expr = c_fully_fold (expr, false, NULL); | 9105 expr = c_fully_fold (expr, false, NULL); |
8768 | 9106 |
8778 Warnings for statement expressions will be emitted later, once we figure | 9116 Warnings for statement expressions will be emitted later, once we figure |
8779 out which is the result. */ | 9117 out which is the result. */ |
8780 if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list) | 9118 if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list) |
8781 && warn_unused_value) | 9119 && warn_unused_value) |
8782 emit_side_effect_warnings (loc, expr); | 9120 emit_side_effect_warnings (loc, expr); |
9121 | |
9122 exprv = expr; | |
9123 while (TREE_CODE (exprv) == COMPOUND_EXPR) | |
9124 exprv = TREE_OPERAND (exprv, 1); | |
9125 if (DECL_P (exprv) || handled_component_p (exprv)) | |
9126 mark_exp_read (exprv); | |
8783 | 9127 |
8784 /* If the expression is not of a type to which we cannot assign a line | 9128 /* If the expression is not of a type to which we cannot assign a line |
8785 number, wrap the thing in a no-op NOP_EXPR. */ | 9129 number, wrap the thing in a no-op NOP_EXPR. */ |
8786 if (DECL_P (expr) || CONSTANT_CLASS_P (expr)) | 9130 if (DECL_P (expr) || CONSTANT_CLASS_P (expr)) |
8787 { | 9131 { |
9039 In the simplest cases this is the common type of the arguments. */ | 9383 In the simplest cases this is the common type of the arguments. */ |
9040 tree result_type = NULL; | 9384 tree result_type = NULL; |
9041 | 9385 |
9042 /* When the computation is in excess precision, the type of the | 9386 /* When the computation is in excess precision, the type of the |
9043 final EXCESS_PRECISION_EXPR. */ | 9387 final EXCESS_PRECISION_EXPR. */ |
9044 tree real_result_type = NULL; | 9388 tree semantic_result_type = NULL; |
9045 | 9389 |
9046 /* Nonzero means operands have already been type-converted | 9390 /* Nonzero means operands have already been type-converted |
9047 in whatever way is necessary. | 9391 in whatever way is necessary. |
9048 Zero means they need to be converted to RESULT_TYPE. */ | 9392 Zero means they need to be converted to RESULT_TYPE. */ |
9049 int converted = 0; | 9393 int converted = 0; |
9080 bool objc_ok; | 9424 bool objc_ok; |
9081 | 9425 |
9082 /* True means this is an arithmetic operation that may need excess | 9426 /* True means this is an arithmetic operation that may need excess |
9083 precision. */ | 9427 precision. */ |
9084 bool may_need_excess_precision; | 9428 bool may_need_excess_precision; |
9429 | |
9430 /* True means this is a boolean operation that converts both its | |
9431 operands to truth-values. */ | |
9432 bool boolean_op = false; | |
9085 | 9433 |
9086 if (location == UNKNOWN_LOCATION) | 9434 if (location == UNKNOWN_LOCATION) |
9087 location = input_location; | 9435 location = input_location; |
9088 | 9436 |
9089 op0 = orig_op0; | 9437 op0 = orig_op0; |
9295 case TRUTH_ORIF_EXPR: | 9643 case TRUTH_ORIF_EXPR: |
9296 case TRUTH_AND_EXPR: | 9644 case TRUTH_AND_EXPR: |
9297 case TRUTH_OR_EXPR: | 9645 case TRUTH_OR_EXPR: |
9298 case TRUTH_XOR_EXPR: | 9646 case TRUTH_XOR_EXPR: |
9299 if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE | 9647 if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE |
9300 || code0 == REAL_TYPE || code0 == COMPLEX_TYPE | 9648 || code0 == REAL_TYPE || code0 == COMPLEX_TYPE |
9301 || code0 == FIXED_POINT_TYPE) | 9649 || code0 == FIXED_POINT_TYPE) |
9302 && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE | 9650 && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE |
9303 || code1 == REAL_TYPE || code1 == COMPLEX_TYPE | 9651 || code1 == REAL_TYPE || code1 == COMPLEX_TYPE |
9304 || code1 == FIXED_POINT_TYPE)) | 9652 || code1 == FIXED_POINT_TYPE)) |
9305 { | 9653 { |
9306 /* Result of these operations is always an int, | 9654 /* Result of these operations is always an int, |
9307 but that does not mean the operands should be | 9655 but that does not mean the operands should be |
9308 converted to ints! */ | 9656 converted to ints! */ |
9309 result_type = integer_type_node; | 9657 result_type = integer_type_node; |
9310 op0 = c_common_truthvalue_conversion (location, op0); | 9658 op0 = c_common_truthvalue_conversion (location, op0); |
9311 op1 = c_common_truthvalue_conversion (location, op1); | 9659 op1 = c_common_truthvalue_conversion (location, op1); |
9312 converted = 1; | 9660 converted = 1; |
9313 } | 9661 boolean_op = true; |
9662 } | |
9314 if (code == TRUTH_ANDIF_EXPR) | 9663 if (code == TRUTH_ANDIF_EXPR) |
9315 { | 9664 { |
9316 int_const_or_overflow = (int_operands | 9665 int_const_or_overflow = (int_operands |
9317 && TREE_CODE (orig_op0) == INTEGER_CST | 9666 && TREE_CODE (orig_op0) == INTEGER_CST |
9318 && (op0 == truthvalue_false_node | 9667 && (op0 == truthvalue_false_node |
9338 /* Shift operations: result has same type as first operand; | 9687 /* Shift operations: result has same type as first operand; |
9339 always convert second operand to int. | 9688 always convert second operand to int. |
9340 Also set SHORT_SHIFT if shifting rightward. */ | 9689 Also set SHORT_SHIFT if shifting rightward. */ |
9341 | 9690 |
9342 case RSHIFT_EXPR: | 9691 case RSHIFT_EXPR: |
9343 if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE) | 9692 if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE |
9344 && code1 == INTEGER_TYPE) | 9693 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE) |
9345 { | |
9346 if (TREE_CODE (op1) == INTEGER_CST) | |
9347 { | 9694 { |
9348 if (tree_int_cst_sgn (op1) < 0) | 9695 result_type = type0; |
9696 converted = 1; | |
9697 } | |
9698 else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE | |
9699 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE | |
9700 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE | |
9701 && TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1)) | |
9702 { | |
9703 result_type = type0; | |
9704 converted = 1; | |
9705 } | |
9706 else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE) | |
9707 && code1 == INTEGER_TYPE) | |
9708 { | |
9709 if (TREE_CODE (op1) == INTEGER_CST) | |
9710 { | |
9711 if (tree_int_cst_sgn (op1) < 0) | |
9712 { | |
9713 int_const = false; | |
9714 if (c_inhibit_evaluation_warnings == 0) | |
9715 warning (0, "right shift count is negative"); | |
9716 } | |
9717 else | |
9718 { | |
9719 if (!integer_zerop (op1)) | |
9720 short_shift = 1; | |
9721 | |
9722 if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0) | |
9723 { | |
9724 int_const = false; | |
9725 if (c_inhibit_evaluation_warnings == 0) | |
9726 warning (0, "right shift count >= width of type"); | |
9727 } | |
9728 } | |
9729 } | |
9730 | |
9731 /* Use the type of the value to be shifted. */ | |
9732 result_type = type0; | |
9733 /* Convert the non vector shift-count to an integer, regardless | |
9734 of size of value being shifted. */ | |
9735 if (TREE_CODE (TREE_TYPE (op1)) != VECTOR_TYPE | |
9736 && TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) | |
9737 op1 = convert (integer_type_node, op1); | |
9738 /* Avoid converting op1 to result_type later. */ | |
9739 converted = 1; | |
9740 } | |
9741 break; | |
9742 | |
9743 case LSHIFT_EXPR: | |
9744 if (code0 == VECTOR_TYPE && code1 == INTEGER_TYPE | |
9745 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE) | |
9349 { | 9746 { |
9350 int_const = false; | 9747 result_type = type0; |
9351 if (c_inhibit_evaluation_warnings == 0) | 9748 converted = 1; |
9352 warning (0, "right shift count is negative"); | |
9353 } | 9749 } |
9354 else | 9750 else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE |
9355 { | 9751 && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE |
9356 if (!integer_zerop (op1)) | 9752 && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE |
9357 short_shift = 1; | 9753 && TYPE_VECTOR_SUBPARTS (type0) == TYPE_VECTOR_SUBPARTS (type1)) |
9358 | 9754 { |
9359 if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0) | 9755 result_type = type0; |
9360 { | 9756 converted = 1; |
9361 int_const = false; | 9757 } |
9362 if (c_inhibit_evaluation_warnings == 0) | 9758 else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE) |
9363 warning (0, "right shift count >= width of type"); | 9759 && code1 == INTEGER_TYPE) |
9364 } | 9760 { |
9365 } | 9761 if (TREE_CODE (op1) == INTEGER_CST) |
9366 } | 9762 { |
9367 | 9763 if (tree_int_cst_sgn (op1) < 0) |
9368 /* Use the type of the value to be shifted. */ | 9764 { |
9369 result_type = type0; | 9765 int_const = false; |
9370 /* Convert the shift-count to an integer, regardless of size | 9766 if (c_inhibit_evaluation_warnings == 0) |
9371 of value being shifted. */ | 9767 warning (0, "left shift count is negative"); |
9372 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) | 9768 } |
9373 op1 = convert (integer_type_node, op1); | 9769 |
9374 /* Avoid converting op1 to result_type later. */ | 9770 else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0) |
9375 converted = 1; | 9771 { |
9376 } | 9772 int_const = false; |
9377 break; | 9773 if (c_inhibit_evaluation_warnings == 0) |
9378 | 9774 warning (0, "left shift count >= width of type"); |
9379 case LSHIFT_EXPR: | 9775 } |
9380 if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE) | 9776 } |
9381 && code1 == INTEGER_TYPE) | 9777 |
9382 { | 9778 /* Use the type of the value to be shifted. */ |
9383 if (TREE_CODE (op1) == INTEGER_CST) | 9779 result_type = type0; |
9384 { | 9780 /* Convert the non vector shift-count to an integer, regardless |
9385 if (tree_int_cst_sgn (op1) < 0) | 9781 of size of value being shifted. */ |
9386 { | 9782 if (TREE_CODE (TREE_TYPE (op1)) != VECTOR_TYPE |
9387 int_const = false; | 9783 && TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) |
9388 if (c_inhibit_evaluation_warnings == 0) | 9784 op1 = convert (integer_type_node, op1); |
9389 warning (0, "left shift count is negative"); | 9785 /* Avoid converting op1 to result_type later. */ |
9390 } | 9786 converted = 1; |
9391 | 9787 } |
9392 else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0) | |
9393 { | |
9394 int_const = false; | |
9395 if (c_inhibit_evaluation_warnings == 0) | |
9396 warning (0, "left shift count >= width of type"); | |
9397 } | |
9398 } | |
9399 | |
9400 /* Use the type of the value to be shifted. */ | |
9401 result_type = type0; | |
9402 /* Convert the shift-count to an integer, regardless of size | |
9403 of value being shifted. */ | |
9404 if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) | |
9405 op1 = convert (integer_type_node, op1); | |
9406 /* Avoid converting op1 to result_type later. */ | |
9407 converted = 1; | |
9408 } | |
9409 break; | 9788 break; |
9410 | 9789 |
9411 case EQ_EXPR: | 9790 case EQ_EXPR: |
9412 case NE_EXPR: | 9791 case NE_EXPR: |
9413 if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)) | 9792 if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)) |
9416 "comparing floating point with == or != is unsafe"); | 9795 "comparing floating point with == or != is unsafe"); |
9417 /* Result of comparison is always int, | 9796 /* Result of comparison is always int, |
9418 but don't convert the args to int! */ | 9797 but don't convert the args to int! */ |
9419 build_type = integer_type_node; | 9798 build_type = integer_type_node; |
9420 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE | 9799 if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE |
9421 || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE) | 9800 || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE) |
9422 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE | 9801 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE |
9423 || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE)) | 9802 || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE)) |
9424 short_compare = 1; | 9803 short_compare = 1; |
9804 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1)) | |
9805 { | |
9806 if (TREE_CODE (op0) == ADDR_EXPR | |
9807 && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0))) | |
9808 { | |
9809 if (code == EQ_EXPR) | |
9810 warning_at (location, | |
9811 OPT_Waddress, | |
9812 "the comparison will always evaluate as %<false%> " | |
9813 "for the address of %qD will never be NULL", | |
9814 TREE_OPERAND (op0, 0)); | |
9815 else | |
9816 warning_at (location, | |
9817 OPT_Waddress, | |
9818 "the comparison will always evaluate as %<true%> " | |
9819 "for the address of %qD will never be NULL", | |
9820 TREE_OPERAND (op0, 0)); | |
9821 } | |
9822 result_type = type0; | |
9823 } | |
9824 else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0)) | |
9825 { | |
9826 if (TREE_CODE (op1) == ADDR_EXPR | |
9827 && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0))) | |
9828 { | |
9829 if (code == EQ_EXPR) | |
9830 warning_at (location, | |
9831 OPT_Waddress, | |
9832 "the comparison will always evaluate as %<false%> " | |
9833 "for the address of %qD will never be NULL", | |
9834 TREE_OPERAND (op1, 0)); | |
9835 else | |
9836 warning_at (location, | |
9837 OPT_Waddress, | |
9838 "the comparison will always evaluate as %<true%> " | |
9839 "for the address of %qD will never be NULL", | |
9840 TREE_OPERAND (op1, 0)); | |
9841 } | |
9842 result_type = type1; | |
9843 } | |
9425 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) | 9844 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) |
9426 { | 9845 { |
9427 tree tt0 = TREE_TYPE (type0); | 9846 tree tt0 = TREE_TYPE (type0); |
9428 tree tt1 = TREE_TYPE (type1); | 9847 tree tt1 = TREE_TYPE (type1); |
9429 addr_space_t as0 = TYPE_ADDR_SPACE (tt0); | 9848 addr_space_t as0 = TYPE_ADDR_SPACE (tt0); |
9430 addr_space_t as1 = TYPE_ADDR_SPACE (tt1); | 9849 addr_space_t as1 = TYPE_ADDR_SPACE (tt1); |
9431 addr_space_t as_common = ADDR_SPACE_GENERIC; | 9850 addr_space_t as_common = ADDR_SPACE_GENERIC; |
9432 | 9851 |
9433 /* Anything compares with void *. void * compares with anything. | 9852 /* Anything compares with void *. void * compares with anything. |
9434 Otherwise, the targets must be compatible | 9853 Otherwise, the targets must be compatible |
9435 and both must be object or both incomplete. */ | 9854 and both must be object or both incomplete. */ |
9436 if (comp_target_types (location, type0, type1)) | 9855 if (comp_target_types (location, type0, type1)) |
9437 result_type = common_pointer_type (type0, type1); | 9856 result_type = common_pointer_type (type0, type1); |
9438 else if (null_pointer_constant_p (orig_op0)) | 9857 else if (!addr_space_superset (as0, as1, &as_common)) |
9439 result_type = type1; | 9858 { |
9440 else if (null_pointer_constant_p (orig_op1)) | 9859 error_at (location, "comparison of pointers to " |
9441 result_type = type0; | 9860 "disjoint address spaces"); |
9442 else if (!addr_space_superset (as0, as1, &as_common)) | 9861 return error_mark_node; |
9443 { | 9862 } |
9444 error_at (location, "comparison of pointers to " | 9863 else if (VOID_TYPE_P (tt0)) |
9445 "disjoint address spaces"); | 9864 { |
9446 return error_mark_node; | 9865 if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE) |
9447 } | 9866 pedwarn (location, OPT_pedantic, "ISO C forbids " |
9448 else if (VOID_TYPE_P (tt0)) | 9867 "comparison of %<void *%> with function pointer"); |
9449 { | 9868 } |
9450 if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE) | 9869 else if (VOID_TYPE_P (tt1)) |
9451 pedwarn (location, OPT_pedantic, "ISO C forbids " | 9870 { |
9452 "comparison of %<void *%> with function pointer"); | 9871 if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE) |
9453 } | 9872 pedwarn (location, OPT_pedantic, "ISO C forbids " |
9454 else if (VOID_TYPE_P (tt1)) | 9873 "comparison of %<void *%> with function pointer"); |
9455 { | 9874 } |
9456 if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE) | 9875 else |
9457 pedwarn (location, OPT_pedantic, "ISO C forbids " | 9876 /* Avoid warning about the volatile ObjC EH puts on decls. */ |
9458 "comparison of %<void *%> with function pointer"); | 9877 if (!objc_ok) |
9459 } | 9878 pedwarn (location, 0, |
9460 else | 9879 "comparison of distinct pointer types lacks a cast"); |
9461 /* Avoid warning about the volatile ObjC EH puts on decls. */ | 9880 |
9462 if (!objc_ok) | 9881 if (result_type == NULL_TREE) |
9463 pedwarn (location, 0, | 9882 { |
9464 "comparison of distinct pointer types lacks a cast"); | 9883 int qual = ENCODE_QUAL_ADDR_SPACE (as_common); |
9465 | 9884 result_type = build_pointer_type |
9466 if (result_type == NULL_TREE) | 9885 (build_qualified_type (void_type_node, qual)); |
9467 { | 9886 } |
9468 int qual = ENCODE_QUAL_ADDR_SPACE (as_common); | 9887 } |
9469 result_type = build_pointer_type | |
9470 (build_qualified_type (void_type_node, qual)); | |
9471 } | |
9472 } | |
9473 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1)) | |
9474 { | |
9475 if (TREE_CODE (op0) == ADDR_EXPR | |
9476 && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0))) | |
9477 warning_at (location, | |
9478 OPT_Waddress, "the address of %qD will never be NULL", | |
9479 TREE_OPERAND (op0, 0)); | |
9480 result_type = type0; | |
9481 } | |
9482 else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0)) | |
9483 { | |
9484 if (TREE_CODE (op1) == ADDR_EXPR | |
9485 && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0))) | |
9486 warning_at (location, | |
9487 OPT_Waddress, "the address of %qD will never be NULL", | |
9488 TREE_OPERAND (op1, 0)); | |
9489 result_type = type1; | |
9490 } | |
9491 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) | 9888 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) |
9492 { | 9889 { |
9493 result_type = type0; | 9890 result_type = type0; |
9494 pedwarn (location, 0, "comparison between pointer and integer"); | 9891 pedwarn (location, 0, "comparison between pointer and integer"); |
9495 } | 9892 } |
9509 || code0 == FIXED_POINT_TYPE) | 9906 || code0 == FIXED_POINT_TYPE) |
9510 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE | 9907 && (code1 == INTEGER_TYPE || code1 == REAL_TYPE |
9511 || code1 == FIXED_POINT_TYPE)) | 9908 || code1 == FIXED_POINT_TYPE)) |
9512 short_compare = 1; | 9909 short_compare = 1; |
9513 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) | 9910 else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) |
9514 { | 9911 { |
9515 addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0)); | 9912 addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0)); |
9516 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1)); | 9913 addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1)); |
9517 addr_space_t as_common; | 9914 addr_space_t as_common; |
9518 | 9915 |
9519 if (comp_target_types (location, type0, type1)) | 9916 if (comp_target_types (location, type0, type1)) |
9520 { | 9917 { |
9521 result_type = common_pointer_type (type0, type1); | 9918 result_type = common_pointer_type (type0, type1); |
9522 if (!COMPLETE_TYPE_P (TREE_TYPE (type0)) | 9919 if (!COMPLETE_TYPE_P (TREE_TYPE (type0)) |
9523 != !COMPLETE_TYPE_P (TREE_TYPE (type1))) | 9920 != !COMPLETE_TYPE_P (TREE_TYPE (type1))) |
9524 pedwarn (location, 0, | 9921 pedwarn (location, 0, |
9525 "comparison of complete and incomplete pointers"); | 9922 "comparison of complete and incomplete pointers"); |
9526 else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE) | 9923 else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE) |
9527 pedwarn (location, OPT_pedantic, "ISO C forbids " | 9924 pedwarn (location, OPT_pedantic, "ISO C forbids " |
9528 "ordered comparisons of pointers to functions"); | 9925 "ordered comparisons of pointers to functions"); |
9529 } | 9926 else if (null_pointer_constant_p (orig_op0) |
9530 else if (!addr_space_superset (as0, as1, &as_common)) | 9927 || null_pointer_constant_p (orig_op1)) |
9531 { | 9928 warning_at (location, OPT_Wextra, |
9532 error_at (location, "comparison of pointers to " | 9929 "ordered comparison of pointer with null pointer"); |
9533 "disjoint address spaces"); | 9930 |
9534 return error_mark_node; | 9931 } |
9535 } | 9932 else if (!addr_space_superset (as0, as1, &as_common)) |
9536 else | 9933 { |
9537 { | 9934 error_at (location, "comparison of pointers to " |
9538 int qual = ENCODE_QUAL_ADDR_SPACE (as_common); | 9935 "disjoint address spaces"); |
9539 result_type = build_pointer_type | 9936 return error_mark_node; |
9540 (build_qualified_type (void_type_node, qual)); | 9937 } |
9541 pedwarn (location, 0, | 9938 else |
9542 "comparison of distinct pointer types lacks a cast"); | 9939 { |
9543 } | 9940 int qual = ENCODE_QUAL_ADDR_SPACE (as_common); |
9544 } | 9941 result_type = build_pointer_type |
9942 (build_qualified_type (void_type_node, qual)); | |
9943 pedwarn (location, 0, | |
9944 "comparison of distinct pointer types lacks a cast"); | |
9945 } | |
9946 } | |
9545 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1)) | 9947 else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1)) |
9546 { | 9948 { |
9547 result_type = type0; | 9949 result_type = type0; |
9548 if (pedantic) | 9950 if (pedantic) |
9549 pedwarn (location, OPT_pedantic, | 9951 pedwarn (location, OPT_pedantic, |
9550 "ordered comparison of pointer with integer zero"); | 9952 "ordered comparison of pointer with integer zero"); |
9551 else if (extra_warnings) | 9953 else if (extra_warnings) |
9552 warning_at (location, OPT_Wextra, | 9954 warning_at (location, OPT_Wextra, |
9553 "ordered comparison of pointer with integer zero"); | 9955 "ordered comparison of pointer with integer zero"); |
9554 } | 9956 } |
9555 else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0)) | 9957 else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0)) |
9556 { | 9958 { |
9557 result_type = type1; | 9959 result_type = type1; |
9558 pedwarn (location, OPT_pedantic, | 9960 if (pedantic) |
9559 "ordered comparison of pointer with integer zero"); | 9961 pedwarn (location, OPT_pedantic, |
9560 } | 9962 "ordered comparison of pointer with integer zero"); |
9963 else if (extra_warnings) | |
9964 warning_at (location, OPT_Wextra, | |
9965 "ordered comparison of pointer with integer zero"); | |
9966 } | |
9561 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) | 9967 else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) |
9562 { | 9968 { |
9563 result_type = type0; | 9969 result_type = type0; |
9564 pedwarn (location, 0, "comparison between pointer and integer"); | 9970 pedwarn (location, 0, "comparison between pointer and integer"); |
9565 } | 9971 } |
9595 bool first_complex = (code0 == COMPLEX_TYPE); | 10001 bool first_complex = (code0 == COMPLEX_TYPE); |
9596 bool second_complex = (code1 == COMPLEX_TYPE); | 10002 bool second_complex = (code1 == COMPLEX_TYPE); |
9597 int none_complex = (!first_complex && !second_complex); | 10003 int none_complex = (!first_complex && !second_complex); |
9598 | 10004 |
9599 if (shorten || common || short_compare) | 10005 if (shorten || common || short_compare) |
9600 { | 10006 { |
9601 result_type = c_common_type (type0, type1); | 10007 result_type = c_common_type (type0, type1); |
9602 if (result_type == error_mark_node) | 10008 do_warn_double_promotion (result_type, type0, type1, |
9603 return error_mark_node; | 10009 "implicit conversion from %qT to %qT " |
9604 } | 10010 "to match other operand of binary " |
10011 "expression", | |
10012 location); | |
10013 if (result_type == error_mark_node) | |
10014 return error_mark_node; | |
10015 } | |
9605 | 10016 |
9606 if (first_complex != second_complex | 10017 if (first_complex != second_complex |
9607 && (code == PLUS_EXPR | 10018 && (code == PLUS_EXPR |
9608 || code == MINUS_EXPR | 10019 || code == MINUS_EXPR |
9609 || code == MULT_EXPR | 10020 || code == MULT_EXPR |
9610 || (code == TRUNC_DIV_EXPR && first_complex)) | 10021 || (code == TRUNC_DIV_EXPR && first_complex)) |
9611 && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE | 10022 && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE |
9612 && flag_signed_zeros) | 10023 && flag_signed_zeros) |
9613 { | 10024 { |
9614 /* An operation on mixed real/complex operands must be | 10025 /* An operation on mixed real/complex operands must be |
9615 handled specially, but the language-independent code can | 10026 handled specially, but the language-independent code can |
9616 more easily optimize the plain complex arithmetic if | 10027 more easily optimize the plain complex arithmetic if |
9617 -fno-signed-zeros. */ | 10028 -fno-signed-zeros. */ |
9618 tree real_type = TREE_TYPE (result_type); | 10029 tree real_type = TREE_TYPE (result_type); |
9619 tree real, imag; | 10030 tree real, imag; |
9620 if (type0 != orig_type0 || type1 != orig_type1) | 10031 if (type0 != orig_type0 || type1 != orig_type1) |
9621 { | 10032 { |
9622 gcc_assert (may_need_excess_precision && common); | 10033 gcc_assert (may_need_excess_precision && common); |
9623 real_result_type = c_common_type (orig_type0, orig_type1); | 10034 semantic_result_type = c_common_type (orig_type0, orig_type1); |
9624 } | 10035 } |
9625 if (first_complex) | 10036 if (first_complex) |
9626 { | 10037 { |
9627 if (TREE_TYPE (op0) != result_type) | 10038 if (TREE_TYPE (op0) != result_type) |
9628 op0 = convert_and_check (result_type, op0); | 10039 op0 = convert_and_check (result_type, op0); |
9629 if (TREE_TYPE (op1) != real_type) | 10040 if (TREE_TYPE (op1) != real_type) |
9630 op1 = convert_and_check (real_type, op1); | 10041 op1 = convert_and_check (real_type, op1); |
9631 } | 10042 } |
9632 else | 10043 else |
9633 { | 10044 { |
9634 if (TREE_TYPE (op0) != real_type) | 10045 if (TREE_TYPE (op0) != real_type) |
9635 op0 = convert_and_check (real_type, op0); | 10046 op0 = convert_and_check (real_type, op0); |
9636 if (TREE_TYPE (op1) != result_type) | 10047 if (TREE_TYPE (op1) != result_type) |
9637 op1 = convert_and_check (result_type, op1); | 10048 op1 = convert_and_check (result_type, op1); |
9638 } | 10049 } |
9639 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK) | 10050 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK) |
9640 return error_mark_node; | 10051 return error_mark_node; |
9641 if (first_complex) | 10052 if (first_complex) |
9642 { | 10053 { |
9643 op0 = c_save_expr (op0); | 10054 op0 = c_save_expr (op0); |
9644 real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR, | 10055 real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR, |
9645 op0, 1); | 10056 op0, 1); |
9646 imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR, | 10057 imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR, |
9647 op0, 1); | 10058 op0, 1); |
9648 switch (code) | 10059 switch (code) |
9649 { | 10060 { |
9650 case MULT_EXPR: | 10061 case MULT_EXPR: |
9651 case TRUNC_DIV_EXPR: | 10062 case TRUNC_DIV_EXPR: |
9652 imag = build2 (resultcode, real_type, imag, op1); | 10063 imag = build2 (resultcode, real_type, imag, op1); |
9653 /* Fall through. */ | 10064 /* Fall through. */ |
9654 case PLUS_EXPR: | 10065 case PLUS_EXPR: |
9655 case MINUS_EXPR: | 10066 case MINUS_EXPR: |
9656 real = build2 (resultcode, real_type, real, op1); | 10067 real = build2 (resultcode, real_type, real, op1); |
9657 break; | 10068 break; |
9658 default: | 10069 default: |
9659 gcc_unreachable(); | 10070 gcc_unreachable(); |
9660 } | 10071 } |
9661 } | 10072 } |
9662 else | 10073 else |
9663 { | 10074 { |
9664 op1 = c_save_expr (op1); | 10075 op1 = c_save_expr (op1); |
9665 real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR, | 10076 real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR, |
9666 op1, 1); | 10077 op1, 1); |
9667 imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR, | 10078 imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR, |
9668 op1, 1); | 10079 op1, 1); |
9669 switch (code) | 10080 switch (code) |
9670 { | 10081 { |
9671 case MULT_EXPR: | 10082 case MULT_EXPR: |
9672 imag = build2 (resultcode, real_type, op0, imag); | 10083 imag = build2 (resultcode, real_type, op0, imag); |
9673 /* Fall through. */ | 10084 /* Fall through. */ |
9674 case PLUS_EXPR: | 10085 case PLUS_EXPR: |
9675 real = build2 (resultcode, real_type, op0, real); | 10086 real = build2 (resultcode, real_type, op0, real); |
9676 break; | 10087 break; |
9677 case MINUS_EXPR: | 10088 case MINUS_EXPR: |
9678 real = build2 (resultcode, real_type, op0, real); | 10089 real = build2 (resultcode, real_type, op0, real); |
9679 imag = build1 (NEGATE_EXPR, real_type, imag); | 10090 imag = build1 (NEGATE_EXPR, real_type, imag); |
9680 break; | 10091 break; |
9681 default: | 10092 default: |
9682 gcc_unreachable(); | 10093 gcc_unreachable(); |
9683 } | 10094 } |
9684 } | 10095 } |
9685 ret = build2 (COMPLEX_EXPR, result_type, real, imag); | 10096 ret = build2 (COMPLEX_EXPR, result_type, real, imag); |
9686 goto return_build_binary_op; | 10097 goto return_build_binary_op; |
9687 } | 10098 } |
9688 | 10099 |
9689 /* For certain operations (which identify themselves by shorten != 0) | 10100 /* For certain operations (which identify themselves by shorten != 0) |
9690 if both args were extended from the same smaller type, | 10101 if both args were extended from the same smaller type, |
9691 do the arithmetic in that type and then extend. | 10102 do the arithmetic in that type and then extend. |
9692 | 10103 |
9815 { | 10226 { |
9816 binary_op_error (location, code, TREE_TYPE (op0), TREE_TYPE (op1)); | 10227 binary_op_error (location, code, TREE_TYPE (op0), TREE_TYPE (op1)); |
9817 return error_mark_node; | 10228 return error_mark_node; |
9818 } | 10229 } |
9819 | 10230 |
10231 if (build_type == NULL_TREE) | |
10232 { | |
10233 build_type = result_type; | |
10234 if ((type0 != orig_type0 || type1 != orig_type1) | |
10235 && !boolean_op) | |
10236 { | |
10237 gcc_assert (may_need_excess_precision && common); | |
10238 semantic_result_type = c_common_type (orig_type0, orig_type1); | |
10239 } | |
10240 } | |
10241 | |
9820 if (!converted) | 10242 if (!converted) |
9821 { | 10243 { |
9822 if (TREE_TYPE (op0) != result_type) | 10244 op0 = ep_convert_and_check (result_type, op0, semantic_result_type); |
9823 op0 = convert_and_check (result_type, op0); | 10245 op1 = ep_convert_and_check (result_type, op1, semantic_result_type); |
9824 if (TREE_TYPE (op1) != result_type) | |
9825 op1 = convert_and_check (result_type, op1); | |
9826 | 10246 |
9827 /* This can happen if one operand has a vector type, and the other | 10247 /* This can happen if one operand has a vector type, and the other |
9828 has a different type. */ | 10248 has a different type. */ |
9829 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK) | 10249 if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK) |
9830 return error_mark_node; | 10250 return error_mark_node; |
9831 } | |
9832 | |
9833 if (build_type == NULL_TREE) | |
9834 { | |
9835 build_type = result_type; | |
9836 if (type0 != orig_type0 || type1 != orig_type1) | |
9837 { | |
9838 gcc_assert (may_need_excess_precision && common); | |
9839 real_result_type = c_common_type (orig_type0, orig_type1); | |
9840 } | |
9841 } | 10251 } |
9842 | 10252 |
9843 /* Treat expressions in initializers specially as they can't trap. */ | 10253 /* Treat expressions in initializers specially as they can't trap. */ |
9844 if (int_const_or_overflow) | 10254 if (int_const_or_overflow) |
9845 ret = (require_constant_value | 10255 ret = (require_constant_value |
9858 ? note_integer_operands (ret) | 10268 ? note_integer_operands (ret) |
9859 : build1 (NOP_EXPR, TREE_TYPE (ret), ret)); | 10269 : build1 (NOP_EXPR, TREE_TYPE (ret), ret)); |
9860 else if (TREE_CODE (ret) != INTEGER_CST && int_operands | 10270 else if (TREE_CODE (ret) != INTEGER_CST && int_operands |
9861 && !in_late_binary_op) | 10271 && !in_late_binary_op) |
9862 ret = note_integer_operands (ret); | 10272 ret = note_integer_operands (ret); |
9863 if (real_result_type) | 10273 if (semantic_result_type) |
9864 ret = build1 (EXCESS_PRECISION_EXPR, real_result_type, ret); | 10274 ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret); |
9865 protected_set_expr_location (ret, location); | 10275 protected_set_expr_location (ret, location); |
9866 return ret; | 10276 return ret; |
9867 } | 10277 } |
9868 | 10278 |
9869 | 10279 |
9885 error_at (location, "used struct type value where scalar is required"); | 10295 error_at (location, "used struct type value where scalar is required"); |
9886 return error_mark_node; | 10296 return error_mark_node; |
9887 | 10297 |
9888 case UNION_TYPE: | 10298 case UNION_TYPE: |
9889 error_at (location, "used union type value where scalar is required"); | 10299 error_at (location, "used union type value where scalar is required"); |
10300 return error_mark_node; | |
10301 | |
10302 case VOID_TYPE: | |
10303 error_at (location, "void value not ignored as it ought to be"); | |
9890 return error_mark_node; | 10304 return error_mark_node; |
9891 | 10305 |
9892 case FUNCTION_TYPE: | 10306 case FUNCTION_TYPE: |
9893 gcc_unreachable (); | 10307 gcc_unreachable (); |
9894 | 10308 |
9899 int_const = (TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr)); | 10313 int_const = (TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr)); |
9900 int_operands = EXPR_INT_CONST_OPERANDS (expr); | 10314 int_operands = EXPR_INT_CONST_OPERANDS (expr); |
9901 if (int_operands) | 10315 if (int_operands) |
9902 expr = remove_c_maybe_const_expr (expr); | 10316 expr = remove_c_maybe_const_expr (expr); |
9903 | 10317 |
9904 /* ??? Should we also give an error for void and vectors rather than | 10318 /* ??? Should we also give an error for vectors rather than leaving |
9905 leaving those to give errors later? */ | 10319 those to give errors later? */ |
9906 expr = c_common_truthvalue_conversion (location, expr); | 10320 expr = c_common_truthvalue_conversion (location, expr); |
9907 | 10321 |
9908 if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const) | 10322 if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const) |
9909 { | 10323 { |
9910 if (TREE_OVERFLOW (expr)) | 10324 if (TREE_OVERFLOW (expr)) |