Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-common.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | 3bfb6c00c1e0 |
children | 326d9e06c2e3 b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
31 #include "rtl.h" | 31 #include "rtl.h" |
32 #include "ggc.h" | 32 #include "ggc.h" |
33 #include "varray.h" | 33 #include "varray.h" |
34 #include "expr.h" | 34 #include "expr.h" |
35 #include "c-common.h" | 35 #include "c-common.h" |
36 #include "diagnostic.h" | |
37 #include "tm_p.h" | 36 #include "tm_p.h" |
38 #include "obstack.h" | 37 #include "obstack.h" |
39 #include "cpplib.h" | 38 #include "cpplib.h" |
40 #include "target.h" | 39 #include "target.h" |
41 #include "langhooks.h" | 40 #include "langhooks.h" |
42 #include "tree-inline.h" | 41 #include "tree-inline.h" |
43 #include "c-tree.h" | 42 #include "c-tree.h" |
44 #include "toplev.h" | 43 #include "toplev.h" |
44 #include "diagnostic.h" | |
45 #include "tree-iterator.h" | 45 #include "tree-iterator.h" |
46 #include "hashtab.h" | 46 #include "hashtab.h" |
47 #include "tree-mudflap.h" | 47 #include "tree-mudflap.h" |
48 #include "opts.h" | 48 #include "opts.h" |
49 #include "real.h" | 49 #include "real.h" |
53 #include "fixed-value.h" | 53 #include "fixed-value.h" |
54 #include "libfuncs.h" | 54 #include "libfuncs.h" |
55 | 55 |
56 cpp_reader *parse_in; /* Declared in c-pragma.h. */ | 56 cpp_reader *parse_in; /* Declared in c-pragma.h. */ |
57 | 57 |
58 /* We let tm.h override the types used here, to handle trivial differences | |
59 such as the choice of unsigned int or long unsigned int for size_t. | |
60 When machines start needing nontrivial differences in the size type, | |
61 it would be best to do something here to figure out automatically | |
62 from other information what type to use. */ | |
63 | |
64 #ifndef SIZE_TYPE | |
65 #define SIZE_TYPE "long unsigned int" | |
66 #endif | |
67 | |
68 #ifndef PID_TYPE | |
69 #define PID_TYPE "int" | |
70 #endif | |
71 | |
72 #ifndef CHAR16_TYPE | |
73 #define CHAR16_TYPE "short unsigned int" | |
74 #endif | |
75 | |
76 #ifndef CHAR32_TYPE | |
77 #define CHAR32_TYPE "unsigned int" | |
78 #endif | |
79 | |
80 #ifndef WCHAR_TYPE | |
81 #define WCHAR_TYPE "int" | |
82 #endif | |
83 | |
84 /* WCHAR_TYPE gets overridden by -fshort-wchar. */ | |
85 #define MODIFIED_WCHAR_TYPE \ | |
86 (flag_short_wchar ? "short unsigned int" : WCHAR_TYPE) | |
87 | |
88 #ifndef PTRDIFF_TYPE | |
89 #define PTRDIFF_TYPE "long int" | |
90 #endif | |
91 | |
92 #ifndef WINT_TYPE | |
93 #define WINT_TYPE "unsigned int" | |
94 #endif | |
95 | |
96 #ifndef INTMAX_TYPE | |
97 #define INTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \ | |
98 ? "int" \ | |
99 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \ | |
100 ? "long int" \ | |
101 : "long long int")) | |
102 #endif | |
103 | |
104 #ifndef UINTMAX_TYPE | |
105 #define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \ | |
106 ? "unsigned int" \ | |
107 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \ | |
108 ? "long unsigned int" \ | |
109 : "long long unsigned int")) | |
110 #endif | |
111 | |
112 /* The following symbols are subsumed in the c_global_trees array, and | 58 /* The following symbols are subsumed in the c_global_trees array, and |
113 listed here individually for documentation purposes. | 59 listed here individually for documentation purposes. |
114 | 60 |
115 INTEGER_TYPE and REAL_TYPE nodes for the standard data types. | 61 INTEGER_TYPE and REAL_TYPE nodes for the standard data types. |
116 | 62 |
129 tree ptrdiff_type_node; | 75 tree ptrdiff_type_node; |
130 | 76 |
131 tree unsigned_char_type_node; | 77 tree unsigned_char_type_node; |
132 tree signed_char_type_node; | 78 tree signed_char_type_node; |
133 tree wchar_type_node; | 79 tree wchar_type_node; |
134 tree signed_wchar_type_node; | |
135 tree unsigned_wchar_type_node; | |
136 | 80 |
137 tree char16_type_node; | 81 tree char16_type_node; |
138 tree char32_type_node; | 82 tree char32_type_node; |
139 | 83 |
140 tree float_type_node; | 84 tree float_type_node; |
473 /* Nonzero means to generate thread-safe code for initializing local | 417 /* Nonzero means to generate thread-safe code for initializing local |
474 statics. */ | 418 statics. */ |
475 | 419 |
476 int flag_threadsafe_statics = 1; | 420 int flag_threadsafe_statics = 1; |
477 | 421 |
422 /* Nonzero if we want to pretty-print template specializations as the | |
423 template signature followed by the arguments. */ | |
424 | |
425 int flag_pretty_templates = 1; | |
426 | |
478 /* Nonzero means warn about implicit declarations. */ | 427 /* Nonzero means warn about implicit declarations. */ |
479 | 428 |
480 int warn_implicit = 1; | 429 int warn_implicit = 1; |
481 | 430 |
482 /* Maximum template instantiation depth. This limit is rather | 431 /* Maximum template instantiation depth. This limit exists to limit the |
483 arbitrary, but it exists to limit the time it takes to notice | 432 time it takes to notice infinite template instantiations; the default |
484 infinite template instantiations. */ | 433 value of 1024 is likely to be in the next C++ standard. */ |
485 | 434 |
486 int max_tinst_depth = 500; | 435 int max_tinst_depth = 1024; |
487 | 436 |
488 | 437 |
489 | 438 |
490 /* The elements of `ridpointers' are identifier nodes for the reserved | 439 /* The elements of `ridpointers' are identifier nodes for the reserved |
491 type names and storage classes. It is indexed by a RID_... value. */ | 440 type names and storage classes. It is indexed by a RID_... value. */ |
492 tree *ridpointers; | 441 tree *ridpointers; |
493 | 442 |
494 tree (*make_fname_decl) (tree, int); | 443 tree (*make_fname_decl) (location_t, tree, int); |
495 | 444 |
496 /* Nonzero means the expression being parsed will never be evaluated. | 445 /* Nonzero means don't warn about problems that occur when the code is |
497 This is a count, since unevaluated expressions can nest. */ | 446 executed. */ |
498 int skip_evaluation; | 447 int c_inhibit_evaluation_warnings; |
448 | |
449 /* Whether lexing has been completed, so subsequent preprocessor | |
450 errors should use the compiler's input_location. */ | |
451 bool done_lexing = false; | |
499 | 452 |
500 /* Information about how a function name is generated. */ | 453 /* Information about how a function name is generated. */ |
501 struct fname_var_t | 454 struct fname_var_t |
502 { | 455 { |
503 tree *const decl; /* pointer to the VAR_DECL. */ | 456 tree *const decl; /* pointer to the VAR_DECL. */ |
516 /* GCC __PRETTY_FUNCTION__ compliant. */ | 469 /* GCC __PRETTY_FUNCTION__ compliant. */ |
517 {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1}, | 470 {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1}, |
518 {NULL, 0, 0}, | 471 {NULL, 0, 0}, |
519 }; | 472 }; |
520 | 473 |
474 static tree c_fully_fold_internal (tree expr, bool, bool *, bool *); | |
521 static tree check_case_value (tree); | 475 static tree check_case_value (tree); |
522 static bool check_case_bounds (tree, tree, tree *, tree *); | 476 static bool check_case_bounds (tree, tree, tree *, tree *); |
523 | 477 |
524 static tree handle_packed_attribute (tree *, tree, tree, int, bool *); | 478 static tree handle_packed_attribute (tree *, tree, tree, int, bool *); |
525 static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *); | 479 static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *); |
526 static tree handle_common_attribute (tree *, tree, tree, int, bool *); | 480 static tree handle_common_attribute (tree *, tree, tree, int, bool *); |
527 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *); | 481 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *); |
528 static tree handle_hot_attribute (tree *, tree, tree, int, bool *); | 482 static tree handle_hot_attribute (tree *, tree, tree, int, bool *); |
529 static tree handle_cold_attribute (tree *, tree, tree, int, bool *); | 483 static tree handle_cold_attribute (tree *, tree, tree, int, bool *); |
530 static tree handle_noinline_attribute (tree *, tree, tree, int, bool *); | 484 static tree handle_noinline_attribute (tree *, tree, tree, int, bool *); |
485 static tree handle_noclone_attribute (tree *, tree, tree, int, bool *); | |
531 static tree handle_always_inline_attribute (tree *, tree, tree, int, | 486 static tree handle_always_inline_attribute (tree *, tree, tree, int, |
532 bool *); | 487 bool *); |
533 static tree handle_gnu_inline_attribute (tree *, tree, tree, int, bool *); | 488 static tree handle_gnu_inline_attribute (tree *, tree, tree, int, bool *); |
534 static tree handle_artificial_attribute (tree *, tree, tree, int, bool *); | 489 static tree handle_artificial_attribute (tree *, tree, tree, int, bool *); |
535 static tree handle_flatten_attribute (tree *, tree, tree, int, bool *); | 490 static tree handle_flatten_attribute (tree *, tree, tree, int, bool *); |
600 | 555 |
601 const struct c_common_resword c_common_reswords[] = | 556 const struct c_common_resword c_common_reswords[] = |
602 { | 557 { |
603 { "_Bool", RID_BOOL, D_CONLY }, | 558 { "_Bool", RID_BOOL, D_CONLY }, |
604 { "_Complex", RID_COMPLEX, 0 }, | 559 { "_Complex", RID_COMPLEX, 0 }, |
560 { "_Imaginary", RID_IMAGINARY, D_CONLY }, | |
605 { "_Decimal32", RID_DFLOAT32, D_CONLY | D_EXT }, | 561 { "_Decimal32", RID_DFLOAT32, D_CONLY | D_EXT }, |
606 { "_Decimal64", RID_DFLOAT64, D_CONLY | D_EXT }, | 562 { "_Decimal64", RID_DFLOAT64, D_CONLY | D_EXT }, |
607 { "_Decimal128", RID_DFLOAT128, D_CONLY | D_EXT }, | 563 { "_Decimal128", RID_DFLOAT128, D_CONLY | D_EXT }, |
608 { "_Fract", RID_FRACT, D_CONLY | D_EXT }, | 564 { "_Fract", RID_FRACT, D_CONLY | D_EXT }, |
609 { "_Accum", RID_ACCUM, D_CONLY | D_EXT }, | 565 { "_Accum", RID_ACCUM, D_CONLY | D_EXT }, |
641 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO, D_CXXONLY }, | 597 { "__is_convertible_to", RID_IS_CONVERTIBLE_TO, D_CXXONLY }, |
642 { "__is_empty", RID_IS_EMPTY, D_CXXONLY }, | 598 { "__is_empty", RID_IS_EMPTY, D_CXXONLY }, |
643 { "__is_enum", RID_IS_ENUM, D_CXXONLY }, | 599 { "__is_enum", RID_IS_ENUM, D_CXXONLY }, |
644 { "__is_pod", RID_IS_POD, D_CXXONLY }, | 600 { "__is_pod", RID_IS_POD, D_CXXONLY }, |
645 { "__is_polymorphic", RID_IS_POLYMORPHIC, D_CXXONLY }, | 601 { "__is_polymorphic", RID_IS_POLYMORPHIC, D_CXXONLY }, |
602 { "__is_standard_layout", RID_IS_STD_LAYOUT, D_CXXONLY }, | |
603 { "__is_trivial", RID_IS_TRIVIAL, D_CXXONLY }, | |
646 { "__is_union", RID_IS_UNION, D_CXXONLY }, | 604 { "__is_union", RID_IS_UNION, D_CXXONLY }, |
647 { "__imag", RID_IMAGPART, 0 }, | 605 { "__imag", RID_IMAGPART, 0 }, |
648 { "__imag__", RID_IMAGPART, 0 }, | 606 { "__imag__", RID_IMAGPART, 0 }, |
649 { "__inline", RID_INLINE, 0 }, | 607 { "__inline", RID_INLINE, 0 }, |
650 { "__inline__", RID_INLINE, 0 }, | 608 { "__inline__", RID_INLINE, 0 }, |
659 { "__thread", RID_THREAD, 0 }, | 617 { "__thread", RID_THREAD, 0 }, |
660 { "__typeof", RID_TYPEOF, 0 }, | 618 { "__typeof", RID_TYPEOF, 0 }, |
661 { "__typeof__", RID_TYPEOF, 0 }, | 619 { "__typeof__", RID_TYPEOF, 0 }, |
662 { "__volatile", RID_VOLATILE, 0 }, | 620 { "__volatile", RID_VOLATILE, 0 }, |
663 { "__volatile__", RID_VOLATILE, 0 }, | 621 { "__volatile__", RID_VOLATILE, 0 }, |
622 { "alignof", RID_ALIGNOF, D_CXXONLY | D_CXX0X | D_CXXWARN }, | |
664 { "asm", RID_ASM, D_ASM }, | 623 { "asm", RID_ASM, D_ASM }, |
665 { "auto", RID_AUTO, 0 }, | 624 { "auto", RID_AUTO, 0 }, |
666 { "bool", RID_BOOL, D_CXXONLY | D_CXXWARN }, | 625 { "bool", RID_BOOL, D_CXXONLY | D_CXXWARN }, |
667 { "break", RID_BREAK, 0 }, | 626 { "break", RID_BREAK, 0 }, |
668 { "case", RID_CASE, 0 }, | 627 { "case", RID_CASE, 0 }, |
670 { "char", RID_CHAR, 0 }, | 629 { "char", RID_CHAR, 0 }, |
671 { "char16_t", RID_CHAR16, D_CXXONLY | D_CXX0X | D_CXXWARN }, | 630 { "char16_t", RID_CHAR16, D_CXXONLY | D_CXX0X | D_CXXWARN }, |
672 { "char32_t", RID_CHAR32, D_CXXONLY | D_CXX0X | D_CXXWARN }, | 631 { "char32_t", RID_CHAR32, D_CXXONLY | D_CXX0X | D_CXXWARN }, |
673 { "class", RID_CLASS, D_CXX_OBJC | D_CXXWARN }, | 632 { "class", RID_CLASS, D_CXX_OBJC | D_CXXWARN }, |
674 { "const", RID_CONST, 0 }, | 633 { "const", RID_CONST, 0 }, |
634 { "constexpr", RID_CONSTEXPR, D_CXXONLY | D_CXX0X | D_CXXWARN }, | |
675 { "const_cast", RID_CONSTCAST, D_CXXONLY | D_CXXWARN }, | 635 { "const_cast", RID_CONSTCAST, D_CXXONLY | D_CXXWARN }, |
676 { "continue", RID_CONTINUE, 0 }, | 636 { "continue", RID_CONTINUE, 0 }, |
677 { "decltype", RID_DECLTYPE, D_CXXONLY | D_CXX0X | D_CXXWARN }, | 637 { "decltype", RID_DECLTYPE, D_CXXONLY | D_CXX0X | D_CXXWARN }, |
678 { "default", RID_DEFAULT, 0 }, | 638 { "default", RID_DEFAULT, 0 }, |
679 { "delete", RID_DELETE, D_CXXONLY | D_CXXWARN }, | 639 { "delete", RID_DELETE, D_CXXONLY | D_CXXWARN }, |
748 { "byref", RID_BYREF, D_OBJC }, | 708 { "byref", RID_BYREF, D_OBJC }, |
749 { "in", RID_IN, D_OBJC }, | 709 { "in", RID_IN, D_OBJC }, |
750 { "inout", RID_INOUT, D_OBJC }, | 710 { "inout", RID_INOUT, D_OBJC }, |
751 { "oneway", RID_ONEWAY, D_OBJC }, | 711 { "oneway", RID_ONEWAY, D_OBJC }, |
752 { "out", RID_OUT, D_OBJC }, | 712 { "out", RID_OUT, D_OBJC }, |
713 | |
714 #ifdef TARGET_ADDR_SPACE_KEYWORDS | |
715 /* Any address space keywords recognized by the target. */ | |
716 TARGET_ADDR_SPACE_KEYWORDS, | |
717 #endif | |
753 }; | 718 }; |
754 | 719 |
755 const unsigned int num_c_common_reswords = | 720 const unsigned int num_c_common_reswords = |
756 sizeof c_common_reswords / sizeof (struct c_common_resword); | 721 sizeof c_common_reswords / sizeof (struct c_common_resword); |
757 | 722 |
774 handle_noreturn_attribute }, | 739 handle_noreturn_attribute }, |
775 { "volatile", 0, 0, true, false, false, | 740 { "volatile", 0, 0, true, false, false, |
776 handle_noreturn_attribute }, | 741 handle_noreturn_attribute }, |
777 { "noinline", 0, 0, true, false, false, | 742 { "noinline", 0, 0, true, false, false, |
778 handle_noinline_attribute }, | 743 handle_noinline_attribute }, |
744 { "noclone", 0, 0, true, false, false, | |
745 handle_noclone_attribute }, | |
779 { "always_inline", 0, 0, true, false, false, | 746 { "always_inline", 0, 0, true, false, false, |
780 handle_always_inline_attribute }, | 747 handle_always_inline_attribute }, |
781 { "gnu_inline", 0, 0, true, false, false, | 748 { "gnu_inline", 0, 0, true, false, false, |
782 handle_gnu_inline_attribute }, | 749 handle_gnu_inline_attribute }, |
783 { "artificial", 0, 0, true, false, false, | 750 { "artificial", 0, 0, true, false, false, |
823 handle_pure_attribute }, | 790 handle_pure_attribute }, |
824 /* For internal use (marking of builtins) only. The name contains space | 791 /* For internal use (marking of builtins) only. The name contains space |
825 to prevent its usage in source code. */ | 792 to prevent its usage in source code. */ |
826 { "no vops", 0, 0, true, false, false, | 793 { "no vops", 0, 0, true, false, false, |
827 handle_novops_attribute }, | 794 handle_novops_attribute }, |
828 { "deprecated", 0, 0, false, false, false, | 795 { "deprecated", 0, 1, false, false, false, |
829 handle_deprecated_attribute }, | 796 handle_deprecated_attribute }, |
830 { "vector_size", 1, 1, false, true, false, | 797 { "vector_size", 1, 1, false, true, false, |
831 handle_vector_size_attribute }, | 798 handle_vector_size_attribute }, |
832 { "visibility", 1, 1, false, false, false, | 799 { "visibility", 1, 1, false, false, false, |
833 handle_visibility_attribute }, | 800 handle_visibility_attribute }, |
876 { "format_arg", 1, 1, false, true, true, | 843 { "format_arg", 1, 1, false, true, true, |
877 handle_format_arg_attribute }, | 844 handle_format_arg_attribute }, |
878 { NULL, 0, 0, false, false, false, NULL } | 845 { NULL, 0, 0, false, false, false, NULL } |
879 }; | 846 }; |
880 | 847 |
848 /* Return identifier for address space AS. */ | |
849 const char * | |
850 c_addr_space_name (addr_space_t as) | |
851 { | |
852 unsigned int i; | |
853 | |
854 for (i = 0; i < num_c_common_reswords; i++) | |
855 if (c_common_reswords[i].rid == RID_FIRST_ADDR_SPACE + as) | |
856 return c_common_reswords[i].word; | |
857 | |
858 gcc_unreachable (); | |
859 } | |
860 | |
881 /* Push current bindings for the function name VAR_DECLS. */ | 861 /* Push current bindings for the function name VAR_DECLS. */ |
882 | 862 |
883 void | 863 void |
884 start_fname_decls (void) | 864 start_fname_decls (void) |
885 { | 865 { |
1014 tree stmts; | 994 tree stmts; |
1015 location_t saved_location = input_location; | 995 location_t saved_location = input_location; |
1016 input_location = UNKNOWN_LOCATION; | 996 input_location = UNKNOWN_LOCATION; |
1017 | 997 |
1018 stmts = push_stmt_list (); | 998 stmts = push_stmt_list (); |
1019 decl = (*make_fname_decl) (id, fname_vars[ix].pretty); | 999 decl = (*make_fname_decl) (loc, id, fname_vars[ix].pretty); |
1020 stmts = pop_stmt_list (stmts); | 1000 stmts = pop_stmt_list (stmts); |
1021 if (!IS_EMPTY_STMT (stmts)) | 1001 if (!IS_EMPTY_STMT (stmts)) |
1022 saved_function_name_decls | 1002 saved_function_name_decls |
1023 = tree_cons (decl, stmts, saved_function_name_decls); | 1003 = tree_cons (decl, stmts, saved_function_name_decls); |
1024 *fname_vars[ix].decl = decl; | 1004 *fname_vars[ix].decl = decl; |
1105 TREE_READONLY (value) = 1; | 1085 TREE_READONLY (value) = 1; |
1106 TREE_STATIC (value) = 1; | 1086 TREE_STATIC (value) = 1; |
1107 return value; | 1087 return value; |
1108 } | 1088 } |
1109 | 1089 |
1090 /* Fully fold EXPR, an expression that was not folded (beyond integer | |
1091 constant expressions and null pointer constants) when being built | |
1092 up. If IN_INIT, this is in a static initializer and certain | |
1093 changes are made to the folding done. Clear *MAYBE_CONST if | |
1094 MAYBE_CONST is not NULL and EXPR is definitely not a constant | |
1095 expression because it contains an evaluated operator (in C99) or an | |
1096 operator outside of sizeof returning an integer constant (in C90) | |
1097 not permitted in constant expressions, or because it contains an | |
1098 evaluated arithmetic overflow. (*MAYBE_CONST should typically be | |
1099 set to true by callers before calling this function.) Return the | |
1100 folded expression. Function arguments have already been folded | |
1101 before calling this function, as have the contents of SAVE_EXPR, | |
1102 TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and | |
1103 C_MAYBE_CONST_EXPR. */ | |
1104 | |
1105 tree | |
1106 c_fully_fold (tree expr, bool in_init, bool *maybe_const) | |
1107 { | |
1108 tree ret; | |
1109 tree eptype = NULL_TREE; | |
1110 bool dummy = true; | |
1111 bool maybe_const_itself = true; | |
1112 location_t loc = EXPR_LOCATION (expr); | |
1113 | |
1114 /* This function is not relevant to C++ because C++ folds while | |
1115 parsing, and may need changes to be correct for C++ when C++ | |
1116 stops folding while parsing. */ | |
1117 if (c_dialect_cxx ()) | |
1118 gcc_unreachable (); | |
1119 | |
1120 if (!maybe_const) | |
1121 maybe_const = &dummy; | |
1122 if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR) | |
1123 { | |
1124 eptype = TREE_TYPE (expr); | |
1125 expr = TREE_OPERAND (expr, 0); | |
1126 } | |
1127 ret = c_fully_fold_internal (expr, in_init, maybe_const, | |
1128 &maybe_const_itself); | |
1129 if (eptype) | |
1130 ret = fold_convert_loc (loc, eptype, ret); | |
1131 *maybe_const &= maybe_const_itself; | |
1132 return ret; | |
1133 } | |
1134 | |
1135 /* Internal helper for c_fully_fold. EXPR and IN_INIT are as for | |
1136 c_fully_fold. *MAYBE_CONST_OPERANDS is cleared because of operands | |
1137 not permitted, while *MAYBE_CONST_ITSELF is cleared because of | |
1138 arithmetic overflow (for C90, *MAYBE_CONST_OPERANDS is carried from | |
1139 both evaluated and unevaluated subexpressions while | |
1140 *MAYBE_CONST_ITSELF is carried from only evaluated | |
1141 subexpressions). */ | |
1142 | |
1143 static tree | |
1144 c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands, | |
1145 bool *maybe_const_itself) | |
1146 { | |
1147 tree ret = expr; | |
1148 enum tree_code code = TREE_CODE (expr); | |
1149 enum tree_code_class kind = TREE_CODE_CLASS (code); | |
1150 location_t loc = EXPR_LOCATION (expr); | |
1151 tree op0, op1, op2, op3; | |
1152 tree orig_op0, orig_op1, orig_op2; | |
1153 bool op0_const = true, op1_const = true, op2_const = true; | |
1154 bool op0_const_self = true, op1_const_self = true, op2_const_self = true; | |
1155 bool nowarning = TREE_NO_WARNING (expr); | |
1156 int unused_p; | |
1157 | |
1158 /* This function is not relevant to C++ because C++ folds while | |
1159 parsing, and may need changes to be correct for C++ when C++ | |
1160 stops folding while parsing. */ | |
1161 if (c_dialect_cxx ()) | |
1162 gcc_unreachable (); | |
1163 | |
1164 /* Constants, declarations, statements, errors, SAVE_EXPRs and | |
1165 anything else not counted as an expression cannot usefully be | |
1166 folded further at this point. */ | |
1167 if (!IS_EXPR_CODE_CLASS (kind) | |
1168 || kind == tcc_statement | |
1169 || code == SAVE_EXPR) | |
1170 return expr; | |
1171 | |
1172 /* Operands of variable-length expressions (function calls) have | |
1173 already been folded, as have __builtin_* function calls, and such | |
1174 expressions cannot occur in constant expressions. */ | |
1175 if (kind == tcc_vl_exp) | |
1176 { | |
1177 *maybe_const_operands = false; | |
1178 ret = fold (expr); | |
1179 goto out; | |
1180 } | |
1181 | |
1182 if (code == C_MAYBE_CONST_EXPR) | |
1183 { | |
1184 tree pre = C_MAYBE_CONST_EXPR_PRE (expr); | |
1185 tree inner = C_MAYBE_CONST_EXPR_EXPR (expr); | |
1186 if (C_MAYBE_CONST_EXPR_NON_CONST (expr)) | |
1187 *maybe_const_operands = false; | |
1188 if (C_MAYBE_CONST_EXPR_INT_OPERANDS (expr)) | |
1189 *maybe_const_itself = false; | |
1190 if (pre && !in_init) | |
1191 ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr), pre, inner); | |
1192 else | |
1193 ret = inner; | |
1194 goto out; | |
1195 } | |
1196 | |
1197 /* Assignment, increment, decrement, function call and comma | |
1198 operators, and statement expressions, cannot occur in constant | |
1199 expressions if evaluated / outside of sizeof. (Function calls | |
1200 were handled above, though VA_ARG_EXPR is treated like a function | |
1201 call here, and statement expressions are handled through | |
1202 C_MAYBE_CONST_EXPR to avoid folding inside them.) */ | |
1203 switch (code) | |
1204 { | |
1205 case MODIFY_EXPR: | |
1206 case PREDECREMENT_EXPR: | |
1207 case PREINCREMENT_EXPR: | |
1208 case POSTDECREMENT_EXPR: | |
1209 case POSTINCREMENT_EXPR: | |
1210 case COMPOUND_EXPR: | |
1211 *maybe_const_operands = false; | |
1212 break; | |
1213 | |
1214 case VA_ARG_EXPR: | |
1215 case TARGET_EXPR: | |
1216 case BIND_EXPR: | |
1217 case OBJ_TYPE_REF: | |
1218 *maybe_const_operands = false; | |
1219 ret = fold (expr); | |
1220 goto out; | |
1221 | |
1222 default: | |
1223 break; | |
1224 } | |
1225 | |
1226 /* Fold individual tree codes as appropriate. */ | |
1227 switch (code) | |
1228 { | |
1229 case COMPOUND_LITERAL_EXPR: | |
1230 /* Any non-constancy will have been marked in a containing | |
1231 C_MAYBE_CONST_EXPR; there is no more folding to do here. */ | |
1232 goto out; | |
1233 | |
1234 case COMPONENT_REF: | |
1235 orig_op0 = op0 = TREE_OPERAND (expr, 0); | |
1236 op1 = TREE_OPERAND (expr, 1); | |
1237 op2 = TREE_OPERAND (expr, 2); | |
1238 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands, | |
1239 maybe_const_itself); | |
1240 STRIP_TYPE_NOPS (op0); | |
1241 if (op0 != orig_op0) | |
1242 ret = build3 (COMPONENT_REF, TREE_TYPE (expr), op0, op1, op2); | |
1243 if (ret != expr) | |
1244 { | |
1245 TREE_READONLY (ret) = TREE_READONLY (expr); | |
1246 TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr); | |
1247 } | |
1248 goto out; | |
1249 | |
1250 case ARRAY_REF: | |
1251 orig_op0 = op0 = TREE_OPERAND (expr, 0); | |
1252 orig_op1 = op1 = TREE_OPERAND (expr, 1); | |
1253 op2 = TREE_OPERAND (expr, 2); | |
1254 op3 = TREE_OPERAND (expr, 3); | |
1255 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands, | |
1256 maybe_const_itself); | |
1257 STRIP_TYPE_NOPS (op0); | |
1258 op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands, | |
1259 maybe_const_itself); | |
1260 STRIP_TYPE_NOPS (op1); | |
1261 op1 = decl_constant_value_for_optimization (op1); | |
1262 if (op0 != orig_op0 || op1 != orig_op1) | |
1263 ret = build4 (ARRAY_REF, TREE_TYPE (expr), op0, op1, op2, op3); | |
1264 if (ret != expr) | |
1265 { | |
1266 TREE_READONLY (ret) = TREE_READONLY (expr); | |
1267 TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr); | |
1268 TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr); | |
1269 } | |
1270 ret = fold (ret); | |
1271 goto out; | |
1272 | |
1273 case COMPOUND_EXPR: | |
1274 case MODIFY_EXPR: | |
1275 case PREDECREMENT_EXPR: | |
1276 case PREINCREMENT_EXPR: | |
1277 case POSTDECREMENT_EXPR: | |
1278 case POSTINCREMENT_EXPR: | |
1279 case PLUS_EXPR: | |
1280 case MINUS_EXPR: | |
1281 case MULT_EXPR: | |
1282 case POINTER_PLUS_EXPR: | |
1283 case TRUNC_DIV_EXPR: | |
1284 case CEIL_DIV_EXPR: | |
1285 case FLOOR_DIV_EXPR: | |
1286 case TRUNC_MOD_EXPR: | |
1287 case RDIV_EXPR: | |
1288 case EXACT_DIV_EXPR: | |
1289 case LSHIFT_EXPR: | |
1290 case RSHIFT_EXPR: | |
1291 case BIT_IOR_EXPR: | |
1292 case BIT_XOR_EXPR: | |
1293 case BIT_AND_EXPR: | |
1294 case LT_EXPR: | |
1295 case LE_EXPR: | |
1296 case GT_EXPR: | |
1297 case GE_EXPR: | |
1298 case EQ_EXPR: | |
1299 case NE_EXPR: | |
1300 case COMPLEX_EXPR: | |
1301 case TRUTH_AND_EXPR: | |
1302 case TRUTH_OR_EXPR: | |
1303 case TRUTH_XOR_EXPR: | |
1304 case UNORDERED_EXPR: | |
1305 case ORDERED_EXPR: | |
1306 case UNLT_EXPR: | |
1307 case UNLE_EXPR: | |
1308 case UNGT_EXPR: | |
1309 case UNGE_EXPR: | |
1310 case UNEQ_EXPR: | |
1311 /* Binary operations evaluating both arguments (increment and | |
1312 decrement are binary internally in GCC). */ | |
1313 orig_op0 = op0 = TREE_OPERAND (expr, 0); | |
1314 orig_op1 = op1 = TREE_OPERAND (expr, 1); | |
1315 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands, | |
1316 maybe_const_itself); | |
1317 STRIP_TYPE_NOPS (op0); | |
1318 if (code != MODIFY_EXPR | |
1319 && code != PREDECREMENT_EXPR | |
1320 && code != PREINCREMENT_EXPR | |
1321 && code != POSTDECREMENT_EXPR | |
1322 && code != POSTINCREMENT_EXPR) | |
1323 op0 = decl_constant_value_for_optimization (op0); | |
1324 /* The RHS of a MODIFY_EXPR was fully folded when building that | |
1325 expression for the sake of conversion warnings. */ | |
1326 if (code != MODIFY_EXPR) | |
1327 op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands, | |
1328 maybe_const_itself); | |
1329 STRIP_TYPE_NOPS (op1); | |
1330 op1 = decl_constant_value_for_optimization (op1); | |
1331 if (op0 != orig_op0 || op1 != orig_op1 || in_init) | |
1332 ret = in_init | |
1333 ? fold_build2_initializer_loc (loc, code, TREE_TYPE (expr), op0, op1) | |
1334 : fold_build2_loc (loc, code, TREE_TYPE (expr), op0, op1); | |
1335 else | |
1336 ret = fold (expr); | |
1337 if (TREE_OVERFLOW_P (ret) | |
1338 && !TREE_OVERFLOW_P (op0) | |
1339 && !TREE_OVERFLOW_P (op1)) | |
1340 overflow_warning (EXPR_LOCATION (expr), ret); | |
1341 goto out; | |
1342 | |
1343 case INDIRECT_REF: | |
1344 case FIX_TRUNC_EXPR: | |
1345 case FLOAT_EXPR: | |
1346 CASE_CONVERT: | |
1347 case NON_LVALUE_EXPR: | |
1348 case NEGATE_EXPR: | |
1349 case BIT_NOT_EXPR: | |
1350 case TRUTH_NOT_EXPR: | |
1351 case ADDR_EXPR: | |
1352 case CONJ_EXPR: | |
1353 case REALPART_EXPR: | |
1354 case IMAGPART_EXPR: | |
1355 /* Unary operations. */ | |
1356 orig_op0 = op0 = TREE_OPERAND (expr, 0); | |
1357 op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands, | |
1358 maybe_const_itself); | |
1359 STRIP_TYPE_NOPS (op0); | |
1360 if (code != ADDR_EXPR && code != REALPART_EXPR && code != IMAGPART_EXPR) | |
1361 op0 = decl_constant_value_for_optimization (op0); | |
1362 if (op0 != orig_op0 || in_init) | |
1363 ret = in_init | |
1364 ? fold_build1_initializer_loc (loc, code, TREE_TYPE (expr), op0) | |
1365 : fold_build1_loc (loc, code, TREE_TYPE (expr), op0); | |
1366 else | |
1367 ret = fold (expr); | |
1368 if (code == INDIRECT_REF | |
1369 && ret != expr | |
1370 && TREE_CODE (ret) == INDIRECT_REF) | |
1371 { | |
1372 TREE_READONLY (ret) = TREE_READONLY (expr); | |
1373 TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (expr); | |
1374 TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (expr); | |
1375 } | |
1376 switch (code) | |
1377 { | |
1378 case FIX_TRUNC_EXPR: | |
1379 case FLOAT_EXPR: | |
1380 CASE_CONVERT: | |
1381 /* Don't warn about explicit conversions. We will already | |
1382 have warned about suspect implicit conversions. */ | |
1383 break; | |
1384 | |
1385 default: | |
1386 if (TREE_OVERFLOW_P (ret) && !TREE_OVERFLOW_P (op0)) | |
1387 overflow_warning (EXPR_LOCATION (expr), ret); | |
1388 break; | |
1389 } | |
1390 goto out; | |
1391 | |
1392 case TRUTH_ANDIF_EXPR: | |
1393 case TRUTH_ORIF_EXPR: | |
1394 /* Binary operations not necessarily evaluating both | |
1395 arguments. */ | |
1396 orig_op0 = op0 = TREE_OPERAND (expr, 0); | |
1397 orig_op1 = op1 = TREE_OPERAND (expr, 1); | |
1398 op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self); | |
1399 STRIP_TYPE_NOPS (op0); | |
1400 | |
1401 unused_p = (op0 == (code == TRUTH_ANDIF_EXPR | |
1402 ? truthvalue_false_node | |
1403 : truthvalue_true_node)); | |
1404 c_inhibit_evaluation_warnings += unused_p; | |
1405 op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self); | |
1406 STRIP_TYPE_NOPS (op1); | |
1407 c_inhibit_evaluation_warnings -= unused_p; | |
1408 | |
1409 if (op0 != orig_op0 || op1 != orig_op1 || in_init) | |
1410 ret = in_init | |
1411 ? fold_build2_initializer_loc (loc, code, TREE_TYPE (expr), op0, op1) | |
1412 : fold_build2_loc (loc, code, TREE_TYPE (expr), op0, op1); | |
1413 else | |
1414 ret = fold (expr); | |
1415 *maybe_const_operands &= op0_const; | |
1416 *maybe_const_itself &= op0_const_self; | |
1417 if (!(flag_isoc99 | |
1418 && op0_const | |
1419 && op0_const_self | |
1420 && (code == TRUTH_ANDIF_EXPR | |
1421 ? op0 == truthvalue_false_node | |
1422 : op0 == truthvalue_true_node))) | |
1423 *maybe_const_operands &= op1_const; | |
1424 if (!(op0_const | |
1425 && op0_const_self | |
1426 && (code == TRUTH_ANDIF_EXPR | |
1427 ? op0 == truthvalue_false_node | |
1428 : op0 == truthvalue_true_node))) | |
1429 *maybe_const_itself &= op1_const_self; | |
1430 goto out; | |
1431 | |
1432 case COND_EXPR: | |
1433 orig_op0 = op0 = TREE_OPERAND (expr, 0); | |
1434 orig_op1 = op1 = TREE_OPERAND (expr, 1); | |
1435 orig_op2 = op2 = TREE_OPERAND (expr, 2); | |
1436 op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self); | |
1437 | |
1438 STRIP_TYPE_NOPS (op0); | |
1439 c_inhibit_evaluation_warnings += (op0 == truthvalue_false_node); | |
1440 op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self); | |
1441 STRIP_TYPE_NOPS (op1); | |
1442 c_inhibit_evaluation_warnings -= (op0 == truthvalue_false_node); | |
1443 | |
1444 c_inhibit_evaluation_warnings += (op0 == truthvalue_true_node); | |
1445 op2 = c_fully_fold_internal (op2, in_init, &op2_const, &op2_const_self); | |
1446 STRIP_TYPE_NOPS (op2); | |
1447 c_inhibit_evaluation_warnings -= (op0 == truthvalue_true_node); | |
1448 | |
1449 if (op0 != orig_op0 || op1 != orig_op1 || op2 != orig_op2) | |
1450 ret = fold_build3_loc (loc, code, TREE_TYPE (expr), op0, op1, op2); | |
1451 else | |
1452 ret = fold (expr); | |
1453 *maybe_const_operands &= op0_const; | |
1454 *maybe_const_itself &= op0_const_self; | |
1455 if (!(flag_isoc99 | |
1456 && op0_const | |
1457 && op0_const_self | |
1458 && op0 == truthvalue_false_node)) | |
1459 *maybe_const_operands &= op1_const; | |
1460 if (!(op0_const | |
1461 && op0_const_self | |
1462 && op0 == truthvalue_false_node)) | |
1463 *maybe_const_itself &= op1_const_self; | |
1464 if (!(flag_isoc99 | |
1465 && op0_const | |
1466 && op0_const_self | |
1467 && op0 == truthvalue_true_node)) | |
1468 *maybe_const_operands &= op2_const; | |
1469 if (!(op0_const | |
1470 && op0_const_self | |
1471 && op0 == truthvalue_true_node)) | |
1472 *maybe_const_itself &= op2_const_self; | |
1473 goto out; | |
1474 | |
1475 case EXCESS_PRECISION_EXPR: | |
1476 /* Each case where an operand with excess precision may be | |
1477 encountered must remove the EXCESS_PRECISION_EXPR around | |
1478 inner operands and possibly put one around the whole | |
1479 expression or possibly convert to the semantic type (which | |
1480 c_fully_fold does); we cannot tell at this stage which is | |
1481 appropriate in any particular case. */ | |
1482 gcc_unreachable (); | |
1483 | |
1484 default: | |
1485 /* Various codes may appear through folding built-in functions | |
1486 and their arguments. */ | |
1487 goto out; | |
1488 } | |
1489 | |
1490 out: | |
1491 /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks | |
1492 have been done by this point, so remove them again. */ | |
1493 nowarning |= TREE_NO_WARNING (ret); | |
1494 STRIP_TYPE_NOPS (ret); | |
1495 if (nowarning && !TREE_NO_WARNING (ret)) | |
1496 { | |
1497 if (!CAN_HAVE_LOCATION_P (ret)) | |
1498 ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret); | |
1499 TREE_NO_WARNING (ret) = 1; | |
1500 } | |
1501 if (ret != expr) | |
1502 protected_set_expr_location (ret, loc); | |
1503 return ret; | |
1504 } | |
1505 | |
1506 /* If not optimizing, EXP is not a VAR_DECL, or EXP has array type, | |
1507 return EXP. Otherwise, return either EXP or its known constant | |
1508 value (if it has one), but return EXP if EXP has mode BLKmode. ??? | |
1509 Is the BLKmode test appropriate? */ | |
1510 | |
1511 tree | |
1512 decl_constant_value_for_optimization (tree exp) | |
1513 { | |
1514 tree ret; | |
1515 | |
1516 /* This function is only used by C, for c_fully_fold and other | |
1517 optimization, and may not be correct for C++. */ | |
1518 if (c_dialect_cxx ()) | |
1519 gcc_unreachable (); | |
1520 | |
1521 if (!optimize | |
1522 || TREE_CODE (exp) != VAR_DECL | |
1523 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE | |
1524 || DECL_MODE (exp) == BLKmode) | |
1525 return exp; | |
1526 | |
1527 ret = decl_constant_value (exp); | |
1528 /* Avoid unwanted tree sharing between the initializer and current | |
1529 function's body where the tree can be modified e.g. by the | |
1530 gimplifier. */ | |
1531 if (ret != exp && TREE_STATIC (exp)) | |
1532 ret = unshare_expr (ret); | |
1533 return ret; | |
1534 } | |
1535 | |
1110 /* Print a warning if a constant expression had overflow in folding. | 1536 /* Print a warning if a constant expression had overflow in folding. |
1111 Invoke this function on every expression that the language | 1537 Invoke this function on every expression that the language |
1112 requires to be a constant expression. | 1538 requires to be a constant expression. |
1113 Note the ANSI C standard says it is erroneous for a | 1539 Note the ANSI C standard says it is erroneous for a |
1114 constant expression to overflow. */ | 1540 constant expression to overflow. */ |
1115 | 1541 |
1116 void | 1542 void |
1117 constant_expression_warning (tree value) | 1543 constant_expression_warning (tree value) |
1118 { | 1544 { |
1119 if (warn_overflow && pedantic | 1545 if (warn_overflow && pedantic |
1120 && (TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST | 1546 && (TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST |
1121 || TREE_CODE (value) == FIXED_CST | 1547 || TREE_CODE (value) == FIXED_CST |
1122 || TREE_CODE (value) == VECTOR_CST | 1548 || TREE_CODE (value) == VECTOR_CST |
1123 || TREE_CODE (value) == COMPLEX_CST) | 1549 || TREE_CODE (value) == COMPLEX_CST) |
1124 && TREE_OVERFLOW (value)) | 1550 && TREE_OVERFLOW (value)) |
1147 however, do not invoke this function on operands of explicit casts | 1573 however, do not invoke this function on operands of explicit casts |
1148 or when the expression is the result of an operator and any operand | 1574 or when the expression is the result of an operator and any operand |
1149 already overflowed. */ | 1575 already overflowed. */ |
1150 | 1576 |
1151 void | 1577 void |
1152 overflow_warning (tree value) | 1578 overflow_warning (location_t loc, tree value) |
1153 { | 1579 { |
1154 if (skip_evaluation) return; | 1580 if (c_inhibit_evaluation_warnings != 0) |
1581 return; | |
1155 | 1582 |
1156 switch (TREE_CODE (value)) | 1583 switch (TREE_CODE (value)) |
1157 { | 1584 { |
1158 case INTEGER_CST: | 1585 case INTEGER_CST: |
1159 warning (OPT_Woverflow, "integer overflow in expression"); | 1586 warning_at (loc, OPT_Woverflow, "integer overflow in expression"); |
1160 break; | 1587 break; |
1161 | 1588 |
1162 case REAL_CST: | 1589 case REAL_CST: |
1163 warning (OPT_Woverflow, "floating point overflow in expression"); | 1590 warning_at (loc, OPT_Woverflow, |
1591 "floating point overflow in expression"); | |
1164 break; | 1592 break; |
1165 | 1593 |
1166 case FIXED_CST: | 1594 case FIXED_CST: |
1167 warning (OPT_Woverflow, "fixed-point overflow in expression"); | 1595 warning_at (loc, OPT_Woverflow, "fixed-point overflow in expression"); |
1168 break; | 1596 break; |
1169 | 1597 |
1170 case VECTOR_CST: | 1598 case VECTOR_CST: |
1171 warning (OPT_Woverflow, "vector overflow in expression"); | 1599 warning_at (loc, OPT_Woverflow, "vector overflow in expression"); |
1172 break; | 1600 break; |
1173 | 1601 |
1174 case COMPLEX_CST: | 1602 case COMPLEX_CST: |
1175 if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST) | 1603 if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST) |
1176 warning (OPT_Woverflow, "complex integer overflow in expression"); | 1604 warning_at (loc, OPT_Woverflow, |
1605 "complex integer overflow in expression"); | |
1177 else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST) | 1606 else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST) |
1178 warning (OPT_Woverflow, "complex floating point overflow in expression"); | 1607 warning_at (loc, OPT_Woverflow, |
1608 "complex floating point overflow in expression"); | |
1179 break; | 1609 break; |
1180 | 1610 |
1181 default: | 1611 default: |
1182 break; | 1612 break; |
1183 } | 1613 } |
1184 } | 1614 } |
1185 | 1615 |
1186 | 1616 /* Warn about uses of logical || / && operator in a context where it |
1187 /* Warn about use of a logical || / && operator being used in a | 1617 is likely that the bitwise equivalent was intended by the |
1188 context where it is likely that the bitwise equivalent was intended | 1618 programmer. We have seen an expression in which CODE is a binary |
1189 by the programmer. CODE is the TREE_CODE of the operator, ARG1 | 1619 operator used to combine expressions OP_LEFT and OP_RIGHT, which before folding |
1190 and ARG2 the arguments. */ | 1620 had CODE_LEFT and CODE_RIGHT, into an expression of type TYPE. */ |
1191 | |
1192 void | 1621 void |
1193 warn_logical_operator (enum tree_code code, tree arg1, tree | 1622 warn_logical_operator (location_t location, enum tree_code code, tree type, |
1194 arg2) | 1623 enum tree_code code_left, tree op_left, |
1195 { | 1624 enum tree_code ARG_UNUSED (code_right), tree op_right) |
1196 switch (code) | 1625 { |
1197 { | 1626 int or_op = (code == TRUTH_ORIF_EXPR || code == TRUTH_OR_EXPR); |
1198 case TRUTH_ANDIF_EXPR: | 1627 int in0_p, in1_p, in_p; |
1199 case TRUTH_ORIF_EXPR: | 1628 tree low0, low1, low, high0, high1, high, lhs, rhs, tem; |
1200 case TRUTH_OR_EXPR: | 1629 bool strict_overflow_p = false; |
1201 case TRUTH_AND_EXPR: | 1630 |
1202 if (!TREE_NO_WARNING (arg1) | 1631 if (code != TRUTH_ANDIF_EXPR |
1203 && INTEGRAL_TYPE_P (TREE_TYPE (arg1)) | 1632 && code != TRUTH_AND_EXPR |
1204 && !CONSTANT_CLASS_P (arg1) | 1633 && code != TRUTH_ORIF_EXPR |
1205 && TREE_CODE (arg2) == INTEGER_CST | 1634 && code != TRUTH_OR_EXPR) |
1206 && !integer_zerop (arg2)) | 1635 return; |
1207 { | 1636 |
1208 warning (OPT_Wlogical_op, | 1637 /* Warn if &&/|| are being used in a context where it is |
1209 "logical %<%s%> with non-zero constant " | 1638 likely that the bitwise equivalent was intended by the |
1210 "will always evaluate as true", | 1639 programmer. That is, an expression such as op && MASK |
1211 ((code == TRUTH_ANDIF_EXPR) | 1640 where op should not be any boolean expression, nor a |
1212 || (code == TRUTH_AND_EXPR)) ? "&&" : "||"); | 1641 constant, and mask seems to be a non-boolean integer constant. */ |
1213 TREE_NO_WARNING (arg1) = true; | 1642 if (!truth_value_p (code_left) |
1214 } | 1643 && INTEGRAL_TYPE_P (TREE_TYPE (op_left)) |
1215 break; | 1644 && !CONSTANT_CLASS_P (op_left) |
1216 default: | 1645 && !TREE_NO_WARNING (op_left) |
1217 break; | 1646 && TREE_CODE (op_right) == INTEGER_CST |
1647 && !integer_zerop (op_right) | |
1648 && !integer_onep (op_right)) | |
1649 { | |
1650 if (or_op) | |
1651 warning_at (location, OPT_Wlogical_op, "logical %<or%>" | |
1652 " applied to non-boolean constant"); | |
1653 else | |
1654 warning_at (location, OPT_Wlogical_op, "logical %<and%>" | |
1655 " applied to non-boolean constant"); | |
1656 TREE_NO_WARNING (op_left) = true; | |
1657 return; | |
1658 } | |
1659 | |
1660 /* We do not warn for constants because they are typical of macro | |
1661 expansions that test for features. */ | |
1662 if (CONSTANT_CLASS_P (op_left) || CONSTANT_CLASS_P (op_right)) | |
1663 return; | |
1664 | |
1665 /* This warning only makes sense with logical operands. */ | |
1666 if (!(truth_value_p (TREE_CODE (op_left)) | |
1667 || INTEGRAL_TYPE_P (TREE_TYPE (op_left))) | |
1668 || !(truth_value_p (TREE_CODE (op_right)) | |
1669 || INTEGRAL_TYPE_P (TREE_TYPE (op_right)))) | |
1670 return; | |
1671 | |
1672 lhs = make_range (op_left, &in0_p, &low0, &high0, &strict_overflow_p); | |
1673 rhs = make_range (op_right, &in1_p, &low1, &high1, &strict_overflow_p); | |
1674 | |
1675 if (lhs && TREE_CODE (lhs) == C_MAYBE_CONST_EXPR) | |
1676 lhs = C_MAYBE_CONST_EXPR_EXPR (lhs); | |
1677 | |
1678 if (rhs && TREE_CODE (rhs) == C_MAYBE_CONST_EXPR) | |
1679 rhs = C_MAYBE_CONST_EXPR_EXPR (rhs); | |
1680 | |
1681 /* If this is an OR operation, invert both sides; we will invert | |
1682 again at the end. */ | |
1683 if (or_op) | |
1684 in0_p = !in0_p, in1_p = !in1_p; | |
1685 | |
1686 /* If both expressions are the same, if we can merge the ranges, and we | |
1687 can build the range test, return it or it inverted. */ | |
1688 if (lhs && rhs && operand_equal_p (lhs, rhs, 0) | |
1689 && merge_ranges (&in_p, &low, &high, in0_p, low0, high0, | |
1690 in1_p, low1, high1) | |
1691 && 0 != (tem = build_range_check (UNKNOWN_LOCATION, | |
1692 type, lhs, in_p, low, high))) | |
1693 { | |
1694 if (TREE_CODE (tem) != INTEGER_CST) | |
1695 return; | |
1696 | |
1697 if (or_op) | |
1698 warning_at (location, OPT_Wlogical_op, | |
1699 "logical %<or%> " | |
1700 "of collectively exhaustive tests is always true"); | |
1701 else | |
1702 warning_at (location, OPT_Wlogical_op, | |
1703 "logical %<and%> " | |
1704 "of mutually exclusive tests is always false"); | |
1218 } | 1705 } |
1219 } | 1706 } |
1220 | 1707 |
1221 | 1708 |
1222 /* Print a warning about casts that might indicate violation | 1709 /* Print a warning about casts that might indicate violation |
1225 TREE_TYPE of EXPR, and TYPE the type we're casting to. */ | 1712 TREE_TYPE of EXPR, and TYPE the type we're casting to. */ |
1226 | 1713 |
1227 bool | 1714 bool |
1228 strict_aliasing_warning (tree otype, tree type, tree expr) | 1715 strict_aliasing_warning (tree otype, tree type, tree expr) |
1229 { | 1716 { |
1717 /* Strip pointer conversion chains and get to the correct original type. */ | |
1718 STRIP_NOPS (expr); | |
1719 otype = TREE_TYPE (expr); | |
1720 | |
1230 if (!(flag_strict_aliasing | 1721 if (!(flag_strict_aliasing |
1231 && POINTER_TYPE_P (type) | 1722 && POINTER_TYPE_P (type) |
1232 && POINTER_TYPE_P (otype) | 1723 && POINTER_TYPE_P (otype) |
1233 && !VOID_TYPE_P (TREE_TYPE (type))) | 1724 && !VOID_TYPE_P (TREE_TYPE (type))) |
1234 /* If the type we are casting to is a ref-all pointer | 1725 /* If the type we are casting to is a ref-all pointer |
1248 "might break strict-aliasing rules"); | 1739 "might break strict-aliasing rules"); |
1249 return true; | 1740 return true; |
1250 } | 1741 } |
1251 else | 1742 else |
1252 { | 1743 { |
1253 /* warn_strict_aliasing >= 3. This includes the default (3). | 1744 /* warn_strict_aliasing >= 3. This includes the default (3). |
1254 Only warn if the cast is dereferenced immediately. */ | 1745 Only warn if the cast is dereferenced immediately. */ |
1255 alias_set_type set1 = | 1746 alias_set_type set1 = |
1256 get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0))); | 1747 get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0))); |
1257 alias_set_type set2 = get_alias_set (TREE_TYPE (type)); | 1748 alias_set_type set2 = get_alias_set (TREE_TYPE (type)); |
1258 | 1749 |
1313 ++argct; | 1804 ++argct; |
1314 switch (argct) | 1805 switch (argct) |
1315 { | 1806 { |
1316 case 1: | 1807 case 1: |
1317 if (TYPE_MAIN_VARIANT (type) != integer_type_node) | 1808 if (TYPE_MAIN_VARIANT (type) != integer_type_node) |
1318 pedwarn (input_location, OPT_Wmain, "first argument of %q+D should be %<int%>", | 1809 pedwarn (input_location, OPT_Wmain, "first argument of %q+D should be %<int%>", |
1319 decl); | 1810 decl); |
1320 break; | 1811 break; |
1321 | 1812 |
1322 case 2: | 1813 case 2: |
1323 if (TREE_CODE (type) != POINTER_TYPE | 1814 if (TREE_CODE (type) != POINTER_TYPE |
1351 vector types. */ | 1842 vector types. */ |
1352 bool | 1843 bool |
1353 vector_targets_convertible_p (const_tree t1, const_tree t2) | 1844 vector_targets_convertible_p (const_tree t1, const_tree t2) |
1354 { | 1845 { |
1355 if (TREE_CODE (t1) == VECTOR_TYPE && TREE_CODE (t2) == VECTOR_TYPE | 1846 if (TREE_CODE (t1) == VECTOR_TYPE && TREE_CODE (t2) == VECTOR_TYPE |
1356 && (targetm.vector_opaque_p (t1) || targetm.vector_opaque_p (t2)) | 1847 && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2)) |
1357 && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))) | 1848 && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))) |
1358 return true; | 1849 return true; |
1359 | 1850 |
1360 return false; | 1851 return false; |
1361 } | 1852 } |
1369 vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note) | 1860 vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note) |
1370 { | 1861 { |
1371 static bool emitted_lax_note = false; | 1862 static bool emitted_lax_note = false; |
1372 bool convertible_lax; | 1863 bool convertible_lax; |
1373 | 1864 |
1374 if ((targetm.vector_opaque_p (t1) || targetm.vector_opaque_p (t2)) | 1865 if ((TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2)) |
1375 && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))) | 1866 && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))) |
1376 return true; | 1867 return true; |
1377 | 1868 |
1378 convertible_lax = | 1869 convertible_lax = |
1379 (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)) | 1870 (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)) |
1408 BITWISE indicates a bitwise operation. | 1899 BITWISE indicates a bitwise operation. |
1409 For them, this optimization is safe only if | 1900 For them, this optimization is safe only if |
1410 both args are zero-extended or both are sign-extended. | 1901 both args are zero-extended or both are sign-extended. |
1411 Otherwise, we might change the result. | 1902 Otherwise, we might change the result. |
1412 Eg, (short)-1 | (unsigned short)-1 is (int)-1 | 1903 Eg, (short)-1 | (unsigned short)-1 is (int)-1 |
1413 but calculated in (unsigned short) it would be (unsigned short)-1. | 1904 but calculated in (unsigned short) it would be (unsigned short)-1. |
1414 */ | 1905 */ |
1415 tree shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise) | 1906 tree shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise) |
1416 { | 1907 { |
1417 int unsigned0, unsigned1; | 1908 int unsigned0, unsigned1; |
1418 tree arg0, arg1; | 1909 tree arg0, arg1; |
1423 excessive narrowing when we call get_narrower below. For | 1914 excessive narrowing when we call get_narrower below. For |
1424 example, suppose that OP0 is of unsigned int extended | 1915 example, suppose that OP0 is of unsigned int extended |
1425 from signed char and that RESULT_TYPE is long long int. | 1916 from signed char and that RESULT_TYPE is long long int. |
1426 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look | 1917 If we explicitly cast OP0 to RESULT_TYPE, OP0 would look |
1427 like | 1918 like |
1428 | 1919 |
1429 (long long int) (unsigned int) signed_char | 1920 (long long int) (unsigned int) signed_char |
1430 | 1921 |
1431 which get_narrower would narrow down to | 1922 which get_narrower would narrow down to |
1432 | 1923 |
1433 (unsigned int) signed char | 1924 (unsigned int) signed char |
1434 | 1925 |
1435 If we do not cast OP0 first, get_narrower would return | 1926 If we do not cast OP0 first, get_narrower would return |
1436 signed_char, which is inconsistent with the case of the | 1927 signed_char, which is inconsistent with the case of the |
1437 explicit cast. */ | 1928 explicit cast. */ |
1438 op0 = convert (result_type, op0); | 1929 op0 = convert (result_type, op0); |
1439 op1 = convert (result_type, op1); | 1930 op1 = convert (result_type, op1); |
1444 /* UNS is 1 if the operation to be done is an unsigned one. */ | 1935 /* UNS is 1 if the operation to be done is an unsigned one. */ |
1445 uns = TYPE_UNSIGNED (result_type); | 1936 uns = TYPE_UNSIGNED (result_type); |
1446 | 1937 |
1447 /* Handle the case that OP0 (or OP1) does not *contain* a conversion | 1938 /* Handle the case that OP0 (or OP1) does not *contain* a conversion |
1448 but it *requires* conversion to FINAL_TYPE. */ | 1939 but it *requires* conversion to FINAL_TYPE. */ |
1449 | 1940 |
1450 if ((TYPE_PRECISION (TREE_TYPE (op0)) | 1941 if ((TYPE_PRECISION (TREE_TYPE (op0)) |
1451 == TYPE_PRECISION (TREE_TYPE (arg0))) | 1942 == TYPE_PRECISION (TREE_TYPE (arg0))) |
1452 && TREE_TYPE (op0) != result_type) | 1943 && TREE_TYPE (op0) != result_type) |
1453 unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0)); | 1944 unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0)); |
1454 if ((TYPE_PRECISION (TREE_TYPE (op1)) | 1945 if ((TYPE_PRECISION (TREE_TYPE (op1)) |
1455 == TYPE_PRECISION (TREE_TYPE (arg1))) | 1946 == TYPE_PRECISION (TREE_TYPE (arg1))) |
1456 && TREE_TYPE (op1) != result_type) | 1947 && TREE_TYPE (op1) != result_type) |
1457 unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1)); | 1948 unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1)); |
1458 | 1949 |
1459 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */ | 1950 /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */ |
1460 | 1951 |
1461 /* For bitwise operations, signedness of nominal type | 1952 /* For bitwise operations, signedness of nominal type |
1462 does not matter. Consider only how operands were extended. */ | 1953 does not matter. Consider only how operands were extended. */ |
1463 if (bitwise) | 1954 if (bitwise) |
1464 uns = unsigned0; | 1955 uns = unsigned0; |
1465 | 1956 |
1466 /* Note that in all three cases below we refrain from optimizing | 1957 /* Note that in all three cases below we refrain from optimizing |
1467 an unsigned operation on sign-extended args. | 1958 an unsigned operation on sign-extended args. |
1468 That would not be valid. */ | 1959 That would not be valid. */ |
1469 | 1960 |
1470 /* Both args variable: if both extended in same way | 1961 /* Both args variable: if both extended in same way |
1471 from same width, do it in that width. | 1962 from same width, do it in that width. |
1472 Do it unsigned if args were zero-extended. */ | 1963 Do it unsigned if args were zero-extended. */ |
1473 if ((TYPE_PRECISION (TREE_TYPE (arg0)) | 1964 if ((TYPE_PRECISION (TREE_TYPE (arg0)) |
1474 < TYPE_PRECISION (result_type)) | 1965 < TYPE_PRECISION (result_type)) |
1543 case TRUTH_XOR_EXPR: | 2034 case TRUTH_XOR_EXPR: |
1544 case TRUTH_NOT_EXPR: | 2035 case TRUTH_NOT_EXPR: |
1545 /* Conversion from boolean to a signed:1 bit-field (which only | 2036 /* Conversion from boolean to a signed:1 bit-field (which only |
1546 can hold the values 0 and -1) doesn't lose information - but | 2037 can hold the values 0 and -1) doesn't lose information - but |
1547 it does change the value. */ | 2038 it does change the value. */ |
1548 if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type)) | 2039 if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type)) |
1549 warning (OPT_Wconversion, | 2040 warning (OPT_Wconversion, |
1550 "conversion to %qT from boolean expression", type); | 2041 "conversion to %qT from boolean expression", type); |
1551 return; | 2042 return; |
1552 | 2043 |
1553 case REAL_CST: | 2044 case REAL_CST: |
1564 /* Warn for an integer constant that does not fit into integer type. */ | 2055 /* Warn for an integer constant that does not fit into integer type. */ |
1565 else if (TREE_CODE (expr_type) == INTEGER_TYPE | 2056 else if (TREE_CODE (expr_type) == INTEGER_TYPE |
1566 && TREE_CODE (type) == INTEGER_TYPE | 2057 && TREE_CODE (type) == INTEGER_TYPE |
1567 && !int_fits_type_p (expr, type)) | 2058 && !int_fits_type_p (expr, type)) |
1568 { | 2059 { |
1569 if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type) | 2060 if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type) |
1570 && tree_int_cst_sgn (expr) < 0) | 2061 && tree_int_cst_sgn (expr) < 0) |
1571 warning (OPT_Wsign_conversion, | 2062 warning (OPT_Wsign_conversion, |
1572 "negative integer implicitly converted to unsigned type"); | 2063 "negative integer implicitly converted to unsigned type"); |
1573 else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type)) | 2064 else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type)) |
1574 warning (OPT_Wsign_conversion, "conversion of unsigned constant " | 2065 warning (OPT_Wsign_conversion, "conversion of unsigned constant " |
1609 COND_EXPR, then we do not care about the type of COND_EXPR, | 2100 COND_EXPR, then we do not care about the type of COND_EXPR, |
1610 only about the conversion of each operand. */ | 2101 only about the conversion of each operand. */ |
1611 tree op1 = TREE_OPERAND (expr, 1); | 2102 tree op1 = TREE_OPERAND (expr, 1); |
1612 tree op2 = TREE_OPERAND (expr, 2); | 2103 tree op2 = TREE_OPERAND (expr, 2); |
1613 | 2104 |
1614 if ((TREE_CODE (op1) == REAL_CST || TREE_CODE (op1) == INTEGER_CST | 2105 if ((TREE_CODE (op1) == REAL_CST || TREE_CODE (op1) == INTEGER_CST |
1615 || TREE_CODE (op1) == COND_EXPR) | 2106 || TREE_CODE (op1) == COND_EXPR) |
1616 && (TREE_CODE (op2) == REAL_CST || TREE_CODE (op2) == INTEGER_CST | 2107 && (TREE_CODE (op2) == REAL_CST || TREE_CODE (op2) == INTEGER_CST |
1617 || TREE_CODE (op2) == COND_EXPR)) | 2108 || TREE_CODE (op2) == COND_EXPR)) |
1618 { | 2109 { |
1619 conversion_warning (type, op1); | 2110 conversion_warning (type, op1); |
1636 /* Don't warn about unsigned char y = 0xff, x = (int) y; */ | 2127 /* Don't warn about unsigned char y = 0xff, x = (int) y; */ |
1637 expr = get_unwidened (expr, 0); | 2128 expr = get_unwidened (expr, 0); |
1638 expr_type = TREE_TYPE (expr); | 2129 expr_type = TREE_TYPE (expr); |
1639 | 2130 |
1640 /* Don't warn for short y; short x = ((int)y & 0xff); */ | 2131 /* Don't warn for short y; short x = ((int)y & 0xff); */ |
1641 if (TREE_CODE (expr) == BIT_AND_EXPR | 2132 if (TREE_CODE (expr) == BIT_AND_EXPR |
1642 || TREE_CODE (expr) == BIT_IOR_EXPR | 2133 || TREE_CODE (expr) == BIT_IOR_EXPR |
1643 || TREE_CODE (expr) == BIT_XOR_EXPR) | 2134 || TREE_CODE (expr) == BIT_XOR_EXPR) |
1644 { | 2135 { |
1645 /* If both args were extended from a shortest type, | 2136 /* If both args were extended from a shortest type, |
1646 use that type if that is safe. */ | 2137 use that type if that is safe. */ |
1647 expr_type = shorten_binary_op (expr_type, | 2138 expr_type = shorten_binary_op (expr_type, |
1648 TREE_OPERAND (expr, 0), | 2139 TREE_OPERAND (expr, 0), |
1649 TREE_OPERAND (expr, 1), | 2140 TREE_OPERAND (expr, 1), |
1650 /* bitwise */1); | 2141 /* bitwise */1); |
1651 | 2142 |
1652 if (TREE_CODE (expr) == BIT_AND_EXPR) | 2143 if (TREE_CODE (expr) == BIT_AND_EXPR) |
1653 { | 2144 { |
1654 tree op0 = TREE_OPERAND (expr, 0); | 2145 tree op0 = TREE_OPERAND (expr, 0); |
1662 if ((TREE_CODE (op0) == INTEGER_CST | 2153 if ((TREE_CODE (op0) == INTEGER_CST |
1663 && int_fits_type_p (op0, c_common_signed_type (type)) | 2154 && int_fits_type_p (op0, c_common_signed_type (type)) |
1664 && int_fits_type_p (op0, c_common_unsigned_type (type))) | 2155 && int_fits_type_p (op0, c_common_unsigned_type (type))) |
1665 || (TREE_CODE (op1) == INTEGER_CST | 2156 || (TREE_CODE (op1) == INTEGER_CST |
1666 && int_fits_type_p (op1, c_common_signed_type (type)) | 2157 && int_fits_type_p (op1, c_common_signed_type (type)) |
1667 && int_fits_type_p (op1, | 2158 && int_fits_type_p (op1, |
1668 c_common_unsigned_type (type)))) | 2159 c_common_unsigned_type (type)))) |
1669 return; | 2160 return; |
1670 /* If constant is unsigned and fits in the target | 2161 /* If constant is unsigned and fits in the target |
1671 type, then the result will also fit. */ | 2162 type, then the result will also fit. */ |
1672 else if ((TREE_CODE (op0) == INTEGER_CST | 2163 else if ((TREE_CODE (op0) == INTEGER_CST |
1673 && unsigned0 | 2164 && unsigned0 |
1674 && int_fits_type_p (op0, type)) | 2165 && int_fits_type_p (op0, type)) |
1675 || (TREE_CODE (op1) == INTEGER_CST | 2166 || (TREE_CODE (op1) == INTEGER_CST |
1676 && unsigned1 | 2167 && unsigned1 |
1677 && int_fits_type_p (op1, type))) | 2168 && int_fits_type_p (op1, type))) |
1678 return; | 2169 return; |
1679 } | 2170 } |
1680 } | 2171 } |
1681 /* Warn for integer types converted to smaller integer types. */ | 2172 /* Warn for integer types converted to smaller integer types. */ |
1682 if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type)) | 2173 if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type)) |
1683 give_warning = true; | 2174 give_warning = true; |
1684 | 2175 |
1685 /* When they are the same width but different signedness, | 2176 /* When they are the same width but different signedness, |
1686 then the value may change. */ | 2177 then the value may change. */ |
1687 else if ((TYPE_PRECISION (type) == TYPE_PRECISION (expr_type) | 2178 else if ((TYPE_PRECISION (type) == TYPE_PRECISION (expr_type) |
1701 else if (TREE_CODE (expr_type) == INTEGER_TYPE | 2192 else if (TREE_CODE (expr_type) == INTEGER_TYPE |
1702 && TREE_CODE (type) == REAL_TYPE) | 2193 && TREE_CODE (type) == REAL_TYPE) |
1703 { | 2194 { |
1704 tree type_low_bound = TYPE_MIN_VALUE (expr_type); | 2195 tree type_low_bound = TYPE_MIN_VALUE (expr_type); |
1705 tree type_high_bound = TYPE_MAX_VALUE (expr_type); | 2196 tree type_high_bound = TYPE_MAX_VALUE (expr_type); |
1706 REAL_VALUE_TYPE real_low_bound | 2197 REAL_VALUE_TYPE real_low_bound |
1707 = real_value_from_int_cst (0, type_low_bound); | 2198 = real_value_from_int_cst (0, type_low_bound); |
1708 REAL_VALUE_TYPE real_high_bound | 2199 REAL_VALUE_TYPE real_high_bound |
1709 = real_value_from_int_cst (0, type_high_bound); | 2200 = real_value_from_int_cst (0, type_high_bound); |
1710 | 2201 |
1711 if (!exact_real_truncate (TYPE_MODE (type), &real_low_bound) | 2202 if (!exact_real_truncate (TYPE_MODE (type), &real_low_bound) |
1712 || !exact_real_truncate (TYPE_MODE (type), &real_high_bound)) | 2203 || !exact_real_truncate (TYPE_MODE (type), &real_high_bound)) |
1713 give_warning = true; | 2204 give_warning = true; |
1752 warning (OPT_Woverflow, | 2243 warning (OPT_Woverflow, |
1753 "large integer implicitly truncated to unsigned type"); | 2244 "large integer implicitly truncated to unsigned type"); |
1754 else | 2245 else |
1755 conversion_warning (type, expr); | 2246 conversion_warning (type, expr); |
1756 } | 2247 } |
1757 else if (!int_fits_type_p (expr, c_common_unsigned_type (type))) | 2248 else if (!int_fits_type_p (expr, c_common_unsigned_type (type))) |
1758 warning (OPT_Woverflow, | 2249 warning (OPT_Woverflow, |
1759 "overflow in implicit constant conversion"); | 2250 "overflow in implicit constant conversion"); |
1760 /* No warning for converting 0x80000000 to int. */ | 2251 /* No warning for converting 0x80000000 to int. */ |
1761 else if (pedantic | 2252 else if (pedantic |
1762 && (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE | 2253 && (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE |
1783 | 2274 |
1784 tree | 2275 tree |
1785 convert_and_check (tree type, tree expr) | 2276 convert_and_check (tree type, tree expr) |
1786 { | 2277 { |
1787 tree result; | 2278 tree result; |
2279 tree expr_for_warning; | |
2280 | |
2281 /* Convert from a value with possible excess precision rather than | |
2282 via the semantic type, but do not warn about values not fitting | |
2283 exactly in the semantic type. */ | |
2284 if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR) | |
2285 { | |
2286 tree orig_type = TREE_TYPE (expr); | |
2287 expr = TREE_OPERAND (expr, 0); | |
2288 expr_for_warning = convert (orig_type, expr); | |
2289 if (orig_type == type) | |
2290 return expr_for_warning; | |
2291 } | |
2292 else | |
2293 expr_for_warning = expr; | |
1788 | 2294 |
1789 if (TREE_TYPE (expr) == type) | 2295 if (TREE_TYPE (expr) == type) |
1790 return expr; | 2296 return expr; |
1791 | 2297 |
1792 result = convert (type, expr); | 2298 result = convert (type, expr); |
1793 | 2299 |
1794 if (!skip_evaluation && !TREE_OVERFLOW_P (expr) && result != error_mark_node) | 2300 if (c_inhibit_evaluation_warnings == 0 |
1795 warnings_for_convert_and_check (type, expr, result); | 2301 && !TREE_OVERFLOW_P (expr) |
2302 && result != error_mark_node) | |
2303 warnings_for_convert_and_check (type, expr_for_warning, result); | |
1796 | 2304 |
1797 return result; | 2305 return result; |
1798 } | 2306 } |
1799 | 2307 |
1800 /* A node in a list that describes references to variables (EXPR), which are | 2308 /* A node in a list that describes references to variables (EXPR), which are |
1830 | 2338 |
1831 static void add_tlist (struct tlist **, struct tlist *, tree, int); | 2339 static void add_tlist (struct tlist **, struct tlist *, tree, int); |
1832 static void merge_tlist (struct tlist **, struct tlist *, int); | 2340 static void merge_tlist (struct tlist **, struct tlist *, int); |
1833 static void verify_tree (tree, struct tlist **, struct tlist **, tree); | 2341 static void verify_tree (tree, struct tlist **, struct tlist **, tree); |
1834 static int warning_candidate_p (tree); | 2342 static int warning_candidate_p (tree); |
2343 static bool candidate_equal_p (const_tree, const_tree); | |
1835 static void warn_for_collisions (struct tlist *); | 2344 static void warn_for_collisions (struct tlist *); |
1836 static void warn_for_collisions_1 (tree, tree, struct tlist *, int); | 2345 static void warn_for_collisions_1 (tree, tree, struct tlist *, int); |
1837 static struct tlist *new_tlist (struct tlist *, tree, tree); | 2346 static struct tlist *new_tlist (struct tlist *, tree, tree); |
1838 | 2347 |
1839 /* Create a new struct tlist and fill in its fields. */ | 2348 /* Create a new struct tlist and fill in its fields. */ |
1857 while (add) | 2366 while (add) |
1858 { | 2367 { |
1859 struct tlist *next = add->next; | 2368 struct tlist *next = add->next; |
1860 if (!copy) | 2369 if (!copy) |
1861 add->next = *to; | 2370 add->next = *to; |
1862 if (!exclude_writer || add->writer != exclude_writer) | 2371 if (!exclude_writer || !candidate_equal_p (add->writer, exclude_writer)) |
1863 *to = copy ? new_tlist (*to, add->expr, add->writer) : add; | 2372 *to = copy ? new_tlist (*to, add->expr, add->writer) : add; |
1864 add = next; | 2373 add = next; |
1865 } | 2374 } |
1866 } | 2375 } |
1867 | 2376 |
1884 int found = 0; | 2393 int found = 0; |
1885 struct tlist *tmp2; | 2394 struct tlist *tmp2; |
1886 struct tlist *next = add->next; | 2395 struct tlist *next = add->next; |
1887 | 2396 |
1888 for (tmp2 = *to; tmp2; tmp2 = tmp2->next) | 2397 for (tmp2 = *to; tmp2; tmp2 = tmp2->next) |
1889 if (tmp2->expr == add->expr) | 2398 if (candidate_equal_p (tmp2->expr, add->expr)) |
1890 { | 2399 { |
1891 found = 1; | 2400 found = 1; |
1892 if (!tmp2->writer) | 2401 if (!tmp2->writer) |
1893 tmp2->writer = add->writer; | 2402 tmp2->writer = add->writer; |
1894 } | 2403 } |
1912 { | 2421 { |
1913 struct tlist *tmp; | 2422 struct tlist *tmp; |
1914 | 2423 |
1915 /* Avoid duplicate warnings. */ | 2424 /* Avoid duplicate warnings. */ |
1916 for (tmp = warned_ids; tmp; tmp = tmp->next) | 2425 for (tmp = warned_ids; tmp; tmp = tmp->next) |
1917 if (tmp->expr == written) | 2426 if (candidate_equal_p (tmp->expr, written)) |
1918 return; | 2427 return; |
1919 | 2428 |
1920 while (list) | 2429 while (list) |
1921 { | 2430 { |
1922 if (list->expr == written | 2431 if (candidate_equal_p (list->expr, written) |
1923 && list->writer != writer | 2432 && !candidate_equal_p (list->writer, writer) |
1924 && (!only_writes || list->writer) | 2433 && (!only_writes || list->writer)) |
1925 && DECL_NAME (list->expr)) | |
1926 { | 2434 { |
1927 warned_ids = new_tlist (warned_ids, written, NULL_TREE); | 2435 warned_ids = new_tlist (warned_ids, written, NULL_TREE); |
1928 warning_at (EXPR_HAS_LOCATION (writer) | 2436 warning_at (EXPR_HAS_LOCATION (writer) |
1929 ? EXPR_LOCATION (writer) : input_location, | 2437 ? EXPR_LOCATION (writer) : input_location, |
1930 OPT_Wsequence_point, "operation on %qE may be undefined", | 2438 OPT_Wsequence_point, "operation on %qE may be undefined", |
1952 /* Return nonzero if X is a tree that can be verified by the sequence point | 2460 /* Return nonzero if X is a tree that can be verified by the sequence point |
1953 warnings. */ | 2461 warnings. */ |
1954 static int | 2462 static int |
1955 warning_candidate_p (tree x) | 2463 warning_candidate_p (tree x) |
1956 { | 2464 { |
1957 return TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == PARM_DECL; | 2465 /* !VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c |
2466 (lvalue_p) crash on TRY/CATCH. */ | |
2467 return !(DECL_P (x) && DECL_ARTIFICIAL (x)) | |
2468 && TREE_TYPE (x) && !VOID_TYPE_P (TREE_TYPE (x)) && lvalue_p (x); | |
2469 } | |
2470 | |
2471 /* Return nonzero if X and Y appear to be the same candidate (or NULL) */ | |
2472 static bool | |
2473 candidate_equal_p (const_tree x, const_tree y) | |
2474 { | |
2475 return (x == y) || (x && y && operand_equal_p (x, y, 0)); | |
1958 } | 2476 } |
1959 | 2477 |
1960 /* Walk the tree X, and record accesses to variables. If X is written by the | 2478 /* Walk the tree X, and record accesses to variables. If X is written by the |
1961 parent tree, WRITER is the parent. | 2479 parent tree, WRITER is the parent. |
1962 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this | 2480 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this |
1998 restart: | 2516 restart: |
1999 code = TREE_CODE (x); | 2517 code = TREE_CODE (x); |
2000 cl = TREE_CODE_CLASS (code); | 2518 cl = TREE_CODE_CLASS (code); |
2001 | 2519 |
2002 if (warning_candidate_p (x)) | 2520 if (warning_candidate_p (x)) |
2003 { | 2521 *pno_sp = new_tlist (*pno_sp, x, writer); |
2004 *pno_sp = new_tlist (*pno_sp, x, writer); | |
2005 return; | |
2006 } | |
2007 | 2522 |
2008 switch (code) | 2523 switch (code) |
2009 { | 2524 { |
2010 case CONSTRUCTOR: | 2525 case CONSTRUCTOR: |
2011 return; | 2526 return; |
2083 args and the function address. Side effects of the function address, | 2598 args and the function address. Side effects of the function address, |
2084 however, are not ordered by the sequence point of the call. */ | 2599 however, are not ordered by the sequence point of the call. */ |
2085 { | 2600 { |
2086 call_expr_arg_iterator iter; | 2601 call_expr_arg_iterator iter; |
2087 tree arg; | 2602 tree arg; |
2088 tmp_before = tmp_nosp = 0; | 2603 tmp_before = tmp_nosp = 0; |
2089 verify_tree (CALL_EXPR_FN (x), &tmp_before, &tmp_nosp, NULL_TREE); | 2604 verify_tree (CALL_EXPR_FN (x), &tmp_before, &tmp_nosp, NULL_TREE); |
2090 FOR_EACH_CALL_EXPR_ARG (arg, iter, x) | 2605 FOR_EACH_CALL_EXPR_ARG (arg, iter, x) |
2091 { | 2606 { |
2092 tmp_list2 = tmp_list3 = 0; | 2607 tmp_list2 = tmp_list3 = 0; |
2093 verify_tree (arg, &tmp_list2, &tmp_list3, NULL_TREE); | 2608 verify_tree (arg, &tmp_list2, &tmp_list3, NULL_TREE); |
2114 | 2629 |
2115 case SAVE_EXPR: | 2630 case SAVE_EXPR: |
2116 { | 2631 { |
2117 struct tlist_cache *t; | 2632 struct tlist_cache *t; |
2118 for (t = save_expr_cache; t; t = t->next) | 2633 for (t = save_expr_cache; t; t = t->next) |
2119 if (t->expr == x) | 2634 if (candidate_equal_p (t->expr, x)) |
2120 break; | 2635 break; |
2121 | 2636 |
2122 if (!t) | 2637 if (!t) |
2123 { | 2638 { |
2124 t = XOBNEW (&tlist_obstack, struct tlist_cache); | 2639 t = XOBNEW (&tlist_obstack, struct tlist_cache); |
2784 void | 3299 void |
2785 c_register_builtin_type (tree type, const char* name) | 3300 c_register_builtin_type (tree type, const char* name) |
2786 { | 3301 { |
2787 tree decl; | 3302 tree decl; |
2788 | 3303 |
2789 decl = build_decl (TYPE_DECL, get_identifier (name), type); | 3304 decl = build_decl (UNKNOWN_LOCATION, |
3305 TYPE_DECL, get_identifier (name), type); | |
2790 DECL_ARTIFICIAL (decl) = 1; | 3306 DECL_ARTIFICIAL (decl) = 1; |
2791 if (!TYPE_NAME (type)) | 3307 if (!TYPE_NAME (type)) |
2792 TYPE_NAME (type) = decl; | 3308 TYPE_NAME (type) = decl; |
2793 pushdecl (decl); | 3309 pushdecl (decl); |
2794 | 3310 |
3167 warning. */ | 3683 warning. */ |
3168 if (warn_type_limits && !in_system_header | 3684 if (warn_type_limits && !in_system_header |
3169 && !(TREE_CODE (primop0) == INTEGER_CST | 3685 && !(TREE_CODE (primop0) == INTEGER_CST |
3170 && !TREE_OVERFLOW (convert (c_common_signed_type (type), | 3686 && !TREE_OVERFLOW (convert (c_common_signed_type (type), |
3171 primop0)))) | 3687 primop0)))) |
3172 warning (OPT_Wtype_limits, | 3688 warning (OPT_Wtype_limits, |
3173 "comparison of unsigned expression >= 0 is always true"); | 3689 "comparison of unsigned expression >= 0 is always true"); |
3174 value = truthvalue_true_node; | 3690 value = truthvalue_true_node; |
3175 break; | 3691 break; |
3176 | 3692 |
3177 case LT_EXPR: | 3693 case LT_EXPR: |
3178 if (warn_type_limits && !in_system_header | 3694 if (warn_type_limits && !in_system_header |
3179 && !(TREE_CODE (primop0) == INTEGER_CST | 3695 && !(TREE_CODE (primop0) == INTEGER_CST |
3180 && !TREE_OVERFLOW (convert (c_common_signed_type (type), | 3696 && !TREE_OVERFLOW (convert (c_common_signed_type (type), |
3181 primop0)))) | 3697 primop0)))) |
3182 warning (OPT_Wtype_limits, | 3698 warning (OPT_Wtype_limits, |
3183 "comparison of unsigned expression < 0 is always false"); | 3699 "comparison of unsigned expression < 0 is always false"); |
3184 value = truthvalue_false_node; | 3700 value = truthvalue_false_node; |
3185 break; | 3701 break; |
3186 | 3702 |
3187 default: | 3703 default: |
3209 | 3725 |
3210 /* Return a tree for the sum or difference (RESULTCODE says which) | 3726 /* Return a tree for the sum or difference (RESULTCODE says which) |
3211 of pointer PTROP and integer INTOP. */ | 3727 of pointer PTROP and integer INTOP. */ |
3212 | 3728 |
3213 tree | 3729 tree |
3214 pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop) | 3730 pointer_int_sum (location_t loc, enum tree_code resultcode, |
3731 tree ptrop, tree intop) | |
3215 { | 3732 { |
3216 tree size_exp, ret; | 3733 tree size_exp, ret; |
3217 | 3734 |
3218 /* The result is a pointer of the same type that is being added. */ | 3735 /* The result is a pointer of the same type that is being added. */ |
3219 tree result_type = TREE_TYPE (ptrop); | 3736 tree result_type = TREE_TYPE (ptrop); |
3220 | 3737 |
3221 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE) | 3738 if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE) |
3222 { | 3739 { |
3223 pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, | 3740 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith, |
3224 "pointer of type %<void *%> used in arithmetic"); | 3741 "pointer of type %<void *%> used in arithmetic"); |
3225 size_exp = integer_one_node; | 3742 size_exp = integer_one_node; |
3226 } | 3743 } |
3227 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE) | 3744 else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE) |
3228 { | 3745 { |
3229 pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, | 3746 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith, |
3230 "pointer to a function used in arithmetic"); | 3747 "pointer to a function used in arithmetic"); |
3231 size_exp = integer_one_node; | 3748 size_exp = integer_one_node; |
3232 } | 3749 } |
3233 else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE) | 3750 else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE) |
3234 { | 3751 { |
3235 pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, | 3752 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith, |
3236 "pointer to member function used in arithmetic"); | 3753 "pointer to member function used in arithmetic"); |
3237 size_exp = integer_one_node; | 3754 size_exp = integer_one_node; |
3238 } | 3755 } |
3239 else | 3756 else |
3240 size_exp = size_in_bytes (TREE_TYPE (result_type)); | 3757 size_exp = size_in_bytes (TREE_TYPE (result_type)); |
3285 | 3802 |
3286 /* Replace the integer argument with a suitable product by the object size. | 3803 /* Replace the integer argument with a suitable product by the object size. |
3287 Do this multiplication as signed, then convert to the appropriate | 3804 Do this multiplication as signed, then convert to the appropriate |
3288 type for the pointer operation. */ | 3805 type for the pointer operation. */ |
3289 intop = convert (sizetype, | 3806 intop = convert (sizetype, |
3290 build_binary_op (EXPR_LOCATION (intop), | 3807 build_binary_op (loc, |
3291 MULT_EXPR, intop, | 3808 MULT_EXPR, intop, |
3292 convert (TREE_TYPE (intop), size_exp), 1)); | 3809 convert (TREE_TYPE (intop), size_exp), 1)); |
3293 | 3810 |
3294 /* Create the sum or difference. */ | 3811 /* Create the sum or difference. */ |
3295 if (resultcode == MINUS_EXPR) | 3812 if (resultcode == MINUS_EXPR) |
3296 intop = fold_build1 (NEGATE_EXPR, sizetype, intop); | 3813 intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop); |
3297 | 3814 |
3298 ret = fold_build2 (POINTER_PLUS_EXPR, result_type, ptrop, intop); | 3815 ret = fold_build2_loc (loc, POINTER_PLUS_EXPR, result_type, ptrop, intop); |
3299 | 3816 |
3300 fold_undefer_and_ignore_overflow_warnings (); | 3817 fold_undefer_and_ignore_overflow_warnings (); |
3301 | 3818 |
3302 return ret; | 3819 return ret; |
3303 } | 3820 } |
3304 | 3821 |
3822 /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded | |
3823 and if NON_CONST is known not to be permitted in an evaluated part | |
3824 of a constant expression. */ | |
3825 | |
3826 tree | |
3827 c_wrap_maybe_const (tree expr, bool non_const) | |
3828 { | |
3829 bool nowarning = TREE_NO_WARNING (expr); | |
3830 location_t loc = EXPR_LOCATION (expr); | |
3831 | |
3832 /* This should never be called for C++. */ | |
3833 if (c_dialect_cxx ()) | |
3834 gcc_unreachable (); | |
3835 | |
3836 /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING. */ | |
3837 STRIP_TYPE_NOPS (expr); | |
3838 expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr); | |
3839 C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const; | |
3840 if (nowarning) | |
3841 TREE_NO_WARNING (expr) = 1; | |
3842 protected_set_expr_location (expr, loc); | |
3843 | |
3844 return expr; | |
3845 } | |
3846 | |
3847 /* Wrap a SAVE_EXPR around EXPR, if appropriate. Like save_expr, but | |
3848 for C folds the inside expression and wraps a C_MAYBE_CONST_EXPR | |
3849 around the SAVE_EXPR if needed so that c_fully_fold does not need | |
3850 to look inside SAVE_EXPRs. */ | |
3851 | |
3852 tree | |
3853 c_save_expr (tree expr) | |
3854 { | |
3855 bool maybe_const = true; | |
3856 if (c_dialect_cxx ()) | |
3857 return save_expr (expr); | |
3858 expr = c_fully_fold (expr, false, &maybe_const); | |
3859 expr = save_expr (expr); | |
3860 if (!maybe_const) | |
3861 expr = c_wrap_maybe_const (expr, true); | |
3862 return expr; | |
3863 } | |
3864 | |
3305 /* Return whether EXPR is a declaration whose address can never be | 3865 /* Return whether EXPR is a declaration whose address can never be |
3306 NULL. */ | 3866 NULL. */ |
3307 | 3867 |
3308 bool | 3868 bool |
3309 decl_with_nonnull_addr_p (const_tree expr) | 3869 decl_with_nonnull_addr_p (const_tree expr) |
3338 case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR: | 3898 case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR: |
3339 case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR: | 3899 case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR: |
3340 case ORDERED_EXPR: case UNORDERED_EXPR: | 3900 case ORDERED_EXPR: case UNORDERED_EXPR: |
3341 if (TREE_TYPE (expr) == truthvalue_type_node) | 3901 if (TREE_TYPE (expr) == truthvalue_type_node) |
3342 return expr; | 3902 return expr; |
3343 return build2 (TREE_CODE (expr), truthvalue_type_node, | 3903 expr = build2 (TREE_CODE (expr), truthvalue_type_node, |
3344 TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1)); | 3904 TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1)); |
3905 goto ret; | |
3345 | 3906 |
3346 case TRUTH_ANDIF_EXPR: | 3907 case TRUTH_ANDIF_EXPR: |
3347 case TRUTH_ORIF_EXPR: | 3908 case TRUTH_ORIF_EXPR: |
3348 case TRUTH_AND_EXPR: | 3909 case TRUTH_AND_EXPR: |
3349 case TRUTH_OR_EXPR: | 3910 case TRUTH_OR_EXPR: |
3350 case TRUTH_XOR_EXPR: | 3911 case TRUTH_XOR_EXPR: |
3351 if (TREE_TYPE (expr) == truthvalue_type_node) | 3912 if (TREE_TYPE (expr) == truthvalue_type_node) |
3352 return expr; | 3913 return expr; |
3353 return build2 (TREE_CODE (expr), truthvalue_type_node, | 3914 expr = build2 (TREE_CODE (expr), truthvalue_type_node, |
3354 c_common_truthvalue_conversion (location, | 3915 c_common_truthvalue_conversion (location, |
3355 TREE_OPERAND (expr, 0)), | 3916 TREE_OPERAND (expr, 0)), |
3356 c_common_truthvalue_conversion (location, | 3917 c_common_truthvalue_conversion (location, |
3357 TREE_OPERAND (expr, 1))); | 3918 TREE_OPERAND (expr, 1))); |
3919 goto ret; | |
3358 | 3920 |
3359 case TRUTH_NOT_EXPR: | 3921 case TRUTH_NOT_EXPR: |
3360 if (TREE_TYPE (expr) == truthvalue_type_node) | 3922 if (TREE_TYPE (expr) == truthvalue_type_node) |
3361 return expr; | 3923 return expr; |
3362 return build1 (TREE_CODE (expr), truthvalue_type_node, | 3924 expr = build1 (TREE_CODE (expr), truthvalue_type_node, |
3363 c_common_truthvalue_conversion (location, | 3925 c_common_truthvalue_conversion (location, |
3364 TREE_OPERAND (expr, 0))); | 3926 TREE_OPERAND (expr, 0))); |
3927 goto ret; | |
3365 | 3928 |
3366 case ERROR_MARK: | 3929 case ERROR_MARK: |
3367 return expr; | 3930 return expr; |
3368 | 3931 |
3369 case INTEGER_CST: | 3932 case INTEGER_CST: |
3405 gcc_assert (DECL_WEAK (inner)); | 3968 gcc_assert (DECL_WEAK (inner)); |
3406 break; | 3969 break; |
3407 } | 3970 } |
3408 | 3971 |
3409 if (TREE_SIDE_EFFECTS (inner)) | 3972 if (TREE_SIDE_EFFECTS (inner)) |
3410 return build2 (COMPOUND_EXPR, truthvalue_type_node, | 3973 { |
3411 inner, truthvalue_true_node); | 3974 expr = build2 (COMPOUND_EXPR, truthvalue_type_node, |
3975 inner, truthvalue_true_node); | |
3976 goto ret; | |
3977 } | |
3412 else | 3978 else |
3413 return truthvalue_true_node; | 3979 return truthvalue_true_node; |
3414 } | 3980 } |
3415 | 3981 |
3416 case COMPLEX_EXPR: | 3982 case COMPLEX_EXPR: |
3417 return build_binary_op (EXPR_LOCATION (expr), | 3983 expr = build_binary_op (EXPR_LOCATION (expr), |
3418 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)) | 3984 (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)) |
3419 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), | 3985 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), |
3420 c_common_truthvalue_conversion (location, | 3986 c_common_truthvalue_conversion (location, |
3421 TREE_OPERAND (expr, 0)), | 3987 TREE_OPERAND (expr, 0)), |
3422 c_common_truthvalue_conversion (location, | 3988 c_common_truthvalue_conversion (location, |
3423 TREE_OPERAND (expr, 1)), | 3989 TREE_OPERAND (expr, 1)), |
3424 0); | 3990 0); |
3991 goto ret; | |
3425 | 3992 |
3426 case NEGATE_EXPR: | 3993 case NEGATE_EXPR: |
3427 case ABS_EXPR: | 3994 case ABS_EXPR: |
3428 case FLOAT_EXPR: | 3995 case FLOAT_EXPR: |
3996 case EXCESS_PRECISION_EXPR: | |
3429 /* These don't change whether an object is nonzero or zero. */ | 3997 /* These don't change whether an object is nonzero or zero. */ |
3430 return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0)); | 3998 return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0)); |
3431 | 3999 |
3432 case LROTATE_EXPR: | 4000 case LROTATE_EXPR: |
3433 case RROTATE_EXPR: | 4001 case RROTATE_EXPR: |
3434 /* These don't change whether an object is zero or nonzero, but | 4002 /* These don't change whether an object is zero or nonzero, but |
3435 we can't ignore them if their second arg has side-effects. */ | 4003 we can't ignore them if their second arg has side-effects. */ |
3436 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))) | 4004 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))) |
3437 return build2 (COMPOUND_EXPR, truthvalue_type_node, | 4005 { |
3438 TREE_OPERAND (expr, 1), | 4006 expr = build2 (COMPOUND_EXPR, truthvalue_type_node, |
3439 c_common_truthvalue_conversion | 4007 TREE_OPERAND (expr, 1), |
3440 (location, TREE_OPERAND (expr, 0))); | 4008 c_common_truthvalue_conversion |
4009 (location, TREE_OPERAND (expr, 0))); | |
4010 goto ret; | |
4011 } | |
3441 else | 4012 else |
3442 return c_common_truthvalue_conversion (location, | 4013 return c_common_truthvalue_conversion (location, |
3443 TREE_OPERAND (expr, 0)); | 4014 TREE_OPERAND (expr, 0)); |
3444 | 4015 |
3445 case COND_EXPR: | 4016 case COND_EXPR: |
3446 /* Distribute the conversion into the arms of a COND_EXPR. */ | 4017 /* Distribute the conversion into the arms of a COND_EXPR. */ |
3447 return fold_build3 (COND_EXPR, truthvalue_type_node, | 4018 if (c_dialect_cxx ()) |
3448 TREE_OPERAND (expr, 0), | 4019 { |
3449 c_common_truthvalue_conversion (location, | 4020 expr = fold_build3_loc (location, COND_EXPR, truthvalue_type_node, |
3450 TREE_OPERAND (expr, 1)), | 4021 TREE_OPERAND (expr, 0), |
3451 c_common_truthvalue_conversion (location, | 4022 c_common_truthvalue_conversion (location, |
3452 TREE_OPERAND (expr, 2))); | 4023 TREE_OPERAND (expr, |
4024 1)), | |
4025 c_common_truthvalue_conversion (location, | |
4026 TREE_OPERAND (expr, | |
4027 2))); | |
4028 goto ret; | |
4029 } | |
4030 else | |
4031 { | |
4032 /* Folding will happen later for C. */ | |
4033 expr = build3 (COND_EXPR, truthvalue_type_node, | |
4034 TREE_OPERAND (expr, 0), | |
4035 c_common_truthvalue_conversion (location, | |
4036 TREE_OPERAND (expr, 1)), | |
4037 c_common_truthvalue_conversion (location, | |
4038 TREE_OPERAND (expr, 2))); | |
4039 goto ret; | |
4040 } | |
3453 | 4041 |
3454 CASE_CONVERT: | 4042 CASE_CONVERT: |
3455 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE, | 4043 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE, |
3456 since that affects how `default_conversion' will behave. */ | 4044 since that affects how `default_conversion' will behave. */ |
3457 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE | 4045 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE |
3478 break; | 4066 break; |
3479 } | 4067 } |
3480 | 4068 |
3481 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE) | 4069 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE) |
3482 { | 4070 { |
3483 tree t = save_expr (expr); | 4071 tree t = c_save_expr (expr); |
3484 return (build_binary_op | 4072 expr = (build_binary_op |
3485 (EXPR_LOCATION (expr), | 4073 (EXPR_LOCATION (expr), |
3486 (TREE_SIDE_EFFECTS (expr) | 4074 (TREE_SIDE_EFFECTS (expr) |
3487 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), | 4075 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), |
3488 c_common_truthvalue_conversion | 4076 c_common_truthvalue_conversion |
3489 (location, | 4077 (location, |
3490 build_unary_op (location, REALPART_EXPR, t, 0)), | 4078 build_unary_op (location, REALPART_EXPR, t, 0)), |
3491 c_common_truthvalue_conversion | 4079 c_common_truthvalue_conversion |
3492 (location, | 4080 (location, |
3493 build_unary_op (location, IMAGPART_EXPR, t, 0)), | 4081 build_unary_op (location, IMAGPART_EXPR, t, 0)), |
3494 0)); | 4082 0)); |
4083 goto ret; | |
3495 } | 4084 } |
3496 | 4085 |
3497 if (TREE_CODE (TREE_TYPE (expr)) == FIXED_POINT_TYPE) | 4086 if (TREE_CODE (TREE_TYPE (expr)) == FIXED_POINT_TYPE) |
3498 { | 4087 { |
3499 tree fixed_zero_node = build_fixed (TREE_TYPE (expr), | 4088 tree fixed_zero_node = build_fixed (TREE_TYPE (expr), |
3500 FCONST0 (TYPE_MODE | 4089 FCONST0 (TYPE_MODE |
3501 (TREE_TYPE (expr)))); | 4090 (TREE_TYPE (expr)))); |
3502 return build_binary_op (EXPR_LOCATION (expr), | 4091 return build_binary_op (location, NE_EXPR, expr, fixed_zero_node, 1); |
3503 NE_EXPR, expr, fixed_zero_node, 1); | 4092 } |
3504 } | 4093 else |
3505 | 4094 return build_binary_op (location, NE_EXPR, expr, integer_zero_node, 1); |
3506 return build_binary_op (EXPR_LOCATION (expr), | 4095 |
3507 NE_EXPR, expr, integer_zero_node, 1); | 4096 ret: |
4097 protected_set_expr_location (expr, location); | |
4098 return expr; | |
3508 } | 4099 } |
3509 | 4100 |
3510 static void def_builtin_1 (enum built_in_function fncode, | 4101 static void def_builtin_1 (enum built_in_function fncode, |
3511 const char *name, | 4102 const char *name, |
3512 enum built_in_class fnclass, | 4103 enum built_in_class fnclass, |
3547 type = TREE_TYPE (type); | 4138 type = TREE_TYPE (type); |
3548 if (!type | 4139 if (!type |
3549 || !POINTER_TYPE_P (type) | 4140 || !POINTER_TYPE_P (type) |
3550 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))) | 4141 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))) |
3551 error ("invalid use of %<restrict%>"); | 4142 error ("invalid use of %<restrict%>"); |
3552 else if (flag_strict_aliasing && type == TREE_TYPE (decl)) | |
3553 /* Indicate we need to make a unique alias set for this pointer. | |
3554 We can't do it here because it might be pointing to an | |
3555 incomplete type. */ | |
3556 DECL_POINTER_ALIAS_SET (decl) = -2; | |
3557 } | 4143 } |
3558 } | 4144 } |
3559 | 4145 |
3560 /* Hash function for the problem of multiple type definitions in | 4146 /* Hash function for the problem of multiple type definitions in |
3561 different files. This must hash all types that will compare | 4147 different files. This must hash all types that will compare |
3613 c_common_get_alias_set (tree t) | 4199 c_common_get_alias_set (tree t) |
3614 { | 4200 { |
3615 tree u; | 4201 tree u; |
3616 PTR *slot; | 4202 PTR *slot; |
3617 | 4203 |
4204 /* For VLAs, use the alias set of the element type rather than the | |
4205 default of alias set 0 for types compared structurally. */ | |
4206 if (TYPE_P (t) && TYPE_STRUCTURAL_EQUALITY_P (t)) | |
4207 { | |
4208 if (TREE_CODE (t) == ARRAY_TYPE) | |
4209 return get_alias_set (TREE_TYPE (t)); | |
4210 return -1; | |
4211 } | |
4212 | |
3618 /* Permit type-punning when accessing a union, provided the access | 4213 /* Permit type-punning when accessing a union, provided the access |
3619 is directly through the union. For example, this code does not | 4214 is directly through the union. For example, this code does not |
3620 permit taking the address of a union member and then storing | 4215 permit taking the address of a union member and then storing |
3621 through it. Even the type-punning allowed here is a GCC | 4216 through it. Even the type-punning allowed here is a GCC |
3622 extension, albeit a common and useful one; the C standard says | 4217 extension, albeit a common and useful one; the C standard says |
3743 *slot = t; | 4338 *slot = t; |
3744 | 4339 |
3745 return -1; | 4340 return -1; |
3746 } | 4341 } |
3747 | 4342 |
3748 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where the | 4343 /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where |
3749 second parameter indicates which OPERATOR is being applied. The COMPLAIN | 4344 the second parameter indicates which OPERATOR is being applied. |
3750 flag controls whether we should diagnose possibly ill-formed | 4345 The COMPLAIN flag controls whether we should diagnose possibly |
3751 constructs or not. */ | 4346 ill-formed constructs or not. LOC is the location of the SIZEOF or |
4347 TYPEOF operator. */ | |
3752 | 4348 |
3753 tree | 4349 tree |
3754 c_sizeof_or_alignof_type (tree type, bool is_sizeof, int complain) | 4350 c_sizeof_or_alignof_type (location_t loc, |
4351 tree type, bool is_sizeof, int complain) | |
3755 { | 4352 { |
3756 const char *op_name; | 4353 const char *op_name; |
3757 tree value = NULL; | 4354 tree value = NULL; |
3758 enum tree_code type_code = TREE_CODE (type); | 4355 enum tree_code type_code = TREE_CODE (type); |
3759 | 4356 |
3762 if (type_code == FUNCTION_TYPE) | 4359 if (type_code == FUNCTION_TYPE) |
3763 { | 4360 { |
3764 if (is_sizeof) | 4361 if (is_sizeof) |
3765 { | 4362 { |
3766 if (complain && (pedantic || warn_pointer_arith)) | 4363 if (complain && (pedantic || warn_pointer_arith)) |
3767 pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, | 4364 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith, |
3768 "invalid application of %<sizeof%> to a function type"); | 4365 "invalid application of %<sizeof%> to a function type"); |
3769 else if (!complain) | 4366 else if (!complain) |
3770 return error_mark_node; | 4367 return error_mark_node; |
3771 value = size_one_node; | 4368 value = size_one_node; |
3772 } | 4369 } |
3775 } | 4372 } |
3776 else if (type_code == VOID_TYPE || type_code == ERROR_MARK) | 4373 else if (type_code == VOID_TYPE || type_code == ERROR_MARK) |
3777 { | 4374 { |
3778 if (type_code == VOID_TYPE | 4375 if (type_code == VOID_TYPE |
3779 && complain && (pedantic || warn_pointer_arith)) | 4376 && complain && (pedantic || warn_pointer_arith)) |
3780 pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, | 4377 pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith, |
3781 "invalid application of %qs to a void type", op_name); | 4378 "invalid application of %qs to a void type", op_name); |
3782 else if (!complain) | 4379 else if (!complain) |
3783 return error_mark_node; | 4380 return error_mark_node; |
3784 value = size_one_node; | 4381 value = size_one_node; |
3785 } | 4382 } |
3786 else if (!COMPLETE_TYPE_P (type)) | 4383 else if (!COMPLETE_TYPE_P (type)) |
3787 { | 4384 { |
3788 if (complain) | 4385 if (complain) |
3789 error ("invalid application of %qs to incomplete type %qT ", | 4386 error_at (loc, "invalid application of %qs to incomplete type %qT ", |
3790 op_name, type); | 4387 op_name, type); |
3791 value = size_zero_node; | 4388 value = size_zero_node; |
3792 } | 4389 } |
3793 else | 4390 else |
3794 { | 4391 { |
3795 if (is_sizeof) | 4392 if (is_sizeof) |
3796 /* Convert in case a char is more than one unit. */ | 4393 /* Convert in case a char is more than one unit. */ |
3797 value = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type), | 4394 value = size_binop_loc (loc, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type), |
3798 size_int (TYPE_PRECISION (char_type_node) | 4395 size_int (TYPE_PRECISION (char_type_node) |
3799 / BITS_PER_UNIT)); | 4396 / BITS_PER_UNIT)); |
3800 else | 4397 else |
3801 value = size_int (TYPE_ALIGN_UNIT (type)); | 4398 value = size_int (TYPE_ALIGN_UNIT (type)); |
3802 } | 4399 } |
3803 | 4400 |
3804 /* VALUE will have an integer type with TYPE_IS_SIZETYPE set. | 4401 /* VALUE will have an integer type with TYPE_IS_SIZETYPE set. |
3805 TYPE_IS_SIZETYPE means that certain things (like overflow) will | 4402 TYPE_IS_SIZETYPE means that certain things (like overflow) will |
3806 never happen. However, this node should really have type | 4403 never happen. However, this node should really have type |
3807 `size_t', which is just a typedef for an ordinary integer type. */ | 4404 `size_t', which is just a typedef for an ordinary integer type. */ |
3808 value = fold_convert (size_type_node, value); | 4405 value = fold_convert_loc (loc, size_type_node, value); |
3809 gcc_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value))); | 4406 gcc_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value))); |
3810 | 4407 |
3811 return value; | 4408 return value; |
3812 } | 4409 } |
3813 | 4410 |
3814 /* Implement the __alignof keyword: Return the minimum required | 4411 /* Implement the __alignof keyword: Return the minimum required |
3815 alignment of EXPR, measured in bytes. For VAR_DECLs, | 4412 alignment of EXPR, measured in bytes. For VAR_DECLs, |
3816 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set | 4413 FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set |
3817 from an "aligned" __attribute__ specification). */ | 4414 from an "aligned" __attribute__ specification). LOC is the |
4415 location of the ALIGNOF operator. */ | |
3818 | 4416 |
3819 tree | 4417 tree |
3820 c_alignof_expr (tree expr) | 4418 c_alignof_expr (location_t loc, tree expr) |
3821 { | 4419 { |
3822 tree t; | 4420 tree t; |
3823 | 4421 |
3824 if (VAR_OR_FUNCTION_DECL_P (expr)) | 4422 if (VAR_OR_FUNCTION_DECL_P (expr)) |
3825 t = size_int (DECL_ALIGN_UNIT (expr)); | 4423 t = size_int (DECL_ALIGN_UNIT (expr)); |
3826 | 4424 |
3827 else if (TREE_CODE (expr) == COMPONENT_REF | 4425 else if (TREE_CODE (expr) == COMPONENT_REF |
3828 && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1))) | 4426 && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1))) |
3829 { | 4427 { |
3830 error ("%<__alignof%> applied to a bit-field"); | 4428 error_at (loc, "%<__alignof%> applied to a bit-field"); |
3831 t = size_one_node; | 4429 t = size_one_node; |
3832 } | 4430 } |
3833 else if (TREE_CODE (expr) == COMPONENT_REF | 4431 else if (TREE_CODE (expr) == COMPONENT_REF |
3834 && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL) | 4432 && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL) |
3835 t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1))); | 4433 t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1))); |
3848 t = TREE_OPERAND (t, 0); | 4446 t = TREE_OPERAND (t, 0); |
3849 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); | 4447 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); |
3850 if (thisalign > bestalign) | 4448 if (thisalign > bestalign) |
3851 best = t, bestalign = thisalign; | 4449 best = t, bestalign = thisalign; |
3852 } | 4450 } |
3853 return c_alignof (TREE_TYPE (TREE_TYPE (best))); | 4451 return c_alignof (loc, TREE_TYPE (TREE_TYPE (best))); |
3854 } | 4452 } |
3855 else | 4453 else |
3856 return c_alignof (TREE_TYPE (expr)); | 4454 return c_alignof (loc, TREE_TYPE (expr)); |
3857 | 4455 |
3858 return fold_convert (size_type_node, t); | 4456 return fold_convert_loc (loc, size_type_node, t); |
3859 } | 4457 } |
3860 | 4458 |
3861 /* Handle C and C++ default attributes. */ | 4459 /* Handle C and C++ default attributes. */ |
3862 | 4460 |
3863 enum built_in_attribute | 4461 enum built_in_attribute |
4041 | 4639 |
4042 if (flag_mudflap) | 4640 if (flag_mudflap) |
4043 mudflap_init (); | 4641 mudflap_init (); |
4044 } | 4642 } |
4045 | 4643 |
4644 /* Like get_identifier, but avoid warnings about null arguments when | |
4645 the argument may be NULL for targets where GCC lacks stdint.h type | |
4646 information. */ | |
4647 | |
4648 static inline tree | |
4649 c_get_ident (const char *id) | |
4650 { | |
4651 return get_identifier (id); | |
4652 } | |
4653 | |
4046 /* Build tree nodes and builtin functions common to both C and C++ language | 4654 /* Build tree nodes and builtin functions common to both C and C++ language |
4047 frontends. */ | 4655 frontends. */ |
4048 | 4656 |
4049 void | 4657 void |
4050 c_common_nodes_and_builtins (void) | 4658 c_common_nodes_and_builtins (void) |
4089 record_builtin_type (RID_MAX, "signed char", signed_char_type_node); | 4697 record_builtin_type (RID_MAX, "signed char", signed_char_type_node); |
4090 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); | 4698 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); |
4091 | 4699 |
4092 /* These are types that c_common_type_for_size and | 4700 /* These are types that c_common_type_for_size and |
4093 c_common_type_for_mode use. */ | 4701 c_common_type_for_mode use. */ |
4094 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4702 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4703 TYPE_DECL, NULL_TREE, | |
4095 intQI_type_node)); | 4704 intQI_type_node)); |
4096 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4705 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4706 TYPE_DECL, NULL_TREE, | |
4097 intHI_type_node)); | 4707 intHI_type_node)); |
4098 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4708 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4709 TYPE_DECL, NULL_TREE, | |
4099 intSI_type_node)); | 4710 intSI_type_node)); |
4100 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4711 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4712 TYPE_DECL, NULL_TREE, | |
4101 intDI_type_node)); | 4713 intDI_type_node)); |
4102 #if HOST_BITS_PER_WIDE_INT >= 64 | 4714 #if HOST_BITS_PER_WIDE_INT >= 64 |
4103 if (targetm.scalar_mode_supported_p (TImode)) | 4715 if (targetm.scalar_mode_supported_p (TImode)) |
4104 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, | 4716 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4717 TYPE_DECL, | |
4105 get_identifier ("__int128_t"), | 4718 get_identifier ("__int128_t"), |
4106 intTI_type_node)); | 4719 intTI_type_node)); |
4107 #endif | 4720 #endif |
4108 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4721 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4722 TYPE_DECL, NULL_TREE, | |
4109 unsigned_intQI_type_node)); | 4723 unsigned_intQI_type_node)); |
4110 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4724 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4725 TYPE_DECL, NULL_TREE, | |
4111 unsigned_intHI_type_node)); | 4726 unsigned_intHI_type_node)); |
4112 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4727 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4728 TYPE_DECL, NULL_TREE, | |
4113 unsigned_intSI_type_node)); | 4729 unsigned_intSI_type_node)); |
4114 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4730 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4731 TYPE_DECL, NULL_TREE, | |
4115 unsigned_intDI_type_node)); | 4732 unsigned_intDI_type_node)); |
4116 #if HOST_BITS_PER_WIDE_INT >= 64 | 4733 #if HOST_BITS_PER_WIDE_INT >= 64 |
4117 if (targetm.scalar_mode_supported_p (TImode)) | 4734 if (targetm.scalar_mode_supported_p (TImode)) |
4118 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, | 4735 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4736 TYPE_DECL, | |
4119 get_identifier ("__uint128_t"), | 4737 get_identifier ("__uint128_t"), |
4120 unsigned_intTI_type_node)); | 4738 unsigned_intTI_type_node)); |
4121 #endif | 4739 #endif |
4122 | 4740 |
4123 /* Create the widest literal types. */ | 4741 /* Create the widest literal types. */ |
4124 widest_integer_literal_type_node | 4742 widest_integer_literal_type_node |
4125 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2); | 4743 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2); |
4126 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4744 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4745 TYPE_DECL, NULL_TREE, | |
4127 widest_integer_literal_type_node)); | 4746 widest_integer_literal_type_node)); |
4128 | 4747 |
4129 widest_unsigned_literal_type_node | 4748 widest_unsigned_literal_type_node |
4130 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2); | 4749 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2); |
4131 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, NULL_TREE, | 4750 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4751 TYPE_DECL, NULL_TREE, | |
4132 widest_unsigned_literal_type_node)); | 4752 widest_unsigned_literal_type_node)); |
4133 | 4753 |
4134 /* `unsigned long' is the standard type for sizeof. | 4754 /* `unsigned long' is the standard type for sizeof. |
4135 Note that stddef.h uses `unsigned long', | 4755 Note that stddef.h uses `unsigned long', |
4136 and this must agree, even if long and int are the same size. */ | 4756 and this must agree, even if long and int are the same size. */ |
4148 record_builtin_type (RID_DOUBLE, NULL, double_type_node); | 4768 record_builtin_type (RID_DOUBLE, NULL, double_type_node); |
4149 record_builtin_type (RID_MAX, "long double", long_double_type_node); | 4769 record_builtin_type (RID_MAX, "long double", long_double_type_node); |
4150 | 4770 |
4151 /* Only supported decimal floating point extension if the target | 4771 /* Only supported decimal floating point extension if the target |
4152 actually supports underlying modes. */ | 4772 actually supports underlying modes. */ |
4153 if (targetm.scalar_mode_supported_p (SDmode) | 4773 if (targetm.scalar_mode_supported_p (SDmode) |
4154 && targetm.scalar_mode_supported_p (DDmode) | 4774 && targetm.scalar_mode_supported_p (DDmode) |
4155 && targetm.scalar_mode_supported_p (TDmode)) | 4775 && targetm.scalar_mode_supported_p (TDmode)) |
4156 { | 4776 { |
4157 record_builtin_type (RID_DFLOAT32, NULL, dfloat32_type_node); | 4777 record_builtin_type (RID_DFLOAT32, NULL, dfloat32_type_node); |
4158 record_builtin_type (RID_DFLOAT64, NULL, dfloat64_type_node); | 4778 record_builtin_type (RID_DFLOAT64, NULL, dfloat64_type_node); |
4218 record_builtin_type (RID_MAX, "_Sat unsigned long long _Accum", | 4838 record_builtin_type (RID_MAX, "_Sat unsigned long long _Accum", |
4219 sat_unsigned_long_long_accum_type_node); | 4839 sat_unsigned_long_long_accum_type_node); |
4220 | 4840 |
4221 } | 4841 } |
4222 | 4842 |
4223 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, | 4843 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4844 TYPE_DECL, | |
4224 get_identifier ("complex int"), | 4845 get_identifier ("complex int"), |
4225 complex_integer_type_node)); | 4846 complex_integer_type_node)); |
4226 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, | 4847 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4848 TYPE_DECL, | |
4227 get_identifier ("complex float"), | 4849 get_identifier ("complex float"), |
4228 complex_float_type_node)); | 4850 complex_float_type_node)); |
4229 lang_hooks.decls.pushdecl (build_decl (TYPE_DECL, | 4851 lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION, |
4852 TYPE_DECL, | |
4230 get_identifier ("complex double"), | 4853 get_identifier ("complex double"), |
4231 complex_double_type_node)); | 4854 complex_double_type_node)); |
4232 lang_hooks.decls.pushdecl | 4855 lang_hooks.decls.pushdecl |
4233 (build_decl (TYPE_DECL, get_identifier ("complex long double"), | 4856 (build_decl (UNKNOWN_LOCATION, |
4857 TYPE_DECL, get_identifier ("complex long double"), | |
4234 complex_long_double_type_node)); | 4858 complex_long_double_type_node)); |
4235 | 4859 |
4236 if (c_dialect_cxx ()) | 4860 if (c_dialect_cxx ()) |
4237 /* For C++, make fileptr_type_node a distinct void * type until | 4861 /* For C++, make fileptr_type_node a distinct void * type until |
4238 FILE type is defined. */ | 4862 FILE type is defined. */ |
4280 | 4904 |
4281 /* This is special for C++ so functions can be overloaded. */ | 4905 /* This is special for C++ so functions can be overloaded. */ |
4282 wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE); | 4906 wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE); |
4283 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node)); | 4907 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node)); |
4284 wchar_type_size = TYPE_PRECISION (wchar_type_node); | 4908 wchar_type_size = TYPE_PRECISION (wchar_type_node); |
4909 underlying_wchar_type_node = wchar_type_node; | |
4285 if (c_dialect_cxx ()) | 4910 if (c_dialect_cxx ()) |
4286 { | 4911 { |
4287 if (TYPE_UNSIGNED (wchar_type_node)) | 4912 if (TYPE_UNSIGNED (wchar_type_node)) |
4288 wchar_type_node = make_unsigned_type (wchar_type_size); | 4913 wchar_type_node = make_unsigned_type (wchar_type_size); |
4289 else | 4914 else |
4290 wchar_type_node = make_signed_type (wchar_type_size); | 4915 wchar_type_node = make_signed_type (wchar_type_size); |
4291 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node); | 4916 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node); |
4292 } | 4917 } |
4293 else | |
4294 { | |
4295 signed_wchar_type_node = c_common_signed_type (wchar_type_node); | |
4296 unsigned_wchar_type_node = c_common_unsigned_type (wchar_type_node); | |
4297 } | |
4298 | 4918 |
4299 /* This is for wide string constants. */ | 4919 /* This is for wide string constants. */ |
4300 wchar_array_type_node | 4920 wchar_array_type_node |
4301 = build_array_type (wchar_type_node, array_domain_type); | 4921 = build_array_type (wchar_type_node, array_domain_type); |
4302 | 4922 |
4338 intmax_type_node = | 4958 intmax_type_node = |
4339 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE))); | 4959 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE))); |
4340 uintmax_type_node = | 4960 uintmax_type_node = |
4341 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE))); | 4961 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE))); |
4342 | 4962 |
4963 if (SIG_ATOMIC_TYPE) | |
4964 sig_atomic_type_node = | |
4965 TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE))); | |
4966 if (INT8_TYPE) | |
4967 int8_type_node = | |
4968 TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE))); | |
4969 if (INT16_TYPE) | |
4970 int16_type_node = | |
4971 TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE))); | |
4972 if (INT32_TYPE) | |
4973 int32_type_node = | |
4974 TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE))); | |
4975 if (INT64_TYPE) | |
4976 int64_type_node = | |
4977 TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE))); | |
4978 if (UINT8_TYPE) | |
4979 uint8_type_node = | |
4980 TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE))); | |
4981 if (UINT16_TYPE) | |
4982 uint16_type_node = | |
4983 TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE))); | |
4984 if (UINT32_TYPE) | |
4985 c_uint32_type_node = | |
4986 TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE))); | |
4987 if (UINT64_TYPE) | |
4988 c_uint64_type_node = | |
4989 TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE))); | |
4990 if (INT_LEAST8_TYPE) | |
4991 int_least8_type_node = | |
4992 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE))); | |
4993 if (INT_LEAST16_TYPE) | |
4994 int_least16_type_node = | |
4995 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE))); | |
4996 if (INT_LEAST32_TYPE) | |
4997 int_least32_type_node = | |
4998 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE))); | |
4999 if (INT_LEAST64_TYPE) | |
5000 int_least64_type_node = | |
5001 TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE))); | |
5002 if (UINT_LEAST8_TYPE) | |
5003 uint_least8_type_node = | |
5004 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE))); | |
5005 if (UINT_LEAST16_TYPE) | |
5006 uint_least16_type_node = | |
5007 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE))); | |
5008 if (UINT_LEAST32_TYPE) | |
5009 uint_least32_type_node = | |
5010 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE))); | |
5011 if (UINT_LEAST64_TYPE) | |
5012 uint_least64_type_node = | |
5013 TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE))); | |
5014 if (INT_FAST8_TYPE) | |
5015 int_fast8_type_node = | |
5016 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE))); | |
5017 if (INT_FAST16_TYPE) | |
5018 int_fast16_type_node = | |
5019 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE))); | |
5020 if (INT_FAST32_TYPE) | |
5021 int_fast32_type_node = | |
5022 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE))); | |
5023 if (INT_FAST64_TYPE) | |
5024 int_fast64_type_node = | |
5025 TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE))); | |
5026 if (UINT_FAST8_TYPE) | |
5027 uint_fast8_type_node = | |
5028 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE))); | |
5029 if (UINT_FAST16_TYPE) | |
5030 uint_fast16_type_node = | |
5031 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE))); | |
5032 if (UINT_FAST32_TYPE) | |
5033 uint_fast32_type_node = | |
5034 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE))); | |
5035 if (UINT_FAST64_TYPE) | |
5036 uint_fast64_type_node = | |
5037 TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE))); | |
5038 if (INTPTR_TYPE) | |
5039 intptr_type_node = | |
5040 TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE))); | |
5041 if (UINTPTR_TYPE) | |
5042 uintptr_type_node = | |
5043 TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE))); | |
5044 | |
4343 default_function_type = build_function_type (integer_type_node, NULL_TREE); | 5045 default_function_type = build_function_type (integer_type_node, NULL_TREE); |
4344 ptrdiff_type_node | 5046 ptrdiff_type_node |
4345 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE))); | 5047 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE))); |
4346 unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node); | 5048 unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node); |
4347 | 5049 |
4348 lang_hooks.decls.pushdecl | 5050 lang_hooks.decls.pushdecl |
4349 (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"), | 5051 (build_decl (UNKNOWN_LOCATION, |
5052 TYPE_DECL, get_identifier ("__builtin_va_list"), | |
4350 va_list_type_node)); | 5053 va_list_type_node)); |
4351 #ifdef TARGET_ENUM_VA_LIST | 5054 #ifdef TARGET_ENUM_VA_LIST |
4352 { | 5055 { |
4353 int l; | 5056 int l; |
4354 const char *pname; | 5057 const char *pname; |
4355 tree ptype; | 5058 tree ptype; |
4356 for (l = 0; TARGET_ENUM_VA_LIST (l, &pname, &ptype); ++l) | 5059 for (l = 0; TARGET_ENUM_VA_LIST (l, &pname, &ptype); ++l) |
4357 { | 5060 { |
4358 lang_hooks.decls.pushdecl | 5061 lang_hooks.decls.pushdecl |
4359 (build_decl (TYPE_DECL, get_identifier (pname), | 5062 (build_decl (UNKNOWN_LOCATION, |
5063 TYPE_DECL, get_identifier (pname), | |
4360 ptype)); | 5064 ptype)); |
4361 | 5065 |
4362 } | 5066 } |
4363 } | 5067 } |
4364 #endif | 5068 #endif |
4384 null_node = make_node (INTEGER_CST); | 5088 null_node = make_node (INTEGER_CST); |
4385 TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0); | 5089 TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0); |
4386 | 5090 |
4387 /* Since builtin_types isn't gc'ed, don't export these nodes. */ | 5091 /* Since builtin_types isn't gc'ed, don't export these nodes. */ |
4388 memset (builtin_types, 0, sizeof (builtin_types)); | 5092 memset (builtin_types, 0, sizeof (builtin_types)); |
4389 } | |
4390 | |
4391 /* Look up the function in built_in_decls that corresponds to DECL | |
4392 and set ASMSPEC as its user assembler name. DECL must be a | |
4393 function decl that declares a builtin. */ | |
4394 | |
4395 void | |
4396 set_builtin_user_assembler_name (tree decl, const char *asmspec) | |
4397 { | |
4398 tree builtin; | |
4399 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL | |
4400 && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL | |
4401 && asmspec != 0); | |
4402 | |
4403 builtin = built_in_decls [DECL_FUNCTION_CODE (decl)]; | |
4404 set_user_assembler_name (builtin, asmspec); | |
4405 switch (DECL_FUNCTION_CODE (decl)) | |
4406 { | |
4407 case BUILT_IN_MEMCPY: | |
4408 init_block_move_fn (asmspec); | |
4409 memcpy_libfunc = set_user_assembler_libfunc ("memcpy", asmspec); | |
4410 break; | |
4411 case BUILT_IN_MEMSET: | |
4412 init_block_clear_fn (asmspec); | |
4413 memset_libfunc = set_user_assembler_libfunc ("memset", asmspec); | |
4414 break; | |
4415 case BUILT_IN_MEMMOVE: | |
4416 memmove_libfunc = set_user_assembler_libfunc ("memmove", asmspec); | |
4417 break; | |
4418 case BUILT_IN_MEMCMP: | |
4419 memcmp_libfunc = set_user_assembler_libfunc ("memcmp", asmspec); | |
4420 break; | |
4421 case BUILT_IN_ABORT: | |
4422 abort_libfunc = set_user_assembler_libfunc ("abort", asmspec); | |
4423 break; | |
4424 default: | |
4425 break; | |
4426 } | |
4427 } | 5093 } |
4428 | 5094 |
4429 /* The number of named compound-literals generated thus far. */ | 5095 /* The number of named compound-literals generated thus far. */ |
4430 static GTY(()) int compound_literal_number; | 5096 static GTY(()) int compound_literal_number; |
4431 | 5097 |
4440 compound_literal_number++; | 5106 compound_literal_number++; |
4441 DECL_NAME (decl) = get_identifier (name); | 5107 DECL_NAME (decl) = get_identifier (name); |
4442 } | 5108 } |
4443 | 5109 |
4444 tree | 5110 tree |
4445 build_va_arg (tree expr, tree type) | 5111 build_va_arg (location_t loc, tree expr, tree type) |
4446 { | 5112 { |
4447 return build1 (VA_ARG_EXPR, type, expr); | 5113 expr = build1 (VA_ARG_EXPR, type, expr); |
5114 SET_EXPR_LOCATION (expr, loc); | |
5115 return expr; | |
4448 } | 5116 } |
4449 | 5117 |
4450 | 5118 |
4451 /* Linked list of disabled built-in functions. */ | 5119 /* Linked list of disabled built-in functions. */ |
4452 | 5120 |
4624 return k1 ? 1 : 0; | 5292 return k1 ? 1 : 0; |
4625 | 5293 |
4626 return tree_int_cst_compare ((tree) k1, (tree) k2); | 5294 return tree_int_cst_compare ((tree) k1, (tree) k2); |
4627 } | 5295 } |
4628 | 5296 |
4629 /* Process a case label for the range LOW_VALUE ... HIGH_VALUE. If | 5297 /* Process a case label, located at LOC, for the range LOW_VALUE |
4630 LOW_VALUE and HIGH_VALUE are both NULL_TREE then this case label is | 5298 ... HIGH_VALUE. If LOW_VALUE and HIGH_VALUE are both NULL_TREE |
4631 actually a `default' label. If only HIGH_VALUE is NULL_TREE, then | 5299 then this case label is actually a `default' label. If only |
4632 case label was declared using the usual C/C++ syntax, rather than | 5300 HIGH_VALUE is NULL_TREE, then case label was declared using the |
4633 the GNU case range extension. CASES is a tree containing all the | 5301 usual C/C++ syntax, rather than the GNU case range extension. |
4634 case ranges processed so far; COND is the condition for the | 5302 CASES is a tree containing all the case ranges processed so far; |
4635 switch-statement itself. Returns the CASE_LABEL_EXPR created, or | 5303 COND is the condition for the switch-statement itself. Returns the |
4636 ERROR_MARK_NODE if no CASE_LABEL_EXPR is created. */ | 5304 CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no CASE_LABEL_EXPR |
5305 is created. */ | |
4637 | 5306 |
4638 tree | 5307 tree |
4639 c_add_case_label (splay_tree cases, tree cond, tree orig_type, | 5308 c_add_case_label (location_t loc, splay_tree cases, tree cond, tree orig_type, |
4640 tree low_value, tree high_value) | 5309 tree low_value, tree high_value) |
4641 { | 5310 { |
4642 tree type; | 5311 tree type; |
4643 tree label; | 5312 tree label; |
4644 tree case_label; | 5313 tree case_label; |
4645 splay_tree_node node; | 5314 splay_tree_node node; |
4646 | 5315 |
4647 /* Create the LABEL_DECL itself. */ | 5316 /* Create the LABEL_DECL itself. */ |
4648 label = create_artificial_label (); | 5317 label = create_artificial_label (loc); |
4649 | 5318 |
4650 /* If there was an error processing the switch condition, bail now | 5319 /* If there was an error processing the switch condition, bail now |
4651 before we get more confused. */ | 5320 before we get more confused. */ |
4652 if (!cond || cond == error_mark_node) | 5321 if (!cond || cond == error_mark_node) |
4653 goto error_out; | 5322 goto error_out; |
4655 if ((low_value && TREE_TYPE (low_value) | 5324 if ((low_value && TREE_TYPE (low_value) |
4656 && POINTER_TYPE_P (TREE_TYPE (low_value))) | 5325 && POINTER_TYPE_P (TREE_TYPE (low_value))) |
4657 || (high_value && TREE_TYPE (high_value) | 5326 || (high_value && TREE_TYPE (high_value) |
4658 && POINTER_TYPE_P (TREE_TYPE (high_value)))) | 5327 && POINTER_TYPE_P (TREE_TYPE (high_value)))) |
4659 { | 5328 { |
4660 error ("pointers are not permitted as case values"); | 5329 error_at (loc, "pointers are not permitted as case values"); |
4661 goto error_out; | 5330 goto error_out; |
4662 } | 5331 } |
4663 | 5332 |
4664 /* Case ranges are a GNU extension. */ | 5333 /* Case ranges are a GNU extension. */ |
4665 if (high_value) | 5334 if (high_value) |
4666 pedwarn (input_location, OPT_pedantic, | 5335 pedwarn (loc, OPT_pedantic, |
4667 "range expressions in switch statements are non-standard"); | 5336 "range expressions in switch statements are non-standard"); |
4668 | 5337 |
4669 type = TREE_TYPE (cond); | 5338 type = TREE_TYPE (cond); |
4670 if (low_value) | 5339 if (low_value) |
4671 { | 5340 { |
4688 really a case range, even though it was written that way. | 5357 really a case range, even though it was written that way. |
4689 Remove the HIGH_VALUE to simplify later processing. */ | 5358 Remove the HIGH_VALUE to simplify later processing. */ |
4690 if (tree_int_cst_equal (low_value, high_value)) | 5359 if (tree_int_cst_equal (low_value, high_value)) |
4691 high_value = NULL_TREE; | 5360 high_value = NULL_TREE; |
4692 else if (!tree_int_cst_lt (low_value, high_value)) | 5361 else if (!tree_int_cst_lt (low_value, high_value)) |
4693 warning (0, "empty range specified"); | 5362 warning_at (loc, 0, "empty range specified"); |
4694 } | 5363 } |
4695 | 5364 |
4696 /* See if the case is in range of the type of the original testing | 5365 /* See if the case is in range of the type of the original testing |
4697 expression. If both low_value and high_value are out of range, | 5366 expression. If both low_value and high_value are out of range, |
4698 don't insert the case label and return NULL_TREE. */ | 5367 don't insert the case label and return NULL_TREE. */ |
4748 { | 5417 { |
4749 tree duplicate = CASE_LABEL ((tree) node->value); | 5418 tree duplicate = CASE_LABEL ((tree) node->value); |
4750 | 5419 |
4751 if (high_value) | 5420 if (high_value) |
4752 { | 5421 { |
4753 error ("duplicate (or overlapping) case value"); | 5422 error_at (loc, "duplicate (or overlapping) case value"); |
4754 error ("%Jthis is the first entry overlapping that value", duplicate); | 5423 error_at (DECL_SOURCE_LOCATION (duplicate), |
5424 "this is the first entry overlapping that value"); | |
4755 } | 5425 } |
4756 else if (low_value) | 5426 else if (low_value) |
4757 { | 5427 { |
4758 error ("duplicate case value") ; | 5428 error_at (loc, "duplicate case value") ; |
4759 error ("%Jpreviously used here", duplicate); | 5429 error_at (DECL_SOURCE_LOCATION (duplicate), "previously used here"); |
4760 } | 5430 } |
4761 else | 5431 else |
4762 { | 5432 { |
4763 error ("multiple default labels in one switch"); | 5433 error_at (loc, "multiple default labels in one switch"); |
4764 error ("%Jthis is the first default label", duplicate); | 5434 error_at (DECL_SOURCE_LOCATION (duplicate), |
5435 "this is the first default label"); | |
4765 } | 5436 } |
4766 goto error_out; | 5437 goto error_out; |
4767 } | 5438 } |
4768 | 5439 |
4769 /* Add a CASE_LABEL to the statement-tree. */ | 5440 /* Add a CASE_LABEL to the statement-tree. */ |
4770 case_label = add_stmt (build_case_label (low_value, high_value, label)); | 5441 case_label = add_stmt (build_case_label (loc, low_value, high_value, label)); |
4771 /* Register this case label in the splay tree. */ | 5442 /* Register this case label in the splay tree. */ |
4772 splay_tree_insert (cases, | 5443 splay_tree_insert (cases, |
4773 (splay_tree_key) low_value, | 5444 (splay_tree_key) low_value, |
4774 (splay_tree_value) case_label); | 5445 (splay_tree_value) case_label); |
4775 | 5446 |
4779 /* Add a label so that the back-end doesn't think that the beginning of | 5450 /* Add a label so that the back-end doesn't think that the beginning of |
4780 the switch is unreachable. Note that we do not add a case label, as | 5451 the switch is unreachable. Note that we do not add a case label, as |
4781 that just leads to duplicates and thence to failure later on. */ | 5452 that just leads to duplicates and thence to failure later on. */ |
4782 if (!cases->root) | 5453 if (!cases->root) |
4783 { | 5454 { |
4784 tree t = create_artificial_label (); | 5455 tree t = create_artificial_label (loc); |
4785 add_stmt (build_stmt (LABEL_EXPR, t)); | 5456 add_stmt (build_stmt (loc, LABEL_EXPR, t)); |
4786 } | 5457 } |
4787 return error_mark_node; | 5458 return error_mark_node; |
4788 } | 5459 } |
4789 | 5460 |
4790 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach. | 5461 /* Subroutines of c_do_switch_warnings, called via splay_tree_foreach. |
4809 snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_DOUBLE_HEX, | 5480 snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_DOUBLE_HEX, |
4810 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (key), | 5481 (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (key), |
4811 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (key)); | 5482 (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (key)); |
4812 | 5483 |
4813 if (TYPE_NAME (type) == 0) | 5484 if (TYPE_NAME (type) == 0) |
4814 warning (warn_switch ? OPT_Wswitch : OPT_Wswitch_enum, | 5485 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label)), |
4815 "%Jcase value %qs not in enumerated type", | 5486 warn_switch ? OPT_Wswitch : OPT_Wswitch_enum, |
4816 CASE_LABEL (label), buf); | 5487 "case value %qs not in enumerated type", |
5488 buf); | |
4817 else | 5489 else |
4818 warning (warn_switch ? OPT_Wswitch : OPT_Wswitch_enum, | 5490 warning_at (DECL_SOURCE_LOCATION (CASE_LABEL (label)), |
4819 "%Jcase value %qs not in enumerated type %qT", | 5491 warn_switch ? OPT_Wswitch : OPT_Wswitch_enum, |
4820 CASE_LABEL (label), buf, type); | 5492 "case value %qs not in enumerated type %qT", |
5493 buf, type); | |
4821 } | 5494 } |
4822 | 5495 |
4823 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach. | 5496 /* Subroutine of c_do_switch_warnings, called via splay_tree_foreach. |
4824 Used to verify that case values match up with enumerator values. */ | 5497 Used to verify that case values match up with enumerator values. */ |
4825 | 5498 |
4866 tree type, tree cond) | 5539 tree type, tree cond) |
4867 { | 5540 { |
4868 splay_tree_node default_node; | 5541 splay_tree_node default_node; |
4869 splay_tree_node node; | 5542 splay_tree_node node; |
4870 tree chain; | 5543 tree chain; |
4871 int saved_warn_switch; | |
4872 | 5544 |
4873 if (!warn_switch && !warn_switch_enum && !warn_switch_default) | 5545 if (!warn_switch && !warn_switch_enum && !warn_switch_default) |
4874 return; | 5546 return; |
4875 | 5547 |
4876 default_node = splay_tree_lookup (cases, (splay_tree_key) NULL); | 5548 default_node = splay_tree_lookup (cases, (splay_tree_key) NULL); |
4877 if (!default_node) | 5549 if (!default_node) |
4878 warning (OPT_Wswitch_default, "%Hswitch missing default case", | 5550 warning_at (switch_location, OPT_Wswitch_default, |
4879 &switch_location); | 5551 "switch missing default case"); |
4880 | 5552 |
4881 /* From here on, we only care about about enumerated types. */ | 5553 /* From here on, we only care about about enumerated types. */ |
4882 if (!type || TREE_CODE (type) != ENUMERAL_TYPE) | 5554 if (!type || TREE_CODE (type) != ENUMERAL_TYPE) |
4883 return; | 5555 return; |
4884 | 5556 |
4885 /* If the switch expression was an enumerated type, check that | 5557 /* From here on, we only care about -Wswitch and -Wswitch-enum. */ |
4886 exactly all enumeration literals are covered by the cases. | 5558 if (!warn_switch_enum && !warn_switch) |
4887 The check is made when -Wswitch was specified and there is no | |
4888 default case, or when -Wswitch-enum was specified. */ | |
4889 | |
4890 if (!warn_switch_enum | |
4891 && !(warn_switch && !default_node)) | |
4892 return; | 5559 return; |
5560 | |
5561 /* Check the cases. Warn about case values which are not members of | |
5562 the enumerated type. For -Wswitch-enum, or for -Wswitch when | |
5563 there is no default case, check that exactly all enumeration | |
5564 literals are covered by the cases. */ | |
4893 | 5565 |
4894 /* Clearing COND if it is not an integer constant simplifies | 5566 /* Clearing COND if it is not an integer constant simplifies |
4895 the tests inside the loop below. */ | 5567 the tests inside the loop below. */ |
4896 if (TREE_CODE (cond) != INTEGER_CST) | 5568 if (TREE_CODE (cond) != INTEGER_CST) |
4897 cond = NULL_TREE; | 5569 cond = NULL_TREE; |
4939 about whether that constant is handled by the switch. */ | 5611 about whether that constant is handled by the switch. */ |
4940 if (cond && tree_int_cst_compare (cond, value)) | 5612 if (cond && tree_int_cst_compare (cond, value)) |
4941 continue; | 5613 continue; |
4942 | 5614 |
4943 /* If there is a default_node, the only relevant option is | 5615 /* If there is a default_node, the only relevant option is |
4944 Wswitch-enum. Otherwise, if both are enabled then we prefer | 5616 Wswitch-enum. Otherwise, if both are enabled then we prefer |
4945 to warn using -Wswitch because -Wswitch is enabled by -Wall | 5617 to warn using -Wswitch because -Wswitch is enabled by -Wall |
4946 while -Wswitch-enum is explicit. */ | 5618 while -Wswitch-enum is explicit. */ |
4947 warning ((default_node || !warn_switch) | 5619 warning_at (switch_location, |
4948 ? OPT_Wswitch_enum : OPT_Wswitch, | 5620 (default_node || !warn_switch |
4949 "%Henumeration value %qE not handled in switch", | 5621 ? OPT_Wswitch_enum |
4950 &switch_location, TREE_PURPOSE (chain)); | 5622 : OPT_Wswitch), |
5623 "enumeration value %qE not handled in switch", | |
5624 TREE_PURPOSE (chain)); | |
4951 } | 5625 } |
4952 | 5626 |
4953 /* Warn if there are case expressions that don't correspond to | 5627 /* Warn if there are case expressions that don't correspond to |
4954 enumerators. This can occur since C and C++ don't enforce | 5628 enumerators. This can occur since C and C++ don't enforce |
4955 type-checking of assignments to enumeration variables. | 5629 type-checking of assignments to enumeration variables. |
4957 The time complexity here is now always O(N) worst case, since | 5631 The time complexity here is now always O(N) worst case, since |
4958 we should have marked both the lower bound and upper bound of | 5632 we should have marked both the lower bound and upper bound of |
4959 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN | 5633 every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN |
4960 above. This scan also resets those fields. */ | 5634 above. This scan also resets those fields. */ |
4961 | 5635 |
4962 /* If there is a default_node, the only relevant option is | |
4963 Wswitch-enum. Otherwise, if both are enabled then we prefer | |
4964 to warn using -Wswitch because -Wswitch is enabled by -Wall | |
4965 while -Wswitch-enum is explicit. */ | |
4966 saved_warn_switch = warn_switch; | |
4967 if (default_node) | |
4968 warn_switch = 0; | |
4969 splay_tree_foreach (cases, match_case_to_enum, type); | 5636 splay_tree_foreach (cases, match_case_to_enum, type); |
4970 warn_switch = saved_warn_switch; | |
4971 | |
4972 } | 5637 } |
4973 | 5638 |
4974 /* Finish an expression taking the address of LABEL (an | 5639 /* Finish an expression taking the address of LABEL (an |
4975 IDENTIFIER_NODE). Returns an expression for the address. | 5640 IDENTIFIER_NODE). Returns an expression for the address. |
4976 | 5641 |
4998 here could be used only in a diagnostic, for example. */ | 5663 here could be used only in a diagnostic, for example. */ |
4999 protected_set_expr_location (result, loc); | 5664 protected_set_expr_location (result, loc); |
5000 } | 5665 } |
5001 | 5666 |
5002 return result; | 5667 return result; |
5003 } | |
5004 | |
5005 /* Hook used by expand_expr to expand language-specific tree codes. */ | |
5006 /* The only things that should go here are bits needed to expand | |
5007 constant initializers. Everything else should be handled by the | |
5008 gimplification routines. */ | |
5009 | |
5010 rtx | |
5011 c_expand_expr (tree exp, rtx target, enum machine_mode tmode, | |
5012 int modifiera /* Actually enum expand_modifier. */, | |
5013 rtx *alt_rtl) | |
5014 { | |
5015 enum expand_modifier modifier = (enum expand_modifier) modifiera; | |
5016 switch (TREE_CODE (exp)) | |
5017 { | |
5018 case COMPOUND_LITERAL_EXPR: | |
5019 { | |
5020 /* Initialize the anonymous variable declared in the compound | |
5021 literal, then return the variable. */ | |
5022 tree decl = COMPOUND_LITERAL_EXPR_DECL (exp); | |
5023 emit_local_var (decl); | |
5024 return expand_expr_real (decl, target, tmode, modifier, alt_rtl); | |
5025 } | |
5026 | |
5027 default: | |
5028 gcc_unreachable (); | |
5029 } | |
5030 } | |
5031 | |
5032 /* Hook used by staticp to handle language-specific tree codes. */ | |
5033 | |
5034 tree | |
5035 c_staticp (tree exp) | |
5036 { | |
5037 return (TREE_CODE (exp) == COMPOUND_LITERAL_EXPR | |
5038 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)) | |
5039 ? exp : NULL); | |
5040 } | 5668 } |
5041 | 5669 |
5042 | 5670 |
5043 /* Given a boolean expression ARG, return a tree representing an increment | 5671 /* Given a boolean expression ARG, return a tree representing an increment |
5044 or decrement (as indicated by CODE) of ARG. The front end must check for | 5672 or decrement (as indicated by CODE) of ARG. The front end must check for |
5061 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg); | 5689 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg); |
5062 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val); | 5690 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val); |
5063 break; | 5691 break; |
5064 case PREDECREMENT_EXPR: | 5692 case PREDECREMENT_EXPR: |
5065 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, | 5693 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, |
5066 invert_truthvalue (arg)); | 5694 invert_truthvalue_loc (input_location, arg)); |
5067 break; | 5695 break; |
5068 case POSTDECREMENT_EXPR: | 5696 case POSTDECREMENT_EXPR: |
5069 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, | 5697 val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, |
5070 invert_truthvalue (arg)); | 5698 invert_truthvalue_loc (input_location, arg)); |
5071 arg = save_expr (arg); | 5699 arg = save_expr (arg); |
5072 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg); | 5700 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg); |
5073 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val); | 5701 val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val); |
5074 break; | 5702 break; |
5075 default: | 5703 default: |
5077 } | 5705 } |
5078 TREE_SIDE_EFFECTS (val) = 1; | 5706 TREE_SIDE_EFFECTS (val) = 1; |
5079 return val; | 5707 return val; |
5080 } | 5708 } |
5081 | 5709 |
5082 /* Built-in macros for stddef.h, that require macros defined in this | 5710 /* Built-in macros for stddef.h and stdint.h, that require macros |
5083 file. */ | 5711 defined in this file. */ |
5084 void | 5712 void |
5085 c_stddef_cpp_builtins(void) | 5713 c_stddef_cpp_builtins(void) |
5086 { | 5714 { |
5087 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0); | 5715 builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0); |
5088 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0); | 5716 builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0); |
5090 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0); | 5718 builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0); |
5091 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0); | 5719 builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0); |
5092 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0); | 5720 builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0); |
5093 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE, 0); | 5721 builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE, 0); |
5094 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE, 0); | 5722 builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE, 0); |
5723 if (SIG_ATOMIC_TYPE) | |
5724 builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE, 0); | |
5725 if (INT8_TYPE) | |
5726 builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE, 0); | |
5727 if (INT16_TYPE) | |
5728 builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE, 0); | |
5729 if (INT32_TYPE) | |
5730 builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE, 0); | |
5731 if (INT64_TYPE) | |
5732 builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE, 0); | |
5733 if (UINT8_TYPE) | |
5734 builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE, 0); | |
5735 if (UINT16_TYPE) | |
5736 builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE, 0); | |
5737 if (UINT32_TYPE) | |
5738 builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE, 0); | |
5739 if (UINT64_TYPE) | |
5740 builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE, 0); | |
5741 if (INT_LEAST8_TYPE) | |
5742 builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE, 0); | |
5743 if (INT_LEAST16_TYPE) | |
5744 builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE, 0); | |
5745 if (INT_LEAST32_TYPE) | |
5746 builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE, 0); | |
5747 if (INT_LEAST64_TYPE) | |
5748 builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE, 0); | |
5749 if (UINT_LEAST8_TYPE) | |
5750 builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE, 0); | |
5751 if (UINT_LEAST16_TYPE) | |
5752 builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE, 0); | |
5753 if (UINT_LEAST32_TYPE) | |
5754 builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE, 0); | |
5755 if (UINT_LEAST64_TYPE) | |
5756 builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE, 0); | |
5757 if (INT_FAST8_TYPE) | |
5758 builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE, 0); | |
5759 if (INT_FAST16_TYPE) | |
5760 builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE, 0); | |
5761 if (INT_FAST32_TYPE) | |
5762 builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE, 0); | |
5763 if (INT_FAST64_TYPE) | |
5764 builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE, 0); | |
5765 if (UINT_FAST8_TYPE) | |
5766 builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE, 0); | |
5767 if (UINT_FAST16_TYPE) | |
5768 builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE, 0); | |
5769 if (UINT_FAST32_TYPE) | |
5770 builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE, 0); | |
5771 if (UINT_FAST64_TYPE) | |
5772 builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE, 0); | |
5773 if (INTPTR_TYPE) | |
5774 builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE, 0); | |
5775 if (UINTPTR_TYPE) | |
5776 builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE, 0); | |
5095 } | 5777 } |
5096 | 5778 |
5097 static void | 5779 static void |
5098 c_init_attributes (void) | 5780 c_init_attributes (void) |
5099 { | 5781 { |
5289 } | 5971 } |
5290 | 5972 |
5291 return NULL_TREE; | 5973 return NULL_TREE; |
5292 } | 5974 } |
5293 | 5975 |
5976 /* Handle a "noclone" attribute; arguments as in | |
5977 struct attribute_spec.handler. */ | |
5978 | |
5979 static tree | |
5980 handle_noclone_attribute (tree *node, tree name, | |
5981 tree ARG_UNUSED (args), | |
5982 int ARG_UNUSED (flags), bool *no_add_attrs) | |
5983 { | |
5984 if (TREE_CODE (*node) != FUNCTION_DECL) | |
5985 { | |
5986 warning (OPT_Wattributes, "%qE attribute ignored", name); | |
5987 *no_add_attrs = true; | |
5988 } | |
5989 | |
5990 return NULL_TREE; | |
5991 } | |
5992 | |
5294 /* Handle a "always_inline" attribute; arguments as in | 5993 /* Handle a "always_inline" attribute; arguments as in |
5295 struct attribute_spec.handler. */ | 5994 struct attribute_spec.handler. */ |
5296 | 5995 |
5297 static tree | 5996 static tree |
5298 handle_always_inline_attribute (tree *node, tree name, | 5997 handle_always_inline_attribute (tree *node, tree name, |
5568 HOST_WIDE_INT pri; | 6267 HOST_WIDE_INT pri; |
5569 tree arg; | 6268 tree arg; |
5570 | 6269 |
5571 if (!args) | 6270 if (!args) |
5572 return DEFAULT_INIT_PRIORITY; | 6271 return DEFAULT_INIT_PRIORITY; |
5573 | 6272 |
5574 if (!SUPPORTS_INIT_PRIORITY) | 6273 if (!SUPPORTS_INIT_PRIORITY) |
5575 { | 6274 { |
5576 if (is_destructor) | 6275 if (is_destructor) |
5577 error ("destructor priorities are not supported"); | 6276 error ("destructor priorities are not supported"); |
5578 else | 6277 else |
5592 if (pri <= MAX_RESERVED_INIT_PRIORITY) | 6291 if (pri <= MAX_RESERVED_INIT_PRIORITY) |
5593 { | 6292 { |
5594 if (is_destructor) | 6293 if (is_destructor) |
5595 warning (0, | 6294 warning (0, |
5596 "destructor priorities from 0 to %d are reserved " | 6295 "destructor priorities from 0 to %d are reserved " |
5597 "for the implementation", | 6296 "for the implementation", |
5598 MAX_RESERVED_INIT_PRIORITY); | 6297 MAX_RESERVED_INIT_PRIORITY); |
5599 else | 6298 else |
5600 warning (0, | 6299 warning (0, |
5601 "constructor priorities from 0 to %d are reserved " | 6300 "constructor priorities from 0 to %d are reserved " |
5602 "for the implementation", | 6301 "for the implementation", |
5603 MAX_RESERVED_INIT_PRIORITY); | 6302 MAX_RESERVED_INIT_PRIORITY); |
5604 } | 6303 } |
5605 return pri; | 6304 return pri; |
5606 | 6305 |
5607 invalid: | 6306 invalid: |
5680 static tree | 6379 static tree |
5681 handle_mode_attribute (tree *node, tree name, tree args, | 6380 handle_mode_attribute (tree *node, tree name, tree args, |
5682 int ARG_UNUSED (flags), bool *no_add_attrs) | 6381 int ARG_UNUSED (flags), bool *no_add_attrs) |
5683 { | 6382 { |
5684 tree type = *node; | 6383 tree type = *node; |
6384 tree ident = TREE_VALUE (args); | |
5685 | 6385 |
5686 *no_add_attrs = true; | 6386 *no_add_attrs = true; |
5687 | 6387 |
5688 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE) | 6388 if (TREE_CODE (ident) != IDENTIFIER_NODE) |
5689 warning (OPT_Wattributes, "%qE attribute ignored", name); | 6389 warning (OPT_Wattributes, "%qE attribute ignored", name); |
5690 else | 6390 else |
5691 { | 6391 { |
5692 int j; | 6392 int j; |
5693 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args)); | 6393 const char *p = IDENTIFIER_POINTER (ident); |
5694 int len = strlen (p); | 6394 int len = strlen (p); |
5695 enum machine_mode mode = VOIDmode; | 6395 enum machine_mode mode = VOIDmode; |
5696 tree typefm; | 6396 tree typefm; |
5697 bool valid_mode; | 6397 bool valid_mode; |
5698 | 6398 |
5728 break; | 6428 break; |
5729 } | 6429 } |
5730 | 6430 |
5731 if (mode == VOIDmode) | 6431 if (mode == VOIDmode) |
5732 { | 6432 { |
5733 error ("unknown machine mode %qs", p); | 6433 error ("unknown machine mode %qE", ident); |
5734 return NULL_TREE; | 6434 return NULL_TREE; |
5735 } | 6435 } |
5736 | 6436 |
5737 valid_mode = false; | 6437 valid_mode = false; |
5738 switch (GET_MODE_CLASS (mode)) | 6438 switch (GET_MODE_CLASS (mode)) |
5775 return NULL_TREE; | 6475 return NULL_TREE; |
5776 } | 6476 } |
5777 | 6477 |
5778 if (POINTER_TYPE_P (type)) | 6478 if (POINTER_TYPE_P (type)) |
5779 { | 6479 { |
6480 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (type)); | |
5780 tree (*fn)(tree, enum machine_mode, bool); | 6481 tree (*fn)(tree, enum machine_mode, bool); |
5781 | 6482 |
5782 if (!targetm.valid_pointer_mode (mode)) | 6483 if (!targetm.addr_space.valid_pointer_mode (mode, as)) |
5783 { | 6484 { |
5784 error ("invalid pointer mode %qs", p); | 6485 error ("invalid pointer mode %qs", p); |
5785 return NULL_TREE; | 6486 return NULL_TREE; |
5786 } | 6487 } |
5787 | 6488 |
5875 { | 6576 { |
5876 if (TREE_CODE (decl) == VAR_DECL | 6577 if (TREE_CODE (decl) == VAR_DECL |
5877 && current_function_decl != NULL_TREE | 6578 && current_function_decl != NULL_TREE |
5878 && !TREE_STATIC (decl)) | 6579 && !TREE_STATIC (decl)) |
5879 { | 6580 { |
5880 error ("%Jsection attribute cannot be specified for " | 6581 error_at (DECL_SOURCE_LOCATION (decl), |
5881 "local variables", decl); | 6582 "section attribute cannot be specified for " |
6583 "local variables"); | |
5882 *no_add_attrs = true; | 6584 *no_add_attrs = true; |
5883 } | 6585 } |
5884 | 6586 |
5885 /* The decl may have already been given a section attribute | 6587 /* The decl may have already been given a section attribute |
5886 from a previous declaration. Ensure they match. */ | 6588 from a previous declaration. Ensure they match. */ |
5908 *no_add_attrs = true; | 6610 *no_add_attrs = true; |
5909 } | 6611 } |
5910 } | 6612 } |
5911 else | 6613 else |
5912 { | 6614 { |
5913 error ("%Jsection attributes are not supported for this target", *node); | 6615 error_at (DECL_SOURCE_LOCATION (*node), |
6616 "section attributes are not supported for this target"); | |
5914 *no_add_attrs = true; | 6617 *no_add_attrs = true; |
5915 } | 6618 } |
5916 | 6619 |
5917 return NULL_TREE; | 6620 return NULL_TREE; |
5918 } | 6621 } |
5948 else if ((i = tree_log2 (align_expr)) == -1) | 6651 else if ((i = tree_log2 (align_expr)) == -1) |
5949 { | 6652 { |
5950 error ("requested alignment is not a power of 2"); | 6653 error ("requested alignment is not a power of 2"); |
5951 *no_add_attrs = true; | 6654 *no_add_attrs = true; |
5952 } | 6655 } |
5953 else if (i > HOST_BITS_PER_INT - 2) | 6656 else if (i >= HOST_BITS_PER_INT - BITS_PER_UNIT_LOG) |
5954 { | 6657 { |
5955 error ("requested alignment is too large"); | 6658 error ("requested alignment is too large"); |
5956 *no_add_attrs = true; | 6659 *no_add_attrs = true; |
5957 } | 6660 } |
5958 else if (is_type) | 6661 else if (is_type) |
5970 TREE_TYPE (decl) = *type; | 6673 TREE_TYPE (decl) = *type; |
5971 } | 6674 } |
5972 else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) | 6675 else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) |
5973 *type = build_variant_type_copy (*type); | 6676 *type = build_variant_type_copy (*type); |
5974 | 6677 |
5975 TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT; | 6678 TYPE_ALIGN (*type) = (1U << i) * BITS_PER_UNIT; |
5976 TYPE_USER_ALIGN (*type) = 1; | 6679 TYPE_USER_ALIGN (*type) = 1; |
5977 } | 6680 } |
5978 else if (! VAR_OR_FUNCTION_DECL_P (decl) | 6681 else if (! VAR_OR_FUNCTION_DECL_P (decl) |
5979 && TREE_CODE (decl) != FIELD_DECL) | 6682 && TREE_CODE (decl) != FIELD_DECL) |
5980 { | 6683 { |
5981 error ("alignment may not be specified for %q+D", decl); | 6684 error ("alignment may not be specified for %q+D", decl); |
5982 *no_add_attrs = true; | 6685 *no_add_attrs = true; |
5983 } | 6686 } |
5984 else if (TREE_CODE (decl) == FUNCTION_DECL | 6687 else if (TREE_CODE (decl) == FUNCTION_DECL |
5985 && DECL_ALIGN (decl) > (1 << i) * BITS_PER_UNIT) | 6688 && DECL_ALIGN (decl) > (1U << i) * BITS_PER_UNIT) |
5986 { | 6689 { |
5987 if (DECL_USER_ALIGN (decl)) | 6690 if (DECL_USER_ALIGN (decl)) |
5988 error ("alignment for %q+D was previously specified as %d " | 6691 error ("alignment for %q+D was previously specified as %d " |
5989 "and may not be decreased", decl, | 6692 "and may not be decreased", decl, |
5990 DECL_ALIGN (decl) / BITS_PER_UNIT); | 6693 DECL_ALIGN (decl) / BITS_PER_UNIT); |
5993 DECL_ALIGN (decl) / BITS_PER_UNIT); | 6696 DECL_ALIGN (decl) / BITS_PER_UNIT); |
5994 *no_add_attrs = true; | 6697 *no_add_attrs = true; |
5995 } | 6698 } |
5996 else | 6699 else |
5997 { | 6700 { |
5998 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT; | 6701 DECL_ALIGN (decl) = (1U << i) * BITS_PER_UNIT; |
5999 DECL_USER_ALIGN (decl) = 1; | 6702 DECL_USER_ALIGN (decl) = 1; |
6000 } | 6703 } |
6001 | 6704 |
6002 return NULL_TREE; | 6705 return NULL_TREE; |
6003 } | 6706 } |
6039 { | 6742 { |
6040 warning (OPT_Wattributes, "%qE attribute ignored", name); | 6743 warning (OPT_Wattributes, "%qE attribute ignored", name); |
6041 *no_add_attrs = true; | 6744 *no_add_attrs = true; |
6042 } | 6745 } |
6043 else if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)) | 6746 else if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)) |
6044 || (TREE_CODE (decl) != FUNCTION_DECL | 6747 || (TREE_CODE (decl) != FUNCTION_DECL |
6045 && TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl)) | 6748 && TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl)) |
6046 /* A static variable declaration is always a tentative definition, | 6749 /* A static variable declaration is always a tentative definition, |
6047 but the alias is a non-tentative definition which overrides. */ | 6750 but the alias is a non-tentative definition which overrides. */ |
6048 || (TREE_CODE (decl) != FUNCTION_DECL | 6751 || (TREE_CODE (decl) != FUNCTION_DECL |
6049 && ! TREE_PUBLIC (decl) && DECL_INITIAL (decl))) | 6752 && ! TREE_PUBLIC (decl) && DECL_INITIAL (decl))) |
6050 { | 6753 { |
6051 error ("%q+D defined both normally and as an alias", decl); | 6754 error ("%q+D defined both normally and as an alias", decl); |
6052 *no_add_attrs = true; | 6755 *no_add_attrs = true; |
6053 } | 6756 } |
6127 decl_attributes (node, attr, flags); | 6830 decl_attributes (node, attr, flags); |
6128 } | 6831 } |
6129 else | 6832 else |
6130 { | 6833 { |
6131 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node))) | 6834 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node))) |
6132 error ("%Jweakref attribute must appear before alias attribute", | 6835 error_at (DECL_SOURCE_LOCATION (*node), |
6133 *node); | 6836 "weakref attribute must appear before alias attribute"); |
6134 | 6837 |
6135 /* Can't call declare_weak because it wants this to be TREE_PUBLIC, | 6838 /* Can't call declare_weak because it wants this to be TREE_PUBLIC, |
6136 and that isn't supported; and because it wants to add it to | 6839 and that isn't supported; and because it wants to add it to |
6137 the list of weak decls, which isn't helpful. */ | 6840 the list of weak decls, which isn't helpful. */ |
6138 DECL_WEAK (*node) = 1; | 6841 DECL_WEAK (*node) = 1; |
6338 { | 7041 { |
6339 tree decl = *node; | 7042 tree decl = *node; |
6340 | 7043 |
6341 if (TREE_CODE (decl) != FUNCTION_DECL) | 7044 if (TREE_CODE (decl) != FUNCTION_DECL) |
6342 { | 7045 { |
6343 error ("%J%qE attribute applies only to functions", decl, name); | 7046 error_at (DECL_SOURCE_LOCATION (decl), |
7047 "%qE attribute applies only to functions", name); | |
6344 *no_add_attrs = true; | 7048 *no_add_attrs = true; |
6345 } | 7049 } |
6346 else if (DECL_INITIAL (decl)) | 7050 else if (DECL_INITIAL (decl)) |
6347 { | 7051 { |
6348 error ("%Jcan%'t set %qE attribute after definition", decl, name); | 7052 error_at (DECL_SOURCE_LOCATION (decl), |
7053 "can%'t set %qE attribute after definition", name); | |
6349 *no_add_attrs = true; | 7054 *no_add_attrs = true; |
6350 } | 7055 } |
6351 else | 7056 else |
6352 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1; | 7057 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1; |
6353 | 7058 |
6384 for (; args; args = TREE_CHAIN (args)) | 7089 for (; args; args = TREE_CHAIN (args)) |
6385 { | 7090 { |
6386 tree position = TREE_VALUE (args); | 7091 tree position = TREE_VALUE (args); |
6387 | 7092 |
6388 if (TREE_CODE (position) != INTEGER_CST | 7093 if (TREE_CODE (position) != INTEGER_CST |
6389 || TREE_INT_CST_HIGH (position) | 7094 || TREE_INT_CST_HIGH (position) |
6390 || TREE_INT_CST_LOW (position) < 1 | 7095 || TREE_INT_CST_LOW (position) < 1 |
6391 || TREE_INT_CST_LOW (position) > arg_count ) | 7096 || TREE_INT_CST_LOW (position) > arg_count ) |
6392 { | 7097 { |
6393 warning (OPT_Wattributes, | 7098 warning (OPT_Wattributes, |
6394 "alloc_size parameter outside range"); | 7099 "alloc_size parameter outside range"); |
6395 *no_add_attrs = true; | 7100 *no_add_attrs = true; |
6396 return NULL_TREE; | 7101 return NULL_TREE; |
6397 } | 7102 } |
6398 } | 7103 } |
6428 { | 7133 { |
6429 tree decl = *node; | 7134 tree decl = *node; |
6430 | 7135 |
6431 if (TREE_CODE (decl) != FUNCTION_DECL) | 7136 if (TREE_CODE (decl) != FUNCTION_DECL) |
6432 { | 7137 { |
6433 error ("%J%qE attribute applies only to functions", decl, name); | 7138 error_at (DECL_SOURCE_LOCATION (decl), |
7139 "%qE attribute applies only to functions", name); | |
6434 *no_add_attrs = true; | 7140 *no_add_attrs = true; |
6435 } | 7141 } |
6436 else if (DECL_INITIAL (decl)) | 7142 else if (DECL_INITIAL (decl)) |
6437 { | 7143 { |
6438 error ("%Jcan%'t set %qE attribute after definition", decl, name); | 7144 error_at (DECL_SOURCE_LOCATION (decl), |
7145 "can%'t set %qE attribute after definition", name); | |
6439 *no_add_attrs = true; | 7146 *no_add_attrs = true; |
6440 } | 7147 } |
6441 else | 7148 else |
6442 DECL_NO_LIMIT_STACK (decl) = 1; | 7149 DECL_NO_LIMIT_STACK (decl) = 1; |
6443 | 7150 |
6479 /* Handle a "deprecated" attribute; arguments as in | 7186 /* Handle a "deprecated" attribute; arguments as in |
6480 struct attribute_spec.handler. */ | 7187 struct attribute_spec.handler. */ |
6481 | 7188 |
6482 static tree | 7189 static tree |
6483 handle_deprecated_attribute (tree *node, tree name, | 7190 handle_deprecated_attribute (tree *node, tree name, |
6484 tree ARG_UNUSED (args), int flags, | 7191 tree args, int flags, |
6485 bool *no_add_attrs) | 7192 bool *no_add_attrs) |
6486 { | 7193 { |
6487 tree type = NULL_TREE; | 7194 tree type = NULL_TREE; |
6488 int warn = 0; | 7195 int warn = 0; |
6489 tree what = NULL_TREE; | 7196 tree what = NULL_TREE; |
7197 | |
7198 if (!args) | |
7199 *no_add_attrs = true; | |
7200 else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST) | |
7201 { | |
7202 error ("deprecated message is not a string"); | |
7203 *no_add_attrs = true; | |
7204 } | |
6490 | 7205 |
6491 if (DECL_P (*node)) | 7206 if (DECL_P (*node)) |
6492 { | 7207 { |
6493 tree decl = *node; | 7208 tree decl = *node; |
6494 type = TREE_TYPE (decl); | 7209 type = TREE_TYPE (decl); |
6936 { | 7651 { |
6937 tree position = TREE_VALUE (args); | 7652 tree position = TREE_VALUE (args); |
6938 | 7653 |
6939 if (TREE_CODE (position) != INTEGER_CST) | 7654 if (TREE_CODE (position) != INTEGER_CST) |
6940 { | 7655 { |
6941 warning (OPT_Wattributes, | 7656 warning (OPT_Wattributes, |
6942 "requested position is not an integer constant"); | 7657 "requested position is not an integer constant"); |
6943 *no_add_attrs = true; | 7658 *no_add_attrs = true; |
6944 } | 7659 } |
6945 else | 7660 else |
6946 { | 7661 { |
6962 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name), | 7677 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name), |
6963 tree ARG_UNUSED (args), int ARG_UNUSED (flags), | 7678 tree ARG_UNUSED (args), int ARG_UNUSED (flags), |
6964 bool * ARG_UNUSED (no_add_attrs)) | 7679 bool * ARG_UNUSED (no_add_attrs)) |
6965 { | 7680 { |
6966 tree params; | 7681 tree params; |
6967 | 7682 |
6968 /* Ensure we have a function type. */ | 7683 /* Ensure we have a function type. */ |
6969 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE); | 7684 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE); |
6970 | 7685 |
6971 params = TYPE_ARG_TYPES (*node); | 7686 params = TYPE_ARG_TYPES (*node); |
6972 while (params && ! VOID_TYPE_P (TREE_VALUE (params))) | 7687 while (params && ! VOID_TYPE_P (TREE_VALUE (params))) |
6973 params = TREE_CHAIN (params); | 7688 params = TREE_CHAIN (params); |
6974 | 7689 |
6975 /* Ensure we have a variadic function. */ | 7690 /* Ensure we have a variadic function. */ |
7107 | 7822 |
7108 saved_flag_strict_aliasing = flag_strict_aliasing; | 7823 saved_flag_strict_aliasing = flag_strict_aliasing; |
7109 | 7824 |
7110 /* Now parse the options. */ | 7825 /* Now parse the options. */ |
7111 decode_options (opt_argc, opt_argv); | 7826 decode_options (opt_argc, opt_argv); |
7827 | |
7828 targetm.override_options_after_change(); | |
7112 | 7829 |
7113 /* Don't allow changing -fstrict-aliasing. */ | 7830 /* Don't allow changing -fstrict-aliasing. */ |
7114 flag_strict_aliasing = saved_flag_strict_aliasing; | 7831 flag_strict_aliasing = saved_flag_strict_aliasing; |
7115 | 7832 |
7116 VEC_truncate (const_char_p, optimize_args, 0); | 7833 VEC_truncate (const_char_p, optimize_args, 0); |
7335 | 8052 |
7336 case BUILT_IN_FPCLASSIFY: | 8053 case BUILT_IN_FPCLASSIFY: |
7337 if (validate_nargs (fndecl, nargs, 6)) | 8054 if (validate_nargs (fndecl, nargs, 6)) |
7338 { | 8055 { |
7339 unsigned i; | 8056 unsigned i; |
7340 | 8057 |
7341 for (i=0; i<5; i++) | 8058 for (i=0; i<5; i++) |
7342 if (TREE_CODE (args[i]) != INTEGER_CST) | 8059 if (TREE_CODE (args[i]) != INTEGER_CST) |
7343 { | 8060 { |
7344 error ("non-const integer argument %u in call to function %qE", | 8061 error ("non-const integer argument %u in call to function %qE", |
7345 i+1, fndecl); | 8062 i+1, fndecl); |
7447 | 8164 |
7448 /* Issue the error given by GMSGID, indicating that it occurred before | 8165 /* Issue the error given by GMSGID, indicating that it occurred before |
7449 TOKEN, which had the associated VALUE. */ | 8166 TOKEN, which had the associated VALUE. */ |
7450 | 8167 |
7451 void | 8168 void |
7452 c_parse_error (const char *gmsgid, enum cpp_ttype token, tree value) | 8169 c_parse_error (const char *gmsgid, enum cpp_ttype token_type, |
8170 tree value, unsigned char token_flags) | |
7453 { | 8171 { |
7454 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2)) | 8172 #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2)) |
7455 | 8173 |
7456 char *message = NULL; | 8174 char *message = NULL; |
7457 | 8175 |
7458 if (token == CPP_EOF) | 8176 if (token_type == CPP_EOF) |
7459 message = catenate_messages (gmsgid, " at end of input"); | 8177 message = catenate_messages (gmsgid, " at end of input"); |
7460 else if (token == CPP_CHAR || token == CPP_WCHAR || token == CPP_CHAR16 | 8178 else if (token_type == CPP_CHAR |
7461 || token == CPP_CHAR32) | 8179 || token_type == CPP_WCHAR |
8180 || token_type == CPP_CHAR16 | |
8181 || token_type == CPP_CHAR32) | |
7462 { | 8182 { |
7463 unsigned int val = TREE_INT_CST_LOW (value); | 8183 unsigned int val = TREE_INT_CST_LOW (value); |
7464 const char *prefix; | 8184 const char *prefix; |
7465 | 8185 |
7466 switch (token) | 8186 switch (token_type) |
7467 { | 8187 { |
7468 default: | 8188 default: |
7469 prefix = ""; | 8189 prefix = ""; |
7470 break; | 8190 break; |
7471 case CPP_WCHAR: | 8191 case CPP_WCHAR: |
7486 | 8206 |
7487 error (message, prefix, val); | 8207 error (message, prefix, val); |
7488 free (message); | 8208 free (message); |
7489 message = NULL; | 8209 message = NULL; |
7490 } | 8210 } |
7491 else if (token == CPP_STRING || token == CPP_WSTRING || token == CPP_STRING16 | 8211 else if (token_type == CPP_STRING |
7492 || token == CPP_STRING32) | 8212 || token_type == CPP_WSTRING |
8213 || token_type == CPP_STRING16 | |
8214 || token_type == CPP_STRING32 | |
8215 || token_type == CPP_UTF8STRING) | |
7493 message = catenate_messages (gmsgid, " before string constant"); | 8216 message = catenate_messages (gmsgid, " before string constant"); |
7494 else if (token == CPP_NUMBER) | 8217 else if (token_type == CPP_NUMBER) |
7495 message = catenate_messages (gmsgid, " before numeric constant"); | 8218 message = catenate_messages (gmsgid, " before numeric constant"); |
7496 else if (token == CPP_NAME) | 8219 else if (token_type == CPP_NAME) |
7497 { | 8220 { |
7498 message = catenate_messages (gmsgid, " before %qE"); | 8221 message = catenate_messages (gmsgid, " before %qE"); |
7499 error (message, value); | 8222 error (message, value); |
7500 free (message); | 8223 free (message); |
7501 message = NULL; | 8224 message = NULL; |
7502 } | 8225 } |
7503 else if (token == CPP_PRAGMA) | 8226 else if (token_type == CPP_PRAGMA) |
7504 message = catenate_messages (gmsgid, " before %<#pragma%>"); | 8227 message = catenate_messages (gmsgid, " before %<#pragma%>"); |
7505 else if (token == CPP_PRAGMA_EOL) | 8228 else if (token_type == CPP_PRAGMA_EOL) |
7506 message = catenate_messages (gmsgid, " before end of line"); | 8229 message = catenate_messages (gmsgid, " before end of line"); |
7507 else if (token < N_TTYPES) | 8230 else if (token_type < N_TTYPES) |
7508 { | 8231 { |
7509 message = catenate_messages (gmsgid, " before %qs token"); | 8232 message = catenate_messages (gmsgid, " before %qs token"); |
7510 error (message, cpp_type2name (token)); | 8233 error (message, cpp_type2name (token_type, token_flags)); |
7511 free (message); | 8234 free (message); |
7512 message = NULL; | 8235 message = NULL; |
7513 } | 8236 } |
7514 else | 8237 else |
7515 error (gmsgid); | 8238 error (gmsgid); |
7520 free (message); | 8243 free (message); |
7521 } | 8244 } |
7522 #undef catenate_messages | 8245 #undef catenate_messages |
7523 } | 8246 } |
7524 | 8247 |
7525 /* Walk a gimplified function and warn for functions whose return value is | 8248 /* Callback from cpp_error for PFILE to print diagnostics from the |
7526 ignored and attribute((warn_unused_result)) is set. This is done before | 8249 preprocessor. The diagnostic is of type LEVEL, at location |
7527 inlining, so we don't have to worry about that. */ | 8250 LOCATION unless this is after lexing and the compiler's location |
7528 | 8251 should be used instead, with column number possibly overridden by |
7529 void | 8252 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP |
7530 c_warn_unused_result (gimple_seq seq) | 8253 the arguments. Returns true if a diagnostic was emitted, false |
7531 { | 8254 otherwise. */ |
7532 tree fdecl, ftype; | 8255 |
7533 gimple_stmt_iterator i; | 8256 bool |
7534 | 8257 c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, |
7535 for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i)) | 8258 location_t location, unsigned int column_override, |
7536 { | 8259 const char *msg, va_list *ap) |
7537 gimple g = gsi_stmt (i); | 8260 { |
7538 | 8261 diagnostic_info diagnostic; |
7539 switch (gimple_code (g)) | 8262 diagnostic_t dlevel; |
7540 { | 8263 int save_warn_system_headers = warn_system_headers; |
7541 case GIMPLE_BIND: | 8264 bool ret; |
7542 c_warn_unused_result (gimple_bind_body (g)); | 8265 |
7543 break; | 8266 switch (level) |
7544 case GIMPLE_TRY: | 8267 { |
7545 c_warn_unused_result (gimple_try_eval (g)); | 8268 case CPP_DL_WARNING_SYSHDR: |
7546 c_warn_unused_result (gimple_try_cleanup (g)); | 8269 if (flag_no_output) |
7547 break; | 8270 return false; |
7548 case GIMPLE_CATCH: | 8271 warn_system_headers = 1; |
7549 c_warn_unused_result (gimple_catch_handler (g)); | 8272 /* Fall through. */ |
7550 break; | 8273 case CPP_DL_WARNING: |
7551 case GIMPLE_EH_FILTER: | 8274 if (flag_no_output) |
7552 c_warn_unused_result (gimple_eh_filter_failure (g)); | 8275 return false; |
7553 break; | 8276 dlevel = DK_WARNING; |
7554 | 8277 break; |
7555 case GIMPLE_CALL: | 8278 case CPP_DL_PEDWARN: |
7556 if (gimple_call_lhs (g)) | 8279 if (flag_no_output && !flag_pedantic_errors) |
7557 break; | 8280 return false; |
7558 | 8281 dlevel = DK_PEDWARN; |
7559 /* This is a naked call, as opposed to a GIMPLE_CALL with an | 8282 break; |
7560 LHS. All calls whose value is ignored should be | 8283 case CPP_DL_ERROR: |
7561 represented like this. Look for the attribute. */ | 8284 dlevel = DK_ERROR; |
7562 fdecl = gimple_call_fndecl (g); | 8285 break; |
7563 ftype = TREE_TYPE (TREE_TYPE (gimple_call_fn (g))); | 8286 case CPP_DL_ICE: |
7564 | 8287 dlevel = DK_ICE; |
7565 if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype))) | 8288 break; |
7566 { | 8289 case CPP_DL_NOTE: |
7567 location_t loc = gimple_location (g); | 8290 dlevel = DK_NOTE; |
7568 | 8291 break; |
7569 if (fdecl) | 8292 case CPP_DL_FATAL: |
7570 warning (0, "%Hignoring return value of %qD, " | 8293 dlevel = DK_FATAL; |
7571 "declared with attribute warn_unused_result", | 8294 break; |
7572 &loc, fdecl); | 8295 default: |
7573 else | 8296 gcc_unreachable (); |
7574 warning (0, "%Hignoring return value of function " | 8297 } |
7575 "declared with attribute warn_unused_result", | 8298 if (done_lexing) |
7576 &loc); | 8299 location = input_location; |
7577 } | 8300 diagnostic_set_info_translated (&diagnostic, msg, ap, |
7578 break; | 8301 location, dlevel); |
7579 | 8302 if (column_override) |
7580 default: | 8303 diagnostic_override_column (&diagnostic, column_override); |
7581 /* Not a container, not a call, or a call whose value is used. */ | 8304 ret = report_diagnostic (&diagnostic); |
7582 break; | 8305 if (level == CPP_DL_WARNING_SYSHDR) |
7583 } | 8306 warn_system_headers = save_warn_system_headers; |
7584 } | 8307 return ret; |
7585 } | 8308 } |
7586 | 8309 |
7587 /* Convert a character from the host to the target execution character | 8310 /* Convert a character from the host to the target execution character |
7588 set. cpplib handles this, mostly. */ | 8311 set. cpplib handles this, mostly. */ |
7589 | 8312 |
7652 { | 8375 { |
7653 error ("attempt to take address of bit-field structure " | 8376 error ("attempt to take address of bit-field structure " |
7654 "member %qD", t); | 8377 "member %qD", t); |
7655 return error_mark_node; | 8378 return error_mark_node; |
7656 } | 8379 } |
7657 off = size_binop (PLUS_EXPR, DECL_FIELD_OFFSET (t), | 8380 off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t), |
7658 size_int (tree_low_cst (DECL_FIELD_BIT_OFFSET (t), 1) | 8381 size_int (tree_low_cst (DECL_FIELD_BIT_OFFSET (t), |
7659 / BITS_PER_UNIT)); | 8382 1) |
8383 / BITS_PER_UNIT)); | |
7660 break; | 8384 break; |
7661 | 8385 |
7662 case ARRAY_REF: | 8386 case ARRAY_REF: |
7663 base = fold_offsetof_1 (TREE_OPERAND (expr, 0), stop_ref); | 8387 base = fold_offsetof_1 (TREE_OPERAND (expr, 0), stop_ref); |
7664 if (base == error_mark_node) | 8388 if (base == error_mark_node) |
7666 | 8390 |
7667 t = TREE_OPERAND (expr, 1); | 8391 t = TREE_OPERAND (expr, 1); |
7668 if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) < 0) | 8392 if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) < 0) |
7669 { | 8393 { |
7670 code = MINUS_EXPR; | 8394 code = MINUS_EXPR; |
7671 t = fold_build1 (NEGATE_EXPR, TREE_TYPE (t), t); | 8395 t = fold_build1_loc (input_location, NEGATE_EXPR, TREE_TYPE (t), t); |
7672 } | 8396 } |
7673 t = convert (sizetype, t); | 8397 t = convert (sizetype, t); |
7674 off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t); | 8398 off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t); |
8399 | |
8400 /* Check if the offset goes beyond the upper bound of the array. */ | |
8401 if (code == PLUS_EXPR && TREE_CODE (t) == INTEGER_CST) | |
8402 { | |
8403 tree upbound = array_ref_up_bound (expr); | |
8404 if (upbound != NULL_TREE | |
8405 && TREE_CODE (upbound) == INTEGER_CST | |
8406 && !tree_int_cst_equal (upbound, | |
8407 TYPE_MAX_VALUE (TREE_TYPE (upbound)))) | |
8408 { | |
8409 upbound = size_binop (PLUS_EXPR, upbound, | |
8410 build_int_cst (TREE_TYPE (upbound), 1)); | |
8411 if (tree_int_cst_lt (upbound, t)) | |
8412 { | |
8413 tree v; | |
8414 | |
8415 for (v = TREE_OPERAND (expr, 0); | |
8416 TREE_CODE (v) == COMPONENT_REF; | |
8417 v = TREE_OPERAND (v, 0)) | |
8418 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) | |
8419 == RECORD_TYPE) | |
8420 { | |
8421 tree fld_chain = TREE_CHAIN (TREE_OPERAND (v, 1)); | |
8422 for (; fld_chain; fld_chain = TREE_CHAIN (fld_chain)) | |
8423 if (TREE_CODE (fld_chain) == FIELD_DECL) | |
8424 break; | |
8425 | |
8426 if (fld_chain) | |
8427 break; | |
8428 } | |
8429 /* Don't warn if the array might be considered a poor | |
8430 man's flexible array member with a very permissive | |
8431 definition thereof. */ | |
8432 if (TREE_CODE (v) == ARRAY_REF | |
8433 || TREE_CODE (v) == COMPONENT_REF) | |
8434 warning (OPT_Warray_bounds, | |
8435 "index %E denotes an offset " | |
8436 "greater than size of %qT", | |
8437 t, TREE_TYPE (TREE_OPERAND (expr, 0))); | |
8438 } | |
8439 } | |
8440 } | |
7675 break; | 8441 break; |
7676 | 8442 |
7677 case COMPOUND_EXPR: | 8443 case COMPOUND_EXPR: |
7678 /* Handle static members of volatile structs. */ | 8444 /* Handle static members of volatile structs. */ |
7679 t = TREE_OPERAND (expr, 1); | 8445 t = TREE_OPERAND (expr, 1); |
7759 unsigned HOST_WIDE_INT cnt; | 8525 unsigned HOST_WIDE_INT cnt; |
7760 constructor_elt *ce; | 8526 constructor_elt *ce; |
7761 bool fold_p = false; | 8527 bool fold_p = false; |
7762 | 8528 |
7763 if (VEC_index (constructor_elt, v, 0)->index) | 8529 if (VEC_index (constructor_elt, v, 0)->index) |
7764 maxindex = fold_convert (sizetype, | 8530 maxindex = fold_convert_loc (input_location, sizetype, |
7765 VEC_index (constructor_elt, | 8531 VEC_index (constructor_elt, |
7766 v, 0)->index); | 8532 v, 0)->index); |
7767 curindex = maxindex; | 8533 curindex = maxindex; |
7768 | 8534 |
7769 for (cnt = 1; | 8535 for (cnt = 1; |
7770 VEC_iterate (constructor_elt, v, cnt, ce); | 8536 VEC_iterate (constructor_elt, v, cnt, ce); |
7771 cnt++) | 8537 cnt++) |
7775 curindex = ce->index, curfold_p = true; | 8541 curindex = ce->index, curfold_p = true; |
7776 else | 8542 else |
7777 { | 8543 { |
7778 if (fold_p) | 8544 if (fold_p) |
7779 curindex = fold_convert (sizetype, curindex); | 8545 curindex = fold_convert (sizetype, curindex); |
7780 curindex = size_binop (PLUS_EXPR, curindex, size_one_node); | 8546 curindex = size_binop (PLUS_EXPR, curindex, |
8547 size_one_node); | |
7781 } | 8548 } |
7782 if (tree_int_cst_lt (maxindex, curindex)) | 8549 if (tree_int_cst_lt (maxindex, curindex)) |
7783 maxindex = curindex, fold_p = curfold_p; | 8550 maxindex = curindex, fold_p = curfold_p; |
7784 } | 8551 } |
7785 if (fold_p) | 8552 if (fold_p) |
7804 elt = TREE_TYPE (type); | 8571 elt = TREE_TYPE (type); |
7805 quals = TYPE_QUALS (strip_array_types (elt)); | 8572 quals = TYPE_QUALS (strip_array_types (elt)); |
7806 if (quals == 0) | 8573 if (quals == 0) |
7807 unqual_elt = elt; | 8574 unqual_elt = elt; |
7808 else | 8575 else |
7809 unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED); | 8576 unqual_elt = c_build_qualified_type (elt, KEEP_QUAL_ADDR_SPACE (quals)); |
7810 | 8577 |
7811 /* Using build_distinct_type_copy and modifying things afterward instead | 8578 /* Using build_distinct_type_copy and modifying things afterward instead |
7812 of using build_array_type to create a new type preserves all of the | 8579 of using build_array_type to create a new type preserves all of the |
7813 TYPE_LANG_FLAG_? bits that the front end may have set. */ | 8580 TYPE_LANG_FLAG_? bits that the front end may have set. */ |
7814 main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); | 8581 main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); |
7816 TYPE_DOMAIN (main_type) = build_index_type (maxindex); | 8583 TYPE_DOMAIN (main_type) = build_index_type (maxindex); |
7817 layout_type (main_type); | 8584 layout_type (main_type); |
7818 | 8585 |
7819 /* Make sure we have the canonical MAIN_TYPE. */ | 8586 /* Make sure we have the canonical MAIN_TYPE. */ |
7820 hashcode = iterative_hash_object (TYPE_HASH (unqual_elt), hashcode); | 8587 hashcode = iterative_hash_object (TYPE_HASH (unqual_elt), hashcode); |
7821 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type)), | 8588 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (main_type)), |
7822 hashcode); | 8589 hashcode); |
7823 main_type = type_hash_canon (hashcode, main_type); | 8590 main_type = type_hash_canon (hashcode, main_type); |
7824 | 8591 |
7825 /* Fix the canonical type. */ | 8592 /* Fix the canonical type. */ |
7826 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type)) | 8593 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type)) |
7827 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type))) | 8594 || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type))) |
7828 SET_TYPE_STRUCTURAL_EQUALITY (main_type); | 8595 SET_TYPE_STRUCTURAL_EQUALITY (main_type); |
7829 else if (TYPE_CANONICAL (TREE_TYPE (main_type)) != TREE_TYPE (main_type) | 8596 else if (TYPE_CANONICAL (TREE_TYPE (main_type)) != TREE_TYPE (main_type) |
7830 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type)) | 8597 || (TYPE_CANONICAL (TYPE_DOMAIN (main_type)) |
7831 != TYPE_DOMAIN (main_type))) | 8598 != TYPE_DOMAIN (main_type))) |
7832 TYPE_CANONICAL (main_type) | 8599 TYPE_CANONICAL (main_type) |
7833 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type)), | 8600 = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type)), |
7834 TYPE_CANONICAL (TYPE_DOMAIN (main_type))); | 8601 TYPE_CANONICAL (TYPE_DOMAIN (main_type))); |
7835 else | 8602 else |
7836 TYPE_CANONICAL (main_type) = main_type; | 8603 TYPE_CANONICAL (main_type) = main_type; |
7837 | 8604 |
7871 overloaded __sync_ builtins. Returns a positive power of 2 if the | 8638 overloaded __sync_ builtins. Returns a positive power of 2 if the |
7872 first operand of PARAMS is a pointer to a supported data type. | 8639 first operand of PARAMS is a pointer to a supported data type. |
7873 Returns 0 if an error is encountered. */ | 8640 Returns 0 if an error is encountered. */ |
7874 | 8641 |
7875 static int | 8642 static int |
7876 sync_resolve_size (tree function, tree params) | 8643 sync_resolve_size (tree function, VEC(tree,gc) *params) |
7877 { | 8644 { |
7878 tree type; | 8645 tree type; |
7879 int size; | 8646 int size; |
7880 | 8647 |
7881 if (params == NULL) | 8648 if (VEC_empty (tree, params)) |
7882 { | 8649 { |
7883 error ("too few arguments to function %qE", function); | 8650 error ("too few arguments to function %qE", function); |
7884 return 0; | 8651 return 0; |
7885 } | 8652 } |
7886 | 8653 |
7887 type = TREE_TYPE (TREE_VALUE (params)); | 8654 type = TREE_TYPE (VEC_index (tree, params, 0)); |
7888 if (TREE_CODE (type) != POINTER_TYPE) | 8655 if (TREE_CODE (type) != POINTER_TYPE) |
7889 goto incompatible; | 8656 goto incompatible; |
7890 | 8657 |
7891 type = TREE_TYPE (type); | 8658 type = TREE_TYPE (type); |
7892 if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) | 8659 if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type)) |
7905 PARAMS to make arguments match up with those of FUNCTION. Drops | 8672 PARAMS to make arguments match up with those of FUNCTION. Drops |
7906 the variadic arguments at the end. Returns false if some error | 8673 the variadic arguments at the end. Returns false if some error |
7907 was encountered; true on success. */ | 8674 was encountered; true on success. */ |
7908 | 8675 |
7909 static bool | 8676 static bool |
7910 sync_resolve_params (tree orig_function, tree function, tree params) | 8677 sync_resolve_params (tree orig_function, tree function, VEC(tree, gc) *params) |
7911 { | 8678 { |
7912 tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); | 8679 tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); |
7913 tree ptype; | 8680 tree ptype; |
7914 int number; | 8681 int number; |
8682 unsigned int parmnum; | |
7915 | 8683 |
7916 /* We've declared the implementation functions to use "volatile void *" | 8684 /* We've declared the implementation functions to use "volatile void *" |
7917 as the pointer parameter, so we shouldn't get any complaints from the | 8685 as the pointer parameter, so we shouldn't get any complaints from the |
7918 call to check_function_arguments what ever type the user used. */ | 8686 call to check_function_arguments what ever type the user used. */ |
7919 arg_types = TREE_CHAIN (arg_types); | 8687 arg_types = TREE_CHAIN (arg_types); |
7920 ptype = TREE_TYPE (TREE_TYPE (TREE_VALUE (params))); | 8688 ptype = TREE_TYPE (TREE_TYPE (VEC_index (tree, params, 0))); |
7921 number = 2; | 8689 number = 2; |
7922 | 8690 |
7923 /* For the rest of the values, we need to cast these to FTYPE, so that we | 8691 /* For the rest of the values, we need to cast these to FTYPE, so that we |
7924 don't get warnings for passing pointer types, etc. */ | 8692 don't get warnings for passing pointer types, etc. */ |
8693 parmnum = 0; | |
7925 while (arg_types != void_list_node) | 8694 while (arg_types != void_list_node) |
7926 { | 8695 { |
7927 tree val; | 8696 tree val; |
7928 | 8697 |
7929 params = TREE_CHAIN (params); | 8698 ++parmnum; |
7930 if (params == NULL) | 8699 if (VEC_length (tree, params) <= parmnum) |
7931 { | 8700 { |
7932 error ("too few arguments to function %qE", orig_function); | 8701 error ("too few arguments to function %qE", orig_function); |
7933 return false; | 8702 return false; |
7934 } | 8703 } |
7935 | 8704 |
7936 /* ??? Ideally for the first conversion we'd use convert_for_assignment | 8705 /* ??? Ideally for the first conversion we'd use convert_for_assignment |
7937 so that we get warnings for anything that doesn't match the pointer | 8706 so that we get warnings for anything that doesn't match the pointer |
7938 type. This isn't portable across the C and C++ front ends atm. */ | 8707 type. This isn't portable across the C and C++ front ends atm. */ |
7939 val = TREE_VALUE (params); | 8708 val = VEC_index (tree, params, parmnum); |
7940 val = convert (ptype, val); | 8709 val = convert (ptype, val); |
7941 val = convert (TREE_VALUE (arg_types), val); | 8710 val = convert (TREE_VALUE (arg_types), val); |
7942 TREE_VALUE (params) = val; | 8711 VEC_replace (tree, params, parmnum, val); |
7943 | 8712 |
7944 arg_types = TREE_CHAIN (arg_types); | 8713 arg_types = TREE_CHAIN (arg_types); |
7945 number++; | 8714 number++; |
7946 } | 8715 } |
7947 | 8716 |
7948 /* The definition of these primitives is variadic, with the remaining | 8717 /* The definition of these primitives is variadic, with the remaining |
7949 being "an optional list of variables protected by the memory barrier". | 8718 being "an optional list of variables protected by the memory barrier". |
7950 No clue what that's supposed to mean, precisely, but we consider all | 8719 No clue what that's supposed to mean, precisely, but we consider all |
7951 call-clobbered variables to be protected so we're safe. */ | 8720 call-clobbered variables to be protected so we're safe. */ |
7952 TREE_CHAIN (params) = NULL; | 8721 VEC_truncate (tree, params, parmnum + 1); |
7953 | 8722 |
7954 return true; | 8723 return true; |
7955 } | 8724 } |
7956 | 8725 |
7957 /* A helper function for resolve_overloaded_builtin. Adds a cast to | 8726 /* A helper function for resolve_overloaded_builtin. Adds a cast to |
7958 RESULT to make it match the type of the first pointer argument in | 8727 RESULT to make it match the type of the first pointer argument in |
7959 PARAMS. */ | 8728 PARAMS. */ |
7960 | 8729 |
7961 static tree | 8730 static tree |
7962 sync_resolve_return (tree params, tree result) | 8731 sync_resolve_return (tree first_param, tree result) |
7963 { | 8732 { |
7964 tree ptype = TREE_TYPE (TREE_TYPE (TREE_VALUE (params))); | 8733 tree ptype = TREE_TYPE (TREE_TYPE (first_param)); |
7965 ptype = TYPE_MAIN_VARIANT (ptype); | 8734 ptype = TYPE_MAIN_VARIANT (ptype); |
7966 return convert (ptype, result); | 8735 return convert (ptype, result); |
7967 } | 8736 } |
7968 | 8737 |
7969 /* Some builtin functions are placeholders for other expressions. This | 8738 /* Some builtin functions are placeholders for other expressions. This |
7970 function should be called immediately after parsing the call expression | 8739 function should be called immediately after parsing the call expression |
7971 before surrounding code has committed to the type of the expression. | 8740 before surrounding code has committed to the type of the expression. |
8741 | |
8742 LOC is the location of the builtin call. | |
7972 | 8743 |
7973 FUNCTION is the DECL that has been invoked; it is known to be a builtin. | 8744 FUNCTION is the DECL that has been invoked; it is known to be a builtin. |
7974 PARAMS is the argument list for the call. The return value is non-null | 8745 PARAMS is the argument list for the call. The return value is non-null |
7975 when expansion is complete, and null if normal processing should | 8746 when expansion is complete, and null if normal processing should |
7976 continue. */ | 8747 continue. */ |
7977 | 8748 |
7978 tree | 8749 tree |
7979 resolve_overloaded_builtin (tree function, tree params) | 8750 resolve_overloaded_builtin (location_t loc, tree function, VEC(tree,gc) *params) |
7980 { | 8751 { |
7981 enum built_in_function orig_code = DECL_FUNCTION_CODE (function); | 8752 enum built_in_function orig_code = DECL_FUNCTION_CODE (function); |
7982 switch (DECL_BUILT_IN_CLASS (function)) | 8753 switch (DECL_BUILT_IN_CLASS (function)) |
7983 { | 8754 { |
7984 case BUILT_IN_NORMAL: | 8755 case BUILT_IN_NORMAL: |
7985 break; | 8756 break; |
7986 case BUILT_IN_MD: | 8757 case BUILT_IN_MD: |
7987 if (targetm.resolve_overloaded_builtin) | 8758 if (targetm.resolve_overloaded_builtin) |
7988 return targetm.resolve_overloaded_builtin (function, params); | 8759 return targetm.resolve_overloaded_builtin (loc, function, params); |
7989 else | 8760 else |
7990 return NULL_TREE; | 8761 return NULL_TREE; |
7991 default: | 8762 default: |
7992 return NULL_TREE; | 8763 return NULL_TREE; |
7993 } | 8764 } |
8011 case BUILT_IN_VAL_COMPARE_AND_SWAP_N: | 8782 case BUILT_IN_VAL_COMPARE_AND_SWAP_N: |
8012 case BUILT_IN_LOCK_TEST_AND_SET_N: | 8783 case BUILT_IN_LOCK_TEST_AND_SET_N: |
8013 case BUILT_IN_LOCK_RELEASE_N: | 8784 case BUILT_IN_LOCK_RELEASE_N: |
8014 { | 8785 { |
8015 int n = sync_resolve_size (function, params); | 8786 int n = sync_resolve_size (function, params); |
8016 tree new_function, result; | 8787 tree new_function, first_param, result; |
8017 | 8788 |
8018 if (n == 0) | 8789 if (n == 0) |
8019 return error_mark_node; | 8790 return error_mark_node; |
8020 | 8791 |
8021 new_function = built_in_decls[orig_code + exact_log2 (n) + 1]; | 8792 new_function = built_in_decls[orig_code + exact_log2 (n) + 1]; |
8022 if (!sync_resolve_params (function, new_function, params)) | 8793 if (!sync_resolve_params (function, new_function, params)) |
8023 return error_mark_node; | 8794 return error_mark_node; |
8024 | 8795 |
8025 result = build_function_call (new_function, params); | 8796 first_param = VEC_index (tree, params, 0); |
8797 result = build_function_call_vec (loc, new_function, params, NULL); | |
8026 if (orig_code != BUILT_IN_BOOL_COMPARE_AND_SWAP_N | 8798 if (orig_code != BUILT_IN_BOOL_COMPARE_AND_SWAP_N |
8027 && orig_code != BUILT_IN_LOCK_RELEASE_N) | 8799 && orig_code != BUILT_IN_LOCK_RELEASE_N) |
8028 result = sync_resolve_return (params, result); | 8800 result = sync_resolve_return (first_param, result); |
8029 | 8801 |
8030 return result; | 8802 return result; |
8031 } | 8803 } |
8032 | 8804 |
8033 default: | 8805 default: |
8117 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \ | 8889 || TREE_CODE (TREE_TYPE (ARG)) == BOOLEAN_TYPE \ |
8118 /* Folding may create 0 or 1 integers from other expressions. */ \ | 8890 /* Folding may create 0 or 1 integers from other expressions. */ \ |
8119 || ((CODE) != INTEGER_CST \ | 8891 || ((CODE) != INTEGER_CST \ |
8120 && (integer_onep (ARG) || integer_zerop (ARG)))) | 8892 && (integer_onep (ARG) || integer_zerop (ARG)))) |
8121 | 8893 |
8122 switch (code) | 8894 switch (code) |
8123 { | 8895 { |
8124 case LSHIFT_EXPR: | 8896 case LSHIFT_EXPR: |
8125 if (code_left == PLUS_EXPR || code_right == PLUS_EXPR) | 8897 if (code_left == PLUS_EXPR || code_right == PLUS_EXPR) |
8126 warning (OPT_Wparentheses, | 8898 warning (OPT_Wparentheses, |
8127 "suggest parentheses around %<+%> inside %<<<%>"); | 8899 "suggest parentheses around %<+%> inside %<<<%>"); |
8251 { | 9023 { |
8252 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning | 9024 /* If DIVISOR is zero, and has integral or fixed-point type, issue a warning |
8253 about division by zero. Do not issue a warning if DIVISOR has a | 9025 about division by zero. Do not issue a warning if DIVISOR has a |
8254 floating-point type, since we consider 0.0/0.0 a valid way of | 9026 floating-point type, since we consider 0.0/0.0 a valid way of |
8255 generating a NaN. */ | 9027 generating a NaN. */ |
8256 if (skip_evaluation == 0 | 9028 if (c_inhibit_evaluation_warnings == 0 |
8257 && (integer_zerop (divisor) || fixed_zerop (divisor))) | 9029 && (integer_zerop (divisor) || fixed_zerop (divisor))) |
8258 warning_at (loc, OPT_Wdiv_by_zero, "division by zero"); | 9030 warning_at (loc, OPT_Wdiv_by_zero, "division by zero"); |
8259 } | 9031 } |
8260 | 9032 |
8261 /* Subroutine of build_binary_op. Give warnings for comparisons | 9033 /* Subroutine of build_binary_op. Give warnings for comparisons |
8267 LOCATION is the location of the comparison operator. | 9039 LOCATION is the location of the comparison operator. |
8268 | 9040 |
8269 The arguments of this function map directly to local variables | 9041 The arguments of this function map directly to local variables |
8270 of build_binary_op. */ | 9042 of build_binary_op. */ |
8271 | 9043 |
8272 void | 9044 void |
8273 warn_for_sign_compare (location_t location, | 9045 warn_for_sign_compare (location_t location, |
8274 tree orig_op0, tree orig_op1, | 9046 tree orig_op0, tree orig_op1, |
8275 tree op0, tree op1, | 9047 tree op0, tree op1, |
8276 tree result_type, enum tree_code resultcode) | 9048 tree result_type, enum tree_code resultcode) |
8277 { | 9049 { |
8278 int op0_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op0)); | 9050 int op0_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op0)); |
8279 int op1_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op1)); | 9051 int op1_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op1)); |
8280 int unsignedp0, unsignedp1; | 9052 int unsignedp0, unsignedp1; |
8281 | 9053 |
8282 /* In C++, check for comparison of different enum types. */ | 9054 /* In C++, check for comparison of different enum types. */ |
8283 if (c_dialect_cxx() | 9055 if (c_dialect_cxx() |
8284 && TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE | 9056 && TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE |
8285 && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE | 9057 && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE |
8286 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0)) | 9058 && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0)) |
8304 tree sop, uop, base_type; | 9076 tree sop, uop, base_type; |
8305 bool ovf; | 9077 bool ovf; |
8306 | 9078 |
8307 if (op0_signed) | 9079 if (op0_signed) |
8308 sop = orig_op0, uop = orig_op1; | 9080 sop = orig_op0, uop = orig_op1; |
8309 else | 9081 else |
8310 sop = orig_op1, uop = orig_op0; | 9082 sop = orig_op1, uop = orig_op0; |
8311 | 9083 |
8312 STRIP_TYPE_NOPS (sop); | 9084 STRIP_TYPE_NOPS (sop); |
8313 STRIP_TYPE_NOPS (uop); | 9085 STRIP_TYPE_NOPS (uop); |
8314 base_type = (TREE_CODE (result_type) == COMPLEX_TYPE | 9086 base_type = (TREE_CODE (result_type) == COMPLEX_TYPE |
8315 ? TREE_TYPE (result_type) : result_type); | 9087 ? TREE_TYPE (result_type) : result_type); |
8316 | 9088 |
8317 /* Do not warn if the signed quantity is an unsuffixed integer | 9089 /* Do not warn if the signed quantity is an unsuffixed integer |
8333 else if (!c_dialect_cxx() && TREE_CODE (uop) == INTEGER_CST | 9105 else if (!c_dialect_cxx() && TREE_CODE (uop) == INTEGER_CST |
8334 && TREE_CODE (TREE_TYPE (uop)) == ENUMERAL_TYPE | 9106 && TREE_CODE (TREE_TYPE (uop)) == ENUMERAL_TYPE |
8335 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop)), | 9107 && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop)), |
8336 c_common_signed_type (base_type))) | 9108 c_common_signed_type (base_type))) |
8337 /* OK */; | 9109 /* OK */; |
8338 else | 9110 else |
8339 warning_at (location, | 9111 warning_at (location, |
8340 OPT_Wsign_compare, | 9112 OPT_Wsign_compare, |
8341 "comparison between signed and unsigned integer expressions"); | 9113 "comparison between signed and unsigned integer expressions"); |
8342 } | 9114 } |
8343 | 9115 |
8344 /* Warn if two unsigned values are being compared in a size larger | 9116 /* Warn if two unsigned values are being compared in a size larger |
8345 than their original size, and one (and only one) is the result of | 9117 than their original size, and one (and only one) is the result of |
8346 a `~' operator. This comparison will always fail. | 9118 a `~' operator. This comparison will always fail. |
8347 | 9119 |
8348 Also warn if one operand is a constant, and the constant does not | 9120 Also warn if one operand is a constant, and the constant does not |
8349 have all bits set that are set in the ~ operand when it is | 9121 have all bits set that are set in the ~ operand when it is |
8350 extended. */ | 9122 extended. */ |
8351 | 9123 |
8352 op0 = get_narrower (op0, &unsignedp0); | 9124 op0 = get_narrower (op0, &unsignedp0); |
8353 op1 = get_narrower (op1, &unsignedp1); | 9125 op1 = get_narrower (op1, &unsignedp1); |
8354 | 9126 |
8355 if ((TREE_CODE (op0) == BIT_NOT_EXPR) | 9127 if ((TREE_CODE (op0) == BIT_NOT_EXPR) |
8356 ^ (TREE_CODE (op1) == BIT_NOT_EXPR)) | 9128 ^ (TREE_CODE (op1) == BIT_NOT_EXPR)) |
8357 { | 9129 { |
8358 if (TREE_CODE (op0) == BIT_NOT_EXPR) | 9130 if (TREE_CODE (op0) == BIT_NOT_EXPR) |
8359 op0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0); | 9131 op0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0); |
8364 { | 9136 { |
8365 tree primop; | 9137 tree primop; |
8366 HOST_WIDE_INT constant, mask; | 9138 HOST_WIDE_INT constant, mask; |
8367 int unsignedp; | 9139 int unsignedp; |
8368 unsigned int bits; | 9140 unsigned int bits; |
8369 | 9141 |
8370 if (host_integerp (op0, 0)) | 9142 if (host_integerp (op0, 0)) |
8371 { | 9143 { |
8372 primop = op1; | 9144 primop = op1; |
8373 unsignedp = unsignedp1; | 9145 unsignedp = unsignedp1; |
8374 constant = tree_low_cst (op0, 0); | 9146 constant = tree_low_cst (op0, 0); |
8377 { | 9149 { |
8378 primop = op0; | 9150 primop = op0; |
8379 unsignedp = unsignedp0; | 9151 unsignedp = unsignedp0; |
8380 constant = tree_low_cst (op1, 0); | 9152 constant = tree_low_cst (op1, 0); |
8381 } | 9153 } |
8382 | 9154 |
8383 bits = TYPE_PRECISION (TREE_TYPE (primop)); | 9155 bits = TYPE_PRECISION (TREE_TYPE (primop)); |
8384 if (bits < TYPE_PRECISION (result_type) | 9156 if (bits < TYPE_PRECISION (result_type) |
8385 && bits < HOST_BITS_PER_LONG && unsignedp) | 9157 && bits < HOST_BITS_PER_LONG && unsignedp) |
8386 { | 9158 { |
8387 mask = (~ (HOST_WIDE_INT) 0) << bits; | 9159 mask = (~ (HOST_WIDE_INT) 0) << bits; |
8388 if ((mask & constant) != mask) | 9160 if ((mask & constant) != mask) |
8389 { | 9161 { |
8390 if (constant == 0) | 9162 if (constant == 0) |
8391 warning (OPT_Wsign_compare, | 9163 warning (OPT_Wsign_compare, |
8392 "promoted ~unsigned is always non-zero"); | 9164 "promoted ~unsigned is always non-zero"); |
8393 else | 9165 else |
8394 warning_at (location, OPT_Wsign_compare, | 9166 warning_at (location, OPT_Wsign_compare, |
8395 "comparison of promoted ~unsigned with constant"); | 9167 "comparison of promoted ~unsigned with constant"); |
8396 } | 9168 } |
8397 } | 9169 } |
8398 } | 9170 } |
8399 else if (unsignedp0 && unsignedp1 | 9171 else if (unsignedp0 && unsignedp1 |
8404 warning_at (location, OPT_Wsign_compare, | 9176 warning_at (location, OPT_Wsign_compare, |
8405 "comparison of promoted ~unsigned with unsigned"); | 9177 "comparison of promoted ~unsigned with unsigned"); |
8406 } | 9178 } |
8407 } | 9179 } |
8408 | 9180 |
9181 /* Setup a TYPE_DECL node as a typedef representation. | |
9182 | |
9183 X is a TYPE_DECL for a typedef statement. Create a brand new | |
9184 ..._TYPE node (which will be just a variant of the existing | |
9185 ..._TYPE node with identical properties) and then install X | |
9186 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node. | |
9187 | |
9188 The whole point here is to end up with a situation where each | |
9189 and every ..._TYPE node the compiler creates will be uniquely | |
9190 associated with AT MOST one node representing a typedef name. | |
9191 This way, even though the compiler substitutes corresponding | |
9192 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very | |
9193 early on, later parts of the compiler can always do the reverse | |
9194 translation and get back the corresponding typedef name. For | |
9195 example, given: | |
9196 | |
9197 typedef struct S MY_TYPE; | |
9198 MY_TYPE object; | |
9199 | |
9200 Later parts of the compiler might only know that `object' was of | |
9201 type `struct S' if it were not for code just below. With this | |
9202 code however, later parts of the compiler see something like: | |
9203 | |
9204 struct S' == struct S | |
9205 typedef struct S' MY_TYPE; | |
9206 struct S' object; | |
9207 | |
9208 And they can then deduce (from the node for type struct S') that | |
9209 the original object declaration was: | |
9210 | |
9211 MY_TYPE object; | |
9212 | |
9213 Being able to do this is important for proper support of protoize, | |
9214 and also for generating precise symbolic debugging information | |
9215 which takes full account of the programmer's (typedef) vocabulary. | |
9216 | |
9217 Obviously, we don't want to generate a duplicate ..._TYPE node if | |
9218 the TYPE_DECL node that we are now processing really represents a | |
9219 standard built-in type. */ | |
9220 | |
9221 void | |
9222 set_underlying_type (tree x) | |
9223 { | |
9224 if (x == error_mark_node) | |
9225 return; | |
9226 if (DECL_IS_BUILTIN (x)) | |
9227 { | |
9228 if (TYPE_NAME (TREE_TYPE (x)) == 0) | |
9229 TYPE_NAME (TREE_TYPE (x)) = x; | |
9230 } | |
9231 else if (TREE_TYPE (x) != error_mark_node | |
9232 && DECL_ORIGINAL_TYPE (x) == NULL_TREE) | |
9233 { | |
9234 tree tt = TREE_TYPE (x); | |
9235 DECL_ORIGINAL_TYPE (x) = tt; | |
9236 tt = build_variant_type_copy (tt); | |
9237 TYPE_STUB_DECL (tt) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x)); | |
9238 TYPE_NAME (tt) = x; | |
9239 TREE_USED (tt) = TREE_USED (x); | |
9240 TREE_TYPE (x) = tt; | |
9241 } | |
9242 } | |
9243 | |
9244 /* Returns true if X is a typedef decl. */ | |
9245 | |
9246 bool | |
9247 is_typedef_decl (tree x) | |
9248 { | |
9249 return (x && TREE_CODE (x) == TYPE_DECL | |
9250 && DECL_ORIGINAL_TYPE (x) != NULL_TREE); | |
9251 } | |
9252 | |
8409 /* Record the types used by the current global variable declaration | 9253 /* Record the types used by the current global variable declaration |
8410 being parsed, so that we can decide later to emit their debug info. | 9254 being parsed, so that we can decide later to emit their debug info. |
8411 Those types are in types_used_by_cur_var_decl, and we are going to | 9255 Those types are in types_used_by_cur_var_decl, and we are going to |
8412 store them in the types_used_by_vars_hash hash table. | 9256 store them in the types_used_by_vars_hash hash table. |
8413 DECL is the declaration of the global variable that has been parsed. */ | 9257 DECL is the declaration of the global variable that has been parsed. */ |
8429 } | 9273 } |
8430 types_used_by_cur_var_decl = NULL; | 9274 types_used_by_cur_var_decl = NULL; |
8431 } | 9275 } |
8432 } | 9276 } |
8433 | 9277 |
9278 /* The C and C++ parsers both use vectors to hold function arguments. | |
9279 For efficiency, we keep a cache of unused vectors. This is the | |
9280 cache. */ | |
9281 | |
9282 typedef VEC(tree,gc)* tree_gc_vec; | |
9283 DEF_VEC_P(tree_gc_vec); | |
9284 DEF_VEC_ALLOC_P(tree_gc_vec,gc); | |
9285 static GTY((deletable)) VEC(tree_gc_vec,gc) *tree_vector_cache; | |
9286 | |
9287 /* Return a new vector from the cache. If the cache is empty, | |
9288 allocate a new vector. These vectors are GC'ed, so it is OK if the | |
9289 pointer is not released.. */ | |
9290 | |
9291 VEC(tree,gc) * | |
9292 make_tree_vector (void) | |
9293 { | |
9294 if (!VEC_empty (tree_gc_vec, tree_vector_cache)) | |
9295 return VEC_pop (tree_gc_vec, tree_vector_cache); | |
9296 else | |
9297 { | |
9298 /* Passing 0 to VEC_alloc returns NULL, and our callers require | |
9299 that we always return a non-NULL value. The vector code uses | |
9300 4 when growing a NULL vector, so we do too. */ | |
9301 return VEC_alloc (tree, gc, 4); | |
9302 } | |
9303 } | |
9304 | |
9305 /* Release a vector of trees back to the cache. */ | |
9306 | |
9307 void | |
9308 release_tree_vector (VEC(tree,gc) *vec) | |
9309 { | |
9310 if (vec != NULL) | |
9311 { | |
9312 VEC_truncate (tree, vec, 0); | |
9313 VEC_safe_push (tree_gc_vec, gc, tree_vector_cache, vec); | |
9314 } | |
9315 } | |
9316 | |
9317 /* Get a new tree vector holding a single tree. */ | |
9318 | |
9319 VEC(tree,gc) * | |
9320 make_tree_vector_single (tree t) | |
9321 { | |
9322 VEC(tree,gc) *ret = make_tree_vector (); | |
9323 VEC_quick_push (tree, ret, t); | |
9324 return ret; | |
9325 } | |
9326 | |
9327 /* Get a new tree vector which is a copy of an existing one. */ | |
9328 | |
9329 VEC(tree,gc) * | |
9330 make_tree_vector_copy (const VEC(tree,gc) *orig) | |
9331 { | |
9332 VEC(tree,gc) *ret; | |
9333 unsigned int ix; | |
9334 tree t; | |
9335 | |
9336 ret = make_tree_vector (); | |
9337 VEC_reserve (tree, gc, ret, VEC_length (tree, orig)); | |
9338 for (ix = 0; VEC_iterate (tree, orig, ix, t); ++ix) | |
9339 VEC_quick_push (tree, ret, t); | |
9340 return ret; | |
9341 } | |
9342 | |
8434 #include "gt-c-common.h" | 9343 #include "gt-c-common.h" |