Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-common.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
1 /* Subroutines shared by all languages that are variants of C. | 1 /* Subroutines shared by all languages that are variants of C. |
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, | 2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 | 3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
4 Free Software Foundation, Inc. | 4 Free Software Foundation, Inc. |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
8 GCC is free software; you can redistribute it and/or modify it under | 8 GCC is free software; you can redistribute it and/or modify it under |
28 #include "flags.h" | 28 #include "flags.h" |
29 #include "output.h" | 29 #include "output.h" |
30 #include "c-pragma.h" | 30 #include "c-pragma.h" |
31 #include "rtl.h" | 31 #include "rtl.h" |
32 #include "ggc.h" | 32 #include "ggc.h" |
33 #include "varray.h" | 33 #include "expr.h" /* For vector_mode_valid_p */ |
34 #include "expr.h" | |
35 #include "c-common.h" | 34 #include "c-common.h" |
36 #include "tm_p.h" | 35 #include "tm_p.h" |
37 #include "obstack.h" | 36 #include "obstack.h" |
38 #include "cpplib.h" | 37 #include "cpplib.h" |
39 #include "target.h" | 38 #include "target.h" |
44 #include "diagnostic.h" | 43 #include "diagnostic.h" |
45 #include "tree-iterator.h" | 44 #include "tree-iterator.h" |
46 #include "hashtab.h" | 45 #include "hashtab.h" |
47 #include "tree-mudflap.h" | 46 #include "tree-mudflap.h" |
48 #include "opts.h" | 47 #include "opts.h" |
49 #include "real.h" | |
50 #include "cgraph.h" | 48 #include "cgraph.h" |
51 #include "target-def.h" | 49 #include "target-def.h" |
52 #include "gimple.h" | |
53 #include "fixed-value.h" | |
54 #include "libfuncs.h" | 50 #include "libfuncs.h" |
55 | 51 |
56 cpp_reader *parse_in; /* Declared in c-pragma.h. */ | 52 cpp_reader *parse_in; /* Declared in c-pragma.h. */ |
57 | 53 |
58 /* The following symbols are subsumed in the c_global_trees array, and | 54 /* The following symbols are subsumed in the c_global_trees array, and |
278 | 274 |
279 /* Nonzero means enable C89 Amendment 1 features. */ | 275 /* Nonzero means enable C89 Amendment 1 features. */ |
280 | 276 |
281 int flag_isoc94; | 277 int flag_isoc94; |
282 | 278 |
283 /* Nonzero means use the ISO C99 dialect of C. */ | 279 /* Nonzero means use the ISO C99 (or C1X) dialect of C. */ |
284 | 280 |
285 int flag_isoc99; | 281 int flag_isoc99; |
282 | |
283 /* Nonzero means use the ISO C1X dialect of C. */ | |
284 | |
285 int flag_isoc1x; | |
286 | 286 |
287 /* Nonzero means that we have builtin functions, and main is an int. */ | 287 /* Nonzero means that we have builtin functions, and main is an int. */ |
288 | 288 |
289 int flag_hosted = 1; | 289 int flag_hosted = 1; |
290 | 290 |
421 | 421 |
422 /* Nonzero if we want to pretty-print template specializations as the | 422 /* Nonzero if we want to pretty-print template specializations as the |
423 template signature followed by the arguments. */ | 423 template signature followed by the arguments. */ |
424 | 424 |
425 int flag_pretty_templates = 1; | 425 int flag_pretty_templates = 1; |
426 | |
427 /* Nonzero means warn about implicit declarations. */ | |
428 | |
429 int warn_implicit = 1; | |
430 | 426 |
431 /* Maximum template instantiation depth. This limit exists to limit the | 427 /* Maximum template instantiation depth. This limit exists to limit the |
432 time it takes to notice infinite template instantiations; the default | 428 time it takes to notice infinite template instantiations; the default |
433 value of 1024 is likely to be in the next C++ standard. */ | 429 value of 1024 is likely to be in the next C++ standard. */ |
434 | 430 |
528 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *); | 524 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *); |
529 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *); | 525 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *); |
530 static tree handle_alloc_size_attribute (tree *, tree, tree, int, bool *); | 526 static tree handle_alloc_size_attribute (tree *, tree, tree, int, bool *); |
531 static tree handle_target_attribute (tree *, tree, tree, int, bool *); | 527 static tree handle_target_attribute (tree *, tree, tree, int, bool *); |
532 static tree handle_optimize_attribute (tree *, tree, tree, int, bool *); | 528 static tree handle_optimize_attribute (tree *, tree, tree, int, bool *); |
529 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *); | |
533 | 530 |
534 static void check_function_nonnull (tree, int, tree *); | 531 static void check_function_nonnull (tree, int, tree *); |
535 static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT); | 532 static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT); |
536 static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT); | 533 static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT); |
537 static bool get_nonnull_operand (tree, unsigned HOST_WIDE_INT *); | 534 static bool get_nonnull_operand (tree, unsigned HOST_WIDE_INT *); |
562 { "_Decimal64", RID_DFLOAT64, D_CONLY | D_EXT }, | 559 { "_Decimal64", RID_DFLOAT64, D_CONLY | D_EXT }, |
563 { "_Decimal128", RID_DFLOAT128, D_CONLY | D_EXT }, | 560 { "_Decimal128", RID_DFLOAT128, D_CONLY | D_EXT }, |
564 { "_Fract", RID_FRACT, D_CONLY | D_EXT }, | 561 { "_Fract", RID_FRACT, D_CONLY | D_EXT }, |
565 { "_Accum", RID_ACCUM, D_CONLY | D_EXT }, | 562 { "_Accum", RID_ACCUM, D_CONLY | D_EXT }, |
566 { "_Sat", RID_SAT, D_CONLY | D_EXT }, | 563 { "_Sat", RID_SAT, D_CONLY | D_EXT }, |
564 { "_Static_assert", RID_STATIC_ASSERT, D_CONLY }, | |
567 { "__FUNCTION__", RID_FUNCTION_NAME, 0 }, | 565 { "__FUNCTION__", RID_FUNCTION_NAME, 0 }, |
568 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 }, | 566 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 }, |
569 { "__alignof", RID_ALIGNOF, 0 }, | 567 { "__alignof", RID_ALIGNOF, 0 }, |
570 { "__alignof__", RID_ALIGNOF, 0 }, | 568 { "__alignof__", RID_ALIGNOF, 0 }, |
571 { "__asm", RID_ASM, 0 }, | 569 { "__asm", RID_ASM, 0 }, |
655 { "int", RID_INT, 0 }, | 653 { "int", RID_INT, 0 }, |
656 { "long", RID_LONG, 0 }, | 654 { "long", RID_LONG, 0 }, |
657 { "mutable", RID_MUTABLE, D_CXXONLY | D_CXXWARN }, | 655 { "mutable", RID_MUTABLE, D_CXXONLY | D_CXXWARN }, |
658 { "namespace", RID_NAMESPACE, D_CXXONLY | D_CXXWARN }, | 656 { "namespace", RID_NAMESPACE, D_CXXONLY | D_CXXWARN }, |
659 { "new", RID_NEW, D_CXXONLY | D_CXXWARN }, | 657 { "new", RID_NEW, D_CXXONLY | D_CXXWARN }, |
658 { "nullptr", RID_NULLPTR, D_CXXONLY | D_CXX0X | D_CXXWARN }, | |
660 { "operator", RID_OPERATOR, D_CXXONLY | D_CXXWARN }, | 659 { "operator", RID_OPERATOR, D_CXXONLY | D_CXXWARN }, |
661 { "private", RID_PRIVATE, D_CXX_OBJC | D_CXXWARN }, | 660 { "private", RID_PRIVATE, D_CXX_OBJC | D_CXXWARN }, |
662 { "protected", RID_PROTECTED, D_CXX_OBJC | D_CXXWARN }, | 661 { "protected", RID_PROTECTED, D_CXX_OBJC | D_CXXWARN }, |
663 { "public", RID_PUBLIC, D_CXX_OBJC | D_CXXWARN }, | 662 { "public", RID_PUBLIC, D_CXX_OBJC | D_CXXWARN }, |
664 { "register", RID_REGISTER, 0 }, | 663 { "register", RID_REGISTER, 0 }, |
827 handle_error_attribute }, | 826 handle_error_attribute }, |
828 { "target", 1, -1, true, false, false, | 827 { "target", 1, -1, true, false, false, |
829 handle_target_attribute }, | 828 handle_target_attribute }, |
830 { "optimize", 1, -1, true, false, false, | 829 { "optimize", 1, -1, true, false, false, |
831 handle_optimize_attribute }, | 830 handle_optimize_attribute }, |
831 /* For internal use (marking of builtins and runtime functions) only. | |
832 The name contains space to prevent its usage in source code. */ | |
833 { "fn spec", 1, 1, false, true, true, | |
834 handle_fnspec_attribute }, | |
832 { NULL, 0, 0, false, false, false, NULL } | 835 { NULL, 0, 0, false, false, false, NULL } |
833 }; | 836 }; |
834 | 837 |
835 /* Give the specifications for the format attributes, used by C and all | 838 /* Give the specifications for the format attributes, used by C and all |
836 descendants. */ | 839 descendants. */ |
2190 all the range of values of the integer type cannot be | 2193 all the range of values of the integer type cannot be |
2191 represented by the real type. */ | 2194 represented by the real type. */ |
2192 else if (TREE_CODE (expr_type) == INTEGER_TYPE | 2195 else if (TREE_CODE (expr_type) == INTEGER_TYPE |
2193 && TREE_CODE (type) == REAL_TYPE) | 2196 && TREE_CODE (type) == REAL_TYPE) |
2194 { | 2197 { |
2195 tree type_low_bound = TYPE_MIN_VALUE (expr_type); | 2198 tree type_low_bound, type_high_bound; |
2196 tree type_high_bound = TYPE_MAX_VALUE (expr_type); | 2199 REAL_VALUE_TYPE real_low_bound, real_high_bound; |
2197 REAL_VALUE_TYPE real_low_bound | 2200 |
2198 = real_value_from_int_cst (0, type_low_bound); | 2201 /* Don't warn about char y = 0xff; float x = (int) y; */ |
2199 REAL_VALUE_TYPE real_high_bound | 2202 expr = get_unwidened (expr, 0); |
2200 = real_value_from_int_cst (0, type_high_bound); | 2203 expr_type = TREE_TYPE (expr); |
2204 | |
2205 type_low_bound = TYPE_MIN_VALUE (expr_type); | |
2206 type_high_bound = TYPE_MAX_VALUE (expr_type); | |
2207 real_low_bound = real_value_from_int_cst (0, type_low_bound); | |
2208 real_high_bound = real_value_from_int_cst (0, type_high_bound); | |
2201 | 2209 |
2202 if (!exact_real_truncate (TYPE_MODE (type), &real_low_bound) | 2210 if (!exact_real_truncate (TYPE_MODE (type), &real_low_bound) |
2203 || !exact_real_truncate (TYPE_MODE (type), &real_high_bound)) | 2211 || !exact_real_truncate (TYPE_MODE (type), &real_high_bound)) |
2204 give_warning = true; | 2212 give_warning = true; |
2205 } | 2213 } |
3799 || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype)) | 3807 || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype)) |
3800 intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype), | 3808 intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype), |
3801 TYPE_UNSIGNED (sizetype)), intop); | 3809 TYPE_UNSIGNED (sizetype)), intop); |
3802 | 3810 |
3803 /* Replace the integer argument with a suitable product by the object size. | 3811 /* Replace the integer argument with a suitable product by the object size. |
3804 Do this multiplication as signed, then convert to the appropriate | 3812 Do this multiplication as signed, then convert to the appropriate type |
3805 type for the pointer operation. */ | 3813 for the pointer operation and disregard an overflow that occured only |
3806 intop = convert (sizetype, | 3814 because of the sign-extension change in the latter conversion. */ |
3807 build_binary_op (loc, | 3815 { |
3808 MULT_EXPR, intop, | 3816 tree t = build_binary_op (loc, |
3809 convert (TREE_TYPE (intop), size_exp), 1)); | 3817 MULT_EXPR, intop, |
3818 convert (TREE_TYPE (intop), size_exp), 1); | |
3819 intop = convert (sizetype, t); | |
3820 if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t)) | |
3821 intop = build_int_cst_wide (TREE_TYPE (intop), TREE_INT_CST_LOW (intop), | |
3822 TREE_INT_CST_HIGH (intop)); | |
3823 } | |
3810 | 3824 |
3811 /* Create the sum or difference. */ | 3825 /* Create the sum or difference. */ |
3812 if (resultcode == MINUS_EXPR) | 3826 if (resultcode == MINUS_EXPR) |
3813 intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop); | 3827 intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop); |
3814 | 3828 |
4383 else if (!COMPLETE_TYPE_P (type)) | 4397 else if (!COMPLETE_TYPE_P (type)) |
4384 { | 4398 { |
4385 if (complain) | 4399 if (complain) |
4386 error_at (loc, "invalid application of %qs to incomplete type %qT ", | 4400 error_at (loc, "invalid application of %qs to incomplete type %qT ", |
4387 op_name, type); | 4401 op_name, type); |
4388 value = size_zero_node; | 4402 return error_mark_node; |
4389 } | 4403 } |
4390 else | 4404 else |
4391 { | 4405 { |
4392 if (is_sizeof) | 4406 if (is_sizeof) |
4393 /* Convert in case a char is more than one unit. */ | 4407 /* Convert in case a char is more than one unit. */ |
5656 result = null_pointer_node; | 5670 result = null_pointer_node; |
5657 else | 5671 else |
5658 { | 5672 { |
5659 TREE_USED (label) = 1; | 5673 TREE_USED (label) = 1; |
5660 result = build1 (ADDR_EXPR, ptr_type_node, label); | 5674 result = build1 (ADDR_EXPR, ptr_type_node, label); |
5661 /* The current function in not necessarily uninlinable. | 5675 /* The current function is not necessarily uninlinable. |
5662 Computed gotos are incompatible with inlining, but the value | 5676 Computed gotos are incompatible with inlining, but the value |
5663 here could be used only in a diagnostic, for example. */ | 5677 here could be used only in a diagnostic, for example. */ |
5664 protected_set_expr_location (result, loc); | 5678 protected_set_expr_location (result, loc); |
5665 } | 5679 } |
5666 | 5680 |
5796 #undef DEF_ATTR_INT | 5810 #undef DEF_ATTR_INT |
5797 #undef DEF_ATTR_IDENT | 5811 #undef DEF_ATTR_IDENT |
5798 #undef DEF_ATTR_TREE_LIST | 5812 #undef DEF_ATTR_TREE_LIST |
5799 } | 5813 } |
5800 | 5814 |
5815 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain | |
5816 identifier as an argument, so the front end shouldn't look it up. */ | |
5817 | |
5818 bool | |
5819 attribute_takes_identifier_p (const_tree attr_id) | |
5820 { | |
5821 if (is_attribute_p ("mode", attr_id) | |
5822 || is_attribute_p ("format", attr_id) | |
5823 || is_attribute_p ("cleanup", attr_id)) | |
5824 return true; | |
5825 else | |
5826 return targetm.attribute_takes_identifier_p (attr_id); | |
5827 } | |
5828 | |
5801 /* Attribute handlers common to C front ends. */ | 5829 /* Attribute handlers common to C front ends. */ |
5802 | 5830 |
5803 /* Handle a "packed" attribute; arguments as in | 5831 /* Handle a "packed" attribute; arguments as in |
5804 struct attribute_spec.handler. */ | 5832 struct attribute_spec.handler. */ |
5805 | 5833 |
6114 if (TREE_CODE (node) == FUNCTION_DECL | 6142 if (TREE_CODE (node) == FUNCTION_DECL |
6115 || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node))) | 6143 || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node))) |
6116 { | 6144 { |
6117 TREE_USED (node) = 1; | 6145 TREE_USED (node) = 1; |
6118 DECL_PRESERVE_P (node) = 1; | 6146 DECL_PRESERVE_P (node) = 1; |
6147 if (TREE_CODE (node) == VAR_DECL) | |
6148 DECL_READ_P (node) = 1; | |
6119 } | 6149 } |
6120 else | 6150 else |
6121 { | 6151 { |
6122 warning (OPT_Wattributes, "%qE attribute ignored", name); | 6152 warning (OPT_Wattributes, "%qE attribute ignored", name); |
6123 *no_add_attrs = true; | 6153 *no_add_attrs = true; |
6140 if (TREE_CODE (decl) == PARM_DECL | 6170 if (TREE_CODE (decl) == PARM_DECL |
6141 || TREE_CODE (decl) == VAR_DECL | 6171 || TREE_CODE (decl) == VAR_DECL |
6142 || TREE_CODE (decl) == FUNCTION_DECL | 6172 || TREE_CODE (decl) == FUNCTION_DECL |
6143 || TREE_CODE (decl) == LABEL_DECL | 6173 || TREE_CODE (decl) == LABEL_DECL |
6144 || TREE_CODE (decl) == TYPE_DECL) | 6174 || TREE_CODE (decl) == TYPE_DECL) |
6145 TREE_USED (decl) = 1; | 6175 { |
6176 TREE_USED (decl) = 1; | |
6177 if (TREE_CODE (decl) == VAR_DECL | |
6178 || TREE_CODE (decl) == PARM_DECL) | |
6179 DECL_READ_P (decl) = 1; | |
6180 } | |
6146 else | 6181 else |
6147 { | 6182 { |
6148 warning (OPT_Wattributes, "%qE attribute ignored", name); | 6183 warning (OPT_Wattributes, "%qE attribute ignored", name); |
6149 *no_add_attrs = true; | 6184 *no_add_attrs = true; |
6150 } | 6185 } |
6245 /* A type variant isn't good enough, since we don't a cast | 6280 /* A type variant isn't good enough, since we don't a cast |
6246 to such a type removed as a no-op. */ | 6281 to such a type removed as a no-op. */ |
6247 *node = type = build_duplicate_type (type); | 6282 *node = type = build_duplicate_type (type); |
6248 } | 6283 } |
6249 | 6284 |
6250 TYPE_TRANSPARENT_UNION (type) = 1; | 6285 TYPE_TRANSPARENT_AGGR (type) = 1; |
6251 return NULL_TREE; | 6286 return NULL_TREE; |
6252 } | 6287 } |
6253 | 6288 |
6254 ignored: | 6289 ignored: |
6255 warning (OPT_Wattributes, "%qE attribute ignored", name); | 6290 warning (OPT_Wattributes, "%qE attribute ignored", name); |
6658 error ("requested alignment is too large"); | 6693 error ("requested alignment is too large"); |
6659 *no_add_attrs = true; | 6694 *no_add_attrs = true; |
6660 } | 6695 } |
6661 else if (is_type) | 6696 else if (is_type) |
6662 { | 6697 { |
6698 if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) | |
6699 /* OK, modify the type in place. */; | |
6663 /* If we have a TYPE_DECL, then copy the type, so that we | 6700 /* If we have a TYPE_DECL, then copy the type, so that we |
6664 don't accidentally modify a builtin type. See pushdecl. */ | 6701 don't accidentally modify a builtin type. See pushdecl. */ |
6665 if (decl && TREE_TYPE (decl) != error_mark_node | 6702 else if (decl && TREE_TYPE (decl) != error_mark_node |
6666 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE) | 6703 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE) |
6667 { | 6704 { |
6668 tree tt = TREE_TYPE (decl); | 6705 tree tt = TREE_TYPE (decl); |
6669 *type = build_variant_type_copy (*type); | 6706 *type = build_variant_type_copy (*type); |
6670 DECL_ORIGINAL_TYPE (decl) = tt; | 6707 DECL_ORIGINAL_TYPE (decl) = tt; |
6671 TYPE_NAME (*type) = decl; | 6708 TYPE_NAME (*type) = decl; |
6672 TREE_USED (*type) = TREE_USED (decl); | 6709 TREE_USED (*type) = TREE_USED (decl); |
6673 TREE_TYPE (decl) = *type; | 6710 TREE_TYPE (decl) = *type; |
6674 } | 6711 } |
6675 else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) | 6712 else |
6676 *type = build_variant_type_copy (*type); | 6713 *type = build_variant_type_copy (*type); |
6677 | 6714 |
6678 TYPE_ALIGN (*type) = (1U << i) * BITS_PER_UNIT; | 6715 TYPE_ALIGN (*type) = (1U << i) * BITS_PER_UNIT; |
6679 TYPE_USER_ALIGN (*type) = 1; | 6716 TYPE_USER_ALIGN (*type) = 1; |
6680 } | 6717 } |
7099 "alloc_size parameter outside range"); | 7136 "alloc_size parameter outside range"); |
7100 *no_add_attrs = true; | 7137 *no_add_attrs = true; |
7101 return NULL_TREE; | 7138 return NULL_TREE; |
7102 } | 7139 } |
7103 } | 7140 } |
7141 return NULL_TREE; | |
7142 } | |
7143 | |
7144 /* Handle a "fn spec" attribute; arguments as in | |
7145 struct attribute_spec.handler. */ | |
7146 | |
7147 static tree | |
7148 handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name), | |
7149 tree args, int ARG_UNUSED (flags), | |
7150 bool *no_add_attrs ATTRIBUTE_UNUSED) | |
7151 { | |
7152 gcc_assert (args | |
7153 && TREE_CODE (TREE_VALUE (args)) == STRING_CST | |
7154 && !TREE_CHAIN (args)); | |
7104 return NULL_TREE; | 7155 return NULL_TREE; |
7105 } | 7156 } |
7106 | 7157 |
7107 /* Handle a "returns_twice" attribute; arguments as in | 7158 /* Handle a "returns_twice" attribute; arguments as in |
7108 struct attribute_spec.handler. */ | 7159 struct attribute_spec.handler. */ |
7973 } | 8024 } |
7974 | 8025 |
7975 (*callback) (ctx, param, param_num); | 8026 (*callback) (ctx, param, param_num); |
7976 } | 8027 } |
7977 | 8028 |
7978 /* Checks the number of arguments NARGS against the required number | 8029 /* Checks for a builtin function FNDECL that the number of arguments |
7979 REQUIRED and issues an error if there is a mismatch. Returns true | 8030 NARGS against the required number REQUIRED and issues an error if |
7980 if the number of arguments is correct, otherwise false. */ | 8031 there is a mismatch. Returns true if the number of arguments is |
8032 correct, otherwise false. */ | |
7981 | 8033 |
7982 static bool | 8034 static bool |
7983 validate_nargs (tree fndecl, int nargs, int required) | 8035 builtin_function_validate_nargs (tree fndecl, int nargs, int required) |
7984 { | 8036 { |
7985 if (nargs < required) | 8037 if (nargs < required) |
7986 { | 8038 { |
7987 error ("not enough arguments to function %qE", fndecl); | 8039 error_at (input_location, |
8040 "not enough arguments to function %qE", fndecl); | |
7988 return false; | 8041 return false; |
7989 } | 8042 } |
7990 else if (nargs > required) | 8043 else if (nargs > required) |
7991 { | 8044 { |
7992 error ("too many arguments to function %qE", fndecl); | 8045 error_at (input_location, |
8046 "too many arguments to function %qE", fndecl); | |
7993 return false; | 8047 return false; |
7994 } | 8048 } |
7995 return true; | 8049 return true; |
7996 } | 8050 } |
7997 | 8051 |
8006 return true; | 8060 return true; |
8007 | 8061 |
8008 switch (DECL_FUNCTION_CODE (fndecl)) | 8062 switch (DECL_FUNCTION_CODE (fndecl)) |
8009 { | 8063 { |
8010 case BUILT_IN_CONSTANT_P: | 8064 case BUILT_IN_CONSTANT_P: |
8011 return validate_nargs (fndecl, nargs, 1); | 8065 return builtin_function_validate_nargs (fndecl, nargs, 1); |
8012 | 8066 |
8013 case BUILT_IN_ISFINITE: | 8067 case BUILT_IN_ISFINITE: |
8014 case BUILT_IN_ISINF: | 8068 case BUILT_IN_ISINF: |
8015 case BUILT_IN_ISINF_SIGN: | 8069 case BUILT_IN_ISINF_SIGN: |
8016 case BUILT_IN_ISNAN: | 8070 case BUILT_IN_ISNAN: |
8017 case BUILT_IN_ISNORMAL: | 8071 case BUILT_IN_ISNORMAL: |
8018 if (validate_nargs (fndecl, nargs, 1)) | 8072 if (builtin_function_validate_nargs (fndecl, nargs, 1)) |
8019 { | 8073 { |
8020 if (TREE_CODE (TREE_TYPE (args[0])) != REAL_TYPE) | 8074 if (TREE_CODE (TREE_TYPE (args[0])) != REAL_TYPE) |
8021 { | 8075 { |
8022 error ("non-floating-point argument in call to " | 8076 error ("non-floating-point argument in call to " |
8023 "function %qE", fndecl); | 8077 "function %qE", fndecl); |
8031 case BUILT_IN_ISGREATEREQUAL: | 8085 case BUILT_IN_ISGREATEREQUAL: |
8032 case BUILT_IN_ISLESS: | 8086 case BUILT_IN_ISLESS: |
8033 case BUILT_IN_ISLESSEQUAL: | 8087 case BUILT_IN_ISLESSEQUAL: |
8034 case BUILT_IN_ISLESSGREATER: | 8088 case BUILT_IN_ISLESSGREATER: |
8035 case BUILT_IN_ISUNORDERED: | 8089 case BUILT_IN_ISUNORDERED: |
8036 if (validate_nargs (fndecl, nargs, 2)) | 8090 if (builtin_function_validate_nargs (fndecl, nargs, 2)) |
8037 { | 8091 { |
8038 enum tree_code code0, code1; | 8092 enum tree_code code0, code1; |
8039 code0 = TREE_CODE (TREE_TYPE (args[0])); | 8093 code0 = TREE_CODE (TREE_TYPE (args[0])); |
8040 code1 = TREE_CODE (TREE_TYPE (args[1])); | 8094 code1 = TREE_CODE (TREE_TYPE (args[1])); |
8041 if (!((code0 == REAL_TYPE && code1 == REAL_TYPE) | 8095 if (!((code0 == REAL_TYPE && code1 == REAL_TYPE) |
8049 return true; | 8103 return true; |
8050 } | 8104 } |
8051 return false; | 8105 return false; |
8052 | 8106 |
8053 case BUILT_IN_FPCLASSIFY: | 8107 case BUILT_IN_FPCLASSIFY: |
8054 if (validate_nargs (fndecl, nargs, 6)) | 8108 if (builtin_function_validate_nargs (fndecl, nargs, 6)) |
8055 { | 8109 { |
8056 unsigned i; | 8110 unsigned i; |
8057 | 8111 |
8058 for (i=0; i<5; i++) | 8112 for (i=0; i<5; i++) |
8059 if (TREE_CODE (args[i]) != INTEGER_CST) | 8113 if (TREE_CODE (args[i]) != INTEGER_CST) |
8243 free (message); | 8297 free (message); |
8244 } | 8298 } |
8245 #undef catenate_messages | 8299 #undef catenate_messages |
8246 } | 8300 } |
8247 | 8301 |
8302 /* Mapping for cpp message reasons to the options that enable them. */ | |
8303 | |
8304 struct reason_option_codes_t | |
8305 { | |
8306 const int reason; /* cpplib message reason. */ | |
8307 const int option_code; /* gcc option that controls this message. */ | |
8308 }; | |
8309 | |
8310 static const struct reason_option_codes_t option_codes[] = { | |
8311 {CPP_W_DEPRECATED, OPT_Wdeprecated}, | |
8312 {CPP_W_COMMENTS, OPT_Wcomments}, | |
8313 {CPP_W_TRIGRAPHS, OPT_Wtrigraphs}, | |
8314 {CPP_W_MULTICHAR, OPT_Wmultichar}, | |
8315 {CPP_W_TRADITIONAL, OPT_Wtraditional}, | |
8316 {CPP_W_LONG_LONG, OPT_Wlong_long}, | |
8317 {CPP_W_ENDIF_LABELS, OPT_Wendif_labels}, | |
8318 {CPP_W_VARIADIC_MACROS, OPT_Wvariadic_macros}, | |
8319 {CPP_W_BUILTIN_MACRO_REDEFINED, OPT_Wbuiltin_macro_redefined}, | |
8320 {CPP_W_UNDEF, OPT_Wundef}, | |
8321 {CPP_W_UNUSED_MACROS, OPT_Wunused_macros}, | |
8322 {CPP_W_CXX_OPERATOR_NAMES, OPT_Wc___compat}, | |
8323 {CPP_W_NORMALIZE, OPT_Wnormalized_}, | |
8324 {CPP_W_INVALID_PCH, OPT_Winvalid_pch}, | |
8325 {CPP_W_WARNING_DIRECTIVE, OPT_Wcpp}, | |
8326 {CPP_W_NONE, 0} | |
8327 }; | |
8328 | |
8329 /* Return the gcc option code associated with the reason for a cpp | |
8330 message, or 0 if none. */ | |
8331 | |
8332 static int | |
8333 c_option_controlling_cpp_error (int reason) | |
8334 { | |
8335 const struct reason_option_codes_t *entry; | |
8336 | |
8337 for (entry = option_codes; entry->reason != CPP_W_NONE; entry++) | |
8338 { | |
8339 if (entry->reason == reason) | |
8340 return entry->option_code; | |
8341 } | |
8342 return 0; | |
8343 } | |
8344 | |
8248 /* Callback from cpp_error for PFILE to print diagnostics from the | 8345 /* Callback from cpp_error for PFILE to print diagnostics from the |
8249 preprocessor. The diagnostic is of type LEVEL, at location | 8346 preprocessor. The diagnostic is of type LEVEL, with REASON set |
8347 to the reason code if LEVEL is represents a warning, at location | |
8250 LOCATION unless this is after lexing and the compiler's location | 8348 LOCATION unless this is after lexing and the compiler's location |
8251 should be used instead, with column number possibly overridden by | 8349 should be used instead, with column number possibly overridden by |
8252 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP | 8350 COLUMN_OVERRIDE if not zero; MSG is the translated message and AP |
8253 the arguments. Returns true if a diagnostic was emitted, false | 8351 the arguments. Returns true if a diagnostic was emitted, false |
8254 otherwise. */ | 8352 otherwise. */ |
8255 | 8353 |
8256 bool | 8354 bool |
8257 c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, | 8355 c_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason, |
8258 location_t location, unsigned int column_override, | 8356 location_t location, unsigned int column_override, |
8259 const char *msg, va_list *ap) | 8357 const char *msg, va_list *ap) |
8260 { | 8358 { |
8261 diagnostic_info diagnostic; | 8359 diagnostic_info diagnostic; |
8262 diagnostic_t dlevel; | 8360 diagnostic_t dlevel; |
8299 location = input_location; | 8397 location = input_location; |
8300 diagnostic_set_info_translated (&diagnostic, msg, ap, | 8398 diagnostic_set_info_translated (&diagnostic, msg, ap, |
8301 location, dlevel); | 8399 location, dlevel); |
8302 if (column_override) | 8400 if (column_override) |
8303 diagnostic_override_column (&diagnostic, column_override); | 8401 diagnostic_override_column (&diagnostic, column_override); |
8402 diagnostic_override_option_index (&diagnostic, | |
8403 c_option_controlling_cpp_error (reason)); | |
8304 ret = report_diagnostic (&diagnostic); | 8404 ret = report_diagnostic (&diagnostic); |
8305 if (level == CPP_DL_WARNING_SYSHDR) | 8405 if (level == CPP_DL_WARNING_SYSHDR) |
8306 warn_system_headers = save_warn_system_headers; | 8406 warn_system_headers = save_warn_system_headers; |
8307 return ret; | 8407 return ret; |
8308 } | 8408 } |
8676 static bool | 8776 static bool |
8677 sync_resolve_params (tree orig_function, tree function, VEC(tree, gc) *params) | 8777 sync_resolve_params (tree orig_function, tree function, VEC(tree, gc) *params) |
8678 { | 8778 { |
8679 tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); | 8779 tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); |
8680 tree ptype; | 8780 tree ptype; |
8681 int number; | |
8682 unsigned int parmnum; | 8781 unsigned int parmnum; |
8683 | 8782 |
8684 /* We've declared the implementation functions to use "volatile void *" | 8783 /* We've declared the implementation functions to use "volatile void *" |
8685 as the pointer parameter, so we shouldn't get any complaints from the | 8784 as the pointer parameter, so we shouldn't get any complaints from the |
8686 call to check_function_arguments what ever type the user used. */ | 8785 call to check_function_arguments what ever type the user used. */ |
8687 arg_types = TREE_CHAIN (arg_types); | 8786 arg_types = TREE_CHAIN (arg_types); |
8688 ptype = TREE_TYPE (TREE_TYPE (VEC_index (tree, params, 0))); | 8787 ptype = TREE_TYPE (TREE_TYPE (VEC_index (tree, params, 0))); |
8689 number = 2; | |
8690 | 8788 |
8691 /* For the rest of the values, we need to cast these to FTYPE, so that we | 8789 /* For the rest of the values, we need to cast these to FTYPE, so that we |
8692 don't get warnings for passing pointer types, etc. */ | 8790 don't get warnings for passing pointer types, etc. */ |
8693 parmnum = 0; | 8791 parmnum = 0; |
8694 while (arg_types != void_list_node) | 8792 while (arg_types != void_list_node) |
8709 val = convert (ptype, val); | 8807 val = convert (ptype, val); |
8710 val = convert (TREE_VALUE (arg_types), val); | 8808 val = convert (TREE_VALUE (arg_types), val); |
8711 VEC_replace (tree, params, parmnum, val); | 8809 VEC_replace (tree, params, parmnum, val); |
8712 | 8810 |
8713 arg_types = TREE_CHAIN (arg_types); | 8811 arg_types = TREE_CHAIN (arg_types); |
8714 number++; | |
8715 } | 8812 } |
8716 | 8813 |
8717 /* The definition of these primitives is variadic, with the remaining | 8814 /* The definition of these primitives is variadic, with the remaining |
8718 being "an optional list of variables protected by the memory barrier". | 8815 being "an optional list of variables protected by the memory barrier". |
8719 No clue what that's supposed to mean, precisely, but we consider all | 8816 No clue what that's supposed to mean, precisely, but we consider all |