From 0a68165a0a81e66224f596a3eeb36b0c7541a44a Mon Sep 17 00:00:00 2001 From: hubicka Date: Fri, 24 Jan 2003 22:07:01 +0000 Subject: [PATCH] * builtins.c (DEF_BUILTIN): Accept 10 arguments. (implicit_built_in_decls): New global array. (mathfn_built_in): New global function. (fold_trunc_transparent_mathfn): New static function (expand_builtin_strstr, expand_bultin_strchr, expand_builtin_strpbrk, expand_builtin_strcpy, expand_builtin_strncpy, expand_bultin_strcmp, expand_bultin_strncat, expand_builtin_fputs): Use implicint_built_in_decls. (fold_builtin): Fold floor/trunc/round/ceil/nearbyint. * builtins.def: Fix comments. (DEF_GCC_BUILTIN, DEF_FALLBACK_BUILTIN, DEF_EXT_FALLBACK_BUILTIN, DEF_LIB_BUILTIN, DEF_LIB_ALWAYS_BUILTIN, DEF_EXT_LIB_BUILTIN, DEF_C99_BULTIN, DEF_FRONT_END_LIB_BUILTIN, DEF_EXT_FRONT_END_LIB_BUILTIN): Pass implicit as needed. (DEF_C99_C90RES_BULTIN): New. (*f, *l builtins): Update. * c-common.c (DEF_BUILTIN): Initialize implicit array. (c_expand_builtin_printf, c_expand_builtin_fprintf): Update. * convert.c (strip_float_extensions): New global function. * tree.h (DEF_BUILTIN): Accept 10 arguments. (implicit_built_in_decls, mathfn_built_in, strip_float_extension): Declare. * java/builtins.c (define_builtin): Handle implicit. (DEF_BUILTIN): Update. * tm.texi (TARGET_C99_FUNCTIONS): Document. * defaults.h (TARGET_C99_FUNCTIONS): Default to 0. * config/linux.h (TARGET_C99_FUNCTIONS): Default to 1 when using glibc2. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@61738 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 32 ++++++++ gcc/builtins.c | 197 ++++++++++++++++++++++++++++++++++++++++++++---- gcc/builtins.def | 210 ++++++++++++++++++++++++++++------------------------ gcc/c-common.c | 12 +-- gcc/config/linux.h | 7 ++ gcc/defaults.h | 6 ++ gcc/doc/tm.texi | 9 +++ gcc/java/builtins.c | 11 ++- gcc/tree.h | 5 +- 9 files changed, 367 insertions(+), 122 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b0c808d1d1f..de8a841d2bf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,35 @@ +Fri Jan 24 23:03:32 CET 2003 Jan Hubicka + + * builtins.c (DEF_BUILTIN): Accept 10 arguments. + (implicit_built_in_decls): New global array. + (mathfn_built_in): New global function. + (fold_trunc_transparent_mathfn): New static function + (expand_builtin_strstr, expand_bultin_strchr, + expand_builtin_strpbrk, expand_builtin_strcpy, + expand_builtin_strncpy, expand_bultin_strcmp, + expand_bultin_strncat, expand_builtin_fputs): Use + implicint_built_in_decls. + (fold_builtin): Fold floor/trunc/round/ceil/nearbyint. + * builtins.def: Fix comments. + (DEF_GCC_BUILTIN, DEF_FALLBACK_BUILTIN, DEF_EXT_FALLBACK_BUILTIN, + DEF_LIB_BUILTIN, DEF_LIB_ALWAYS_BUILTIN, DEF_EXT_LIB_BUILTIN, + DEF_C99_BULTIN, DEF_FRONT_END_LIB_BUILTIN, + DEF_EXT_FRONT_END_LIB_BUILTIN): Pass implicit as needed. + (DEF_C99_C90RES_BULTIN): New. + (*f, *l builtins): Update. + * c-common.c (DEF_BUILTIN): Initialize implicit array. + (c_expand_builtin_printf, c_expand_builtin_fprintf): Update. + * convert.c (strip_float_extensions): New global function. + * tree.h (DEF_BUILTIN): Accept 10 arguments. + (implicit_built_in_decls, mathfn_built_in, strip_float_extension): + Declare. + * java/builtins.c (define_builtin): Handle implicit. + (DEF_BUILTIN): Update. + * tm.texi (TARGET_C99_FUNCTIONS): Document. + * defaults.h (TARGET_C99_FUNCTIONS): Default to 0. + * config/linux.h (TARGET_C99_FUNCTIONS): Default to 1 + when using glibc2. + 2003-01-24 Bob Wilson * config.gcc (xtensa-*-elf*): Removed assignments to with_newlib, diff --git a/gcc/builtins.c b/gcc/builtins.c index 5e72df6b9fe..bb1f023f272 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -64,7 +64,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA const char *const built_in_class_names[4] = {"NOT_BUILT_IN", "BUILT_IN_FRONTEND", "BUILT_IN_MD", "BUILT_IN_NORMAL"}; -#define DEF_BUILTIN(X, N, C, T, LT, B, F, NA, AT) STRINGX(X), +#define DEF_BUILTIN(X, N, C, T, LT, B, F, NA, AT, IM) STRINGX(X), const char *const built_in_names[(int) END_BUILTINS] = { #include "builtins.def" @@ -74,6 +74,10 @@ const char *const built_in_names[(int) END_BUILTINS] = /* Setup an array of _DECL trees, make sure each element is initialized to NULL_TREE. */ tree built_in_decls[(int) END_BUILTINS]; +/* Declarations used when constructing the builtin implicitly in the compiler. + It may be NULL_TREE when this is invalid (for instance runtime is not + required to implement the function call in all cases. */ +tree implicit_built_in_decls[(int) END_BUILTINS]; static int get_pointer_alignment PARAMS ((tree, unsigned int)); static tree c_strlen PARAMS ((tree)); @@ -153,6 +157,7 @@ static tree fold_builtin_classify_type PARAMS ((tree)); static tree fold_builtin_inf PARAMS ((tree, int)); static tree fold_builtin_nan PARAMS ((tree, tree, int)); static int validate_arglist PARAMS ((tree, ...)); +static tree fold_trunc_transparent_mathfn PARAMS ((tree)); /* Return the alignment in bits of EXP, a pointer valued expression. But don't return more than MAX_ALIGN no matter what. @@ -1469,6 +1474,170 @@ expand_builtin_constant_p (exp) return tmp; } +/* Return mathematic function equivalent to FN but operating directly on TYPE, + if available. */ +tree +mathfn_built_in (type, fn) + tree type; + enum built_in_function fn; +{ + enum built_in_function fcode = NOT_BUILT_IN; + if (TYPE_MODE (type) == TYPE_MODE (double_type_node)) + switch (fn) + { + case BUILT_IN_SQRT: + case BUILT_IN_SQRTF: + case BUILT_IN_SQRTL: + fcode = BUILT_IN_SQRT; + break; + case BUILT_IN_SIN: + case BUILT_IN_SINF: + case BUILT_IN_SINL: + fcode = BUILT_IN_SIN; + break; + case BUILT_IN_COS: + case BUILT_IN_COSF: + case BUILT_IN_COSL: + fcode = BUILT_IN_COS; + break; + case BUILT_IN_EXP: + case BUILT_IN_EXPF: + case BUILT_IN_EXPL: + fcode = BUILT_IN_EXP; + break; + case BUILT_IN_FLOOR: + case BUILT_IN_FLOORF: + case BUILT_IN_FLOORL: + fcode = BUILT_IN_FLOOR; + break; + case BUILT_IN_CEIL: + case BUILT_IN_CEILF: + case BUILT_IN_CEILL: + fcode = BUILT_IN_CEIL; + break; + case BUILT_IN_TRUNC: + case BUILT_IN_TRUNCF: + case BUILT_IN_TRUNCL: + fcode = BUILT_IN_TRUNC; + break; + case BUILT_IN_ROUND: + case BUILT_IN_ROUNDF: + case BUILT_IN_ROUNDL: + fcode = BUILT_IN_ROUND; + break; + case BUILT_IN_NEARBYINT: + case BUILT_IN_NEARBYINTF: + case BUILT_IN_NEARBYINTL: + fcode = BUILT_IN_NEARBYINT; + break; + default: + abort (); + } + else if (TYPE_MODE (type) == TYPE_MODE (float_type_node)) + switch (fn) + { + case BUILT_IN_SQRT: + case BUILT_IN_SQRTF: + case BUILT_IN_SQRTL: + fcode = BUILT_IN_SQRTF; + break; + case BUILT_IN_SIN: + case BUILT_IN_SINF: + case BUILT_IN_SINL: + fcode = BUILT_IN_SINF; + break; + case BUILT_IN_COS: + case BUILT_IN_COSF: + case BUILT_IN_COSL: + fcode = BUILT_IN_COSF; + break; + case BUILT_IN_EXP: + case BUILT_IN_EXPF: + case BUILT_IN_EXPL: + fcode = BUILT_IN_EXPF; + break; + case BUILT_IN_FLOOR: + case BUILT_IN_FLOORF: + case BUILT_IN_FLOORL: + fcode = BUILT_IN_FLOORF; + break; + case BUILT_IN_CEIL: + case BUILT_IN_CEILF: + case BUILT_IN_CEILL: + fcode = BUILT_IN_CEILF; + break; + case BUILT_IN_TRUNC: + case BUILT_IN_TRUNCF: + case BUILT_IN_TRUNCL: + fcode = BUILT_IN_TRUNCF; + break; + case BUILT_IN_ROUND: + case BUILT_IN_ROUNDF: + case BUILT_IN_ROUNDL: + fcode = BUILT_IN_ROUNDF; + break; + case BUILT_IN_NEARBYINT: + case BUILT_IN_NEARBYINTF: + case BUILT_IN_NEARBYINTL: + fcode = BUILT_IN_NEARBYINTF; + break; + default: + abort (); + } + else if (TYPE_MODE (type) == TYPE_MODE (long_double_type_node)) + switch (fn) + { + case BUILT_IN_SQRT: + case BUILT_IN_SQRTF: + case BUILT_IN_SQRTL: + fcode = BUILT_IN_SQRTL; + break; + case BUILT_IN_SIN: + case BUILT_IN_SINF: + case BUILT_IN_SINL: + fcode = BUILT_IN_SINL; + break; + case BUILT_IN_COS: + case BUILT_IN_COSF: + case BUILT_IN_COSL: + fcode = BUILT_IN_COSL; + break; + case BUILT_IN_EXP: + case BUILT_IN_EXPF: + case BUILT_IN_EXPL: + fcode = BUILT_IN_EXPL; + break; + case BUILT_IN_FLOOR: + case BUILT_IN_FLOORF: + case BUILT_IN_FLOORL: + fcode = BUILT_IN_FLOORL; + break; + case BUILT_IN_CEIL: + case BUILT_IN_CEILF: + case BUILT_IN_CEILL: + fcode = BUILT_IN_CEILL; + break; + case BUILT_IN_TRUNC: + case BUILT_IN_TRUNCF: + case BUILT_IN_TRUNCL: + fcode = BUILT_IN_TRUNCL; + break; + case BUILT_IN_ROUND: + case BUILT_IN_ROUNDF: + case BUILT_IN_ROUNDL: + fcode = BUILT_IN_ROUNDL; + break; + case BUILT_IN_NEARBYINT: + case BUILT_IN_NEARBYINTF: + case BUILT_IN_NEARBYINTL: + fcode = BUILT_IN_NEARBYINTL; + break; + default: + abort (); + } + return implicit_built_in_decls[fcode]; +} + /* Expand a call to one of the builtin math functions (sin, cos, or sqrt). Return 0 if a normal call should be emitted rather than expanding the function in-line. EXP is the expression that is a call to the builtin @@ -1756,7 +1925,7 @@ expand_builtin_strstr (arglist, target, mode) if (p2[1] != '\0') return 0; - fn = built_in_decls[BUILT_IN_STRCHR]; + fn = implicit_built_in_decls[BUILT_IN_STRCHR]; if (!fn) return 0; @@ -1860,7 +2029,7 @@ expand_builtin_strrchr (arglist, target, mode) if (! integer_zerop (s2)) return 0; - fn = built_in_decls[BUILT_IN_STRCHR]; + fn = implicit_built_in_decls[BUILT_IN_STRCHR]; if (!fn) return 0; @@ -1918,7 +2087,7 @@ expand_builtin_strpbrk (arglist, target, mode) if (p2[1] != '\0') return 0; /* Really call strpbrk. */ - fn = built_in_decls[BUILT_IN_STRCHR]; + fn = implicit_built_in_decls[BUILT_IN_STRCHR]; if (!fn) return 0; @@ -2057,7 +2226,7 @@ expand_builtin_strcpy (exp, target, mode) if (!validate_arglist (arglist, POINTER_TYPE, POINTER_TYPE, VOID_TYPE)) return 0; - fn = built_in_decls[BUILT_IN_MEMCPY]; + fn = implicit_built_in_decls[BUILT_IN_MEMCPY]; if (!fn) return 0; @@ -2159,7 +2328,7 @@ expand_builtin_strncpy (arglist, target, mode) } /* OK transform into builtin memcpy. */ - fn = built_in_decls[BUILT_IN_MEMCPY]; + fn = implicit_built_in_decls[BUILT_IN_MEMCPY]; if (!fn) return 0; return expand_expr (build_function_call_expr (fn, arglist), @@ -2575,7 +2744,7 @@ expand_builtin_strcmp (exp, target, mode) if (TREE_SIDE_EFFECTS (len)) return 0; - fn = built_in_decls[BUILT_IN_MEMCMP]; + fn = implicit_built_in_decls[BUILT_IN_MEMCMP]; if (!fn) return 0; @@ -2669,7 +2838,7 @@ expand_builtin_strncmp (exp, target, mode) if (!len) return 0; - fn = built_in_decls[BUILT_IN_MEMCMP]; + fn = implicit_built_in_decls[BUILT_IN_MEMCMP]; if (!fn) return 0; @@ -2750,7 +2919,7 @@ expand_builtin_strncat (arglist, target, mode) { tree newarglist = tree_cons (NULL_TREE, dst, build_tree_list (NULL_TREE, src)); - tree fn = built_in_decls[BUILT_IN_STRCAT]; + tree fn = implicit_built_in_decls[BUILT_IN_STRCAT]; /* If the replacement _DECL isn't initialized, don't do the transformation. */ @@ -2838,7 +3007,7 @@ expand_builtin_strcspn (arglist, target, mode) if (p2 && *p2 == '\0') { tree newarglist = build_tree_list (NULL_TREE, s1), - fn = built_in_decls[BUILT_IN_STRLEN]; + fn = implicit_built_in_decls[BUILT_IN_STRLEN]; /* If the replacement _DECL isn't initialized, don't do the transformation. */ @@ -3445,10 +3614,10 @@ expand_builtin_fputs (arglist, ignore, unlocked) int unlocked; { tree len, fn; - tree fn_fputc = unlocked ? built_in_decls[BUILT_IN_FPUTC_UNLOCKED] - : built_in_decls[BUILT_IN_FPUTC]; - tree fn_fwrite = unlocked ? built_in_decls[BUILT_IN_FWRITE_UNLOCKED] - : built_in_decls[BUILT_IN_FWRITE]; + tree fn_fputc = unlocked ? implicit_built_in_decls[BUILT_IN_FPUTC_UNLOCKED] + : implicit_built_in_decls[BUILT_IN_FPUTC]; + tree fn_fwrite = unlocked ? implicit_built_in_decls[BUILT_IN_FWRITE_UNLOCKED] + : implicit_built_in_decls[BUILT_IN_FWRITE]; /* If the return value is used, or the replacement _DECL isn't initialized, don't do the transformation. */ diff --git a/gcc/builtins.def b/gcc/builtins.def index 44297457899..23a69df8b67 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -22,7 +22,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA /* Before including this file, you should define a macro: DEF_BUILTIN (ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, - FALLBACK_P, NONANSI_P, ATTRS) + FALLBACK_P, NONANSI_P, ATTRS, IMPLICIT) This macro will be called once for each builtin function. The ENUM will be of type `enum built_in_function', and will indicate @@ -53,7 +53,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA exist when compiling in ANSI conformant mode. ATTRs is an attribute list as defined in builtin-attrs.def that - describes the attributes of this builtin function. */ + describes the attributes of this builtin function. + + IMPLICIT specifies condition when the builtin can be produced by + compiler. For instance C90 reserves floorf function, but does not + define it's meaning. When user uses floorf we may assume that the + floorf has the meaning we expect, but we can't produce floorf by + simplifing floor((double)float) since runtime don't need to implement it. */ /* A GCC builtin (like __builtin_saveregs) is provided by the compiler, but does not correspond to a function in the standard @@ -61,7 +67,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #undef DEF_GCC_BUILTIN #define DEF_GCC_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, BT_LAST, \ - false, false, false, ATTRS) + false, false, false, ATTRS, true) /* A fallback builtin is a builtin (like __builtin_puts) that falls @@ -71,7 +77,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #undef DEF_FALLBACK_BUILTIN #define DEF_FALLBACK_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ - false, true, false, ATTRS) + false, true, false, ATTRS, true) /* Like DEF_FALLBACK_BUILTIN, except that the function is not one that is specified by ANSI/ISO C. So, when we're being fully conformant @@ -80,7 +86,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #undef DEF_EXT_FALLBACK_BUILTIN #define DEF_EXT_FALLBACK_BUILTIN(ENUM, NAME, TYPE) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ - false, true, true, ATTR_NOTHROW_LIST) + false, true, true, ATTR_NOTHROW_LIST, true) /* A library builtin (like __builtin_strchr) is a builtin equivalent of an ANSI/ISO standard library function. In addition to the @@ -91,14 +97,14 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #undef DEF_LIB_BUILTIN #define DEF_LIB_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ - true, true, false, ATTRS) + true, true, false, ATTRS, true) /* Like DEF_LIB_BUILTIN, except that a call to the builtin should never fall back to the library version. */ #undef DEF_LIB_ALWAYS_BUILTIN #define DEF_LIB_ALWAYS_BUILTIN(ENUM, NAME, TYPE) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ - true, false, true, ATTR_CONST_NOTHROW_LIST) + true, false, true, ATTR_CONST_NOTHROW_LIST, true) /* Like DEF_LIB_BUILTIN, except that the function is not one that is specified by ANSI/ISO C. So, when we're being fully conformant we @@ -107,21 +113,29 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #undef DEF_EXT_LIB_BUILTIN #define DEF_EXT_LIB_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ - true, true, true, ATTRS) + true, true, true, ATTRS, false) /* Like DEF_LIB_BUILTIN, except that the function is only a part of the standard in C99 or above. */ #undef DEF_C99_BUILTIN #define DEF_C99_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ - true, true, !flag_isoc99, ATTRS) + true, true, !flag_isoc99, ATTRS, TARGET_C99_FUNCTIONS) + +/* Builtin that is specified by C99 and C90 reserve the name for future use. + We can still recognize the builtin in C90 mode but we can't produce it + implicitly. */ +#undef DEF_C99_C90RES_BUILTIN +#define DEF_C99_C90RES_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ + DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ + true, true, !flag_isoc99, ATTRS, TARGET_C99_FUNCTIONS) /* Like DEF_LIB_BUILTIN, except that the function is expanded in the front-end. */ #undef DEF_FRONT_END_LIB_BUILTIN #define DEF_FRONT_END_LIB_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_FRONTEND, TYPE, TYPE, \ - true, true, false, ATTRS) + true, true, false, ATTRS, true) /* Like DEF_FRONT_END_LIB_BUILTIN, except that the function is not one that is specified by ANSI/ISO C. So, when we're being fully @@ -130,13 +144,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #undef DEF_EXT_FRONT_END_LIB_BUILTIN #define DEF_EXT_FRONT_END_LIB_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_FRONTEND, TYPE, TYPE, \ - true, true, true, ATTRS) + true, true, true, ATTRS, true) /* A built-in that is not currently used. */ #undef DEF_UNUSED_BUILTIN #define DEF_UNUSED_BUILTIN(X) \ DEF_BUILTIN (X, (const char *) NULL, NOT_BUILT_IN, BT_LAST, \ - BT_LAST, false, false, false, ATTR_NOTHROW_LIST) + BT_LAST, false, false, false, ATTR_NOTHROW_LIST, false) /* If SMALL_STACK is defined, then `alloca' is only defined in its `__builtin' form. */ @@ -173,27 +187,27 @@ DEF_LIB_BUILTIN(BUILT_IN_FLOOR, "__builtin_floor", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LIST) -DEF_LIB_BUILTIN(BUILT_IN_FLOORF, - "__builtin_floorf", - BT_FN_FLOAT_FLOAT, - ATTR_CONST_NOTHROW_LIST) -DEF_LIB_BUILTIN(BUILT_IN_FLOORL, - "__builtin_floorl", - BT_FN_LONG_DOUBLE_LONG_DOUBLE, - ATTR_CONST_NOTHROW_LIST) +DEF_C99_C90RES_BUILTIN(BUILT_IN_FLOORF, + "__builtin_floorf", + BT_FN_FLOAT_FLOAT, + ATTR_CONST_NOTHROW_LIST) +DEF_C99_C90RES_BUILTIN(BUILT_IN_FLOORL, + "__builtin_floorl", + BT_FN_LONG_DOUBLE_LONG_DOUBLE, + ATTR_CONST_NOTHROW_LIST) DEF_LIB_BUILTIN(BUILT_IN_CEIL, "__builtin_ceil", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LIST) -DEF_LIB_BUILTIN(BUILT_IN_CEILF, - "__builtin_ceilf", - BT_FN_FLOAT_FLOAT, - ATTR_CONST_NOTHROW_LIST) -DEF_LIB_BUILTIN(BUILT_IN_CEILL, - "__builtin_ceill", - BT_FN_LONG_DOUBLE_LONG_DOUBLE, - ATTR_CONST_NOTHROW_LIST) +DEF_C99_C90RES_BUILTIN(BUILT_IN_CEILF, + "__builtin_ceilf", + BT_FN_FLOAT_FLOAT, + ATTR_CONST_NOTHROW_LIST) +DEF_C99_C90RES_BUILTIN(BUILT_IN_CEILL, + "__builtin_ceill", + BT_FN_LONG_DOUBLE_LONG_DOUBLE, + ATTR_CONST_NOTHROW_LIST) DEF_C99_BUILTIN(BUILT_IN_ROUND, "__builtin_round", @@ -295,14 +309,14 @@ DEF_BUILTIN (BUILT_IN_BZERO, BT_FN_VOID_PTR_SIZE, BT_FN_VOID_VAR, true, true, true, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_LIST, false) DEF_BUILTIN (BUILT_IN_BCMP, "__builtin_bcmp", BUILT_IN_NORMAL, BT_FN_INT_CONST_PTR_CONST_PTR_SIZE, BT_FN_INT_VAR, true, true, true, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_LIST, false) DEF_EXT_LIB_BUILTIN(BUILT_IN_FFS, "__builtin_ffs", @@ -414,68 +428,68 @@ DEF_LIB_BUILTIN(BUILT_IN_LOG, : (flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST : ATTR_PURE_NOTHROW_LIST)) -DEF_LIB_BUILTIN(BUILT_IN_SQRTF, - "__builtin_sqrtf", - BT_FN_FLOAT_FLOAT, - flag_errno_math ? ATTR_NOTHROW_LIST - : (flag_unsafe_math_optimizations - ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST)) -DEF_LIB_BUILTIN(BUILT_IN_SINF, - "__builtin_sinf", - BT_FN_FLOAT_FLOAT, - flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST) -DEF_LIB_BUILTIN(BUILT_IN_COSF, - "__builtin_cosf", - BT_FN_FLOAT_FLOAT, - flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST) -DEF_LIB_BUILTIN(BUILT_IN_EXPF, - "__builtin_expf", - BT_FN_FLOAT_FLOAT, - flag_errno_math ? ATTR_NOTHROW_LIST - : (flag_unsafe_math_optimizations - ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST)) -DEF_LIB_BUILTIN(BUILT_IN_LOGF, - "__builtin_logf", - BT_FN_FLOAT_FLOAT, - flag_errno_math ? ATTR_NOTHROW_LIST - : (flag_unsafe_math_optimizations - ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST)) -DEF_LIB_BUILTIN(BUILT_IN_SQRTL, - "__builtin_sqrtl", - BT_FN_LONG_DOUBLE_LONG_DOUBLE, - flag_errno_math ? ATTR_NOTHROW_LIST - : (flag_unsafe_math_optimizations - ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST)) -DEF_LIB_BUILTIN(BUILT_IN_SINL, - "__builtin_sinl", - BT_FN_LONG_DOUBLE_LONG_DOUBLE, - flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST) -DEF_LIB_BUILTIN(BUILT_IN_COSL, - "__builtin_cosl", - BT_FN_LONG_DOUBLE_LONG_DOUBLE, - flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST) -DEF_LIB_BUILTIN(BUILT_IN_EXPL, - "__builtin_expl", - BT_FN_LONG_DOUBLE_LONG_DOUBLE, - flag_errno_math ? ATTR_NOTHROW_LIST - : (flag_unsafe_math_optimizations - ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST)) -DEF_LIB_BUILTIN(BUILT_IN_LOGL, - "__builtin_logl", - BT_FN_LONG_DOUBLE_LONG_DOUBLE, - flag_errno_math ? ATTR_NOTHROW_LIST - : (flag_unsafe_math_optimizations - ? ATTR_CONST_NOTHROW_LIST - : ATTR_PURE_NOTHROW_LIST)) +DEF_C99_C90RES_BUILTIN(BUILT_IN_SQRTF, + "__builtin_sqrtf", + BT_FN_FLOAT_FLOAT, + flag_errno_math ? ATTR_NOTHROW_LIST + : (flag_unsafe_math_optimizations + ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST)) +DEF_C99_C90RES_BUILTIN(BUILT_IN_SINF, + "__builtin_sinf", + BT_FN_FLOAT_FLOAT, + flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST) +DEF_C99_C90RES_BUILTIN(BUILT_IN_COSF, + "__builtin_cosf", + BT_FN_FLOAT_FLOAT, + flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST) +DEF_C99_C90RES_BUILTIN(BUILT_IN_EXPF, + "__builtin_expf", + BT_FN_FLOAT_FLOAT, + flag_errno_math ? ATTR_NOTHROW_LIST + : (flag_unsafe_math_optimizations + ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST)) +DEF_C99_C90RES_BUILTIN(BUILT_IN_LOGF, + "__builtin_logf", + BT_FN_FLOAT_FLOAT, + flag_errno_math ? ATTR_NOTHROW_LIST + : (flag_unsafe_math_optimizations + ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST)) +DEF_C99_C90RES_BUILTIN(BUILT_IN_SQRTL, + "__builtin_sqrtl", + BT_FN_LONG_DOUBLE_LONG_DOUBLE, + flag_errno_math ? ATTR_NOTHROW_LIST + : (flag_unsafe_math_optimizations + ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST)) +DEF_C99_C90RES_BUILTIN(BUILT_IN_SINL, + "__builtin_sinl", + BT_FN_LONG_DOUBLE_LONG_DOUBLE, + flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST) +DEF_C99_C90RES_BUILTIN(BUILT_IN_COSL, + "__builtin_cosl", + BT_FN_LONG_DOUBLE_LONG_DOUBLE, + flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST) +DEF_C99_C90RES_BUILTIN(BUILT_IN_EXPL, + "__builtin_expl", + BT_FN_LONG_DOUBLE_LONG_DOUBLE, + flag_errno_math ? ATTR_NOTHROW_LIST + : (flag_unsafe_math_optimizations + ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST)) +DEF_C99_C90RES_BUILTIN(BUILT_IN_LOGL, + "__builtin_logl", + BT_FN_LONG_DOUBLE_LONG_DOUBLE, + flag_errno_math ? ATTR_NOTHROW_LIST + : (flag_unsafe_math_optimizations + ? ATTR_CONST_NOTHROW_LIST + : ATTR_PURE_NOTHROW_LIST)) DEF_GCC_BUILTIN(BUILT_IN_INF, "__builtin_inf", @@ -616,7 +630,7 @@ DEF_BUILTIN (BUILT_IN_FPUTS, BUILT_IN_NORMAL, BT_FN_INT_CONST_STRING_PTR, BT_FN_INT_VAR, - true, true, false, ATTR_NOTHROW_LIST) + true, true, false, ATTR_NOTHROW_LIST, true) DEF_FALLBACK_BUILTIN(BUILT_IN_FWRITE, "__builtin_fwrite", BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR, @@ -650,7 +664,7 @@ DEF_BUILTIN (BUILT_IN_FPUTS_UNLOCKED, BUILT_IN_NORMAL, BT_FN_INT_CONST_STRING_PTR, BT_FN_INT_VAR, - true, true, true, ATTR_NOTHROW_LIST) + true, true, true, ATTR_NOTHROW_LIST, true) DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_FWRITE_UNLOCKED, "__builtin_fwrite_unlocked", BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR) @@ -755,7 +769,7 @@ DEF_BUILTIN (BUILT_IN_ABORT, BT_FN_VOID, BT_FN_VOID, 1, 0, 0, - ATTR_NORETURN_NOTHROW_LIST) + ATTR_NORETURN_NOTHROW_LIST, true) DEF_BUILTIN (BUILT_IN_EXIT, "__builtin_exit", @@ -763,7 +777,7 @@ DEF_BUILTIN (BUILT_IN_EXIT, BT_FN_VOID_INT, BT_FN_VOID_INT, 1, 0, 0, - ATTR_NORETURN_NOTHROW_LIST) + ATTR_NORETURN_NOTHROW_LIST, true) DEF_BUILTIN (BUILT_IN__EXIT, "__builtin__exit", @@ -771,7 +785,7 @@ DEF_BUILTIN (BUILT_IN__EXIT, BT_FN_VOID_INT, BT_FN_VOID_INT, 1, 0, 1, - ATTR_NORETURN_NOTHROW_LIST) + ATTR_NORETURN_NOTHROW_LIST, false) DEF_BUILTIN (BUILT_IN__EXIT2, "__builtin__Exit", @@ -779,5 +793,5 @@ DEF_BUILTIN (BUILT_IN__EXIT2, BT_FN_VOID_INT, BT_FN_VOID_INT, 1, 0, !flag_isoc99, - ATTR_NORETURN_NOTHROW_LIST) + ATTR_NORETURN_NOTHROW_LIST, false) diff --git a/gcc/c-common.c b/gcc/c-common.c index 2eb2eb7e8c8..cf7fb0706e5 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -3549,7 +3549,7 @@ c_common_nodes_and_builtins () c_init_attributes (); #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, \ - BOTH_P, FALLBACK_P, NONANSI_P, ATTRS) \ + BOTH_P, FALLBACK_P, NONANSI_P, ATTRS, IMPLICIT) \ if (NAME) \ { \ tree decl; \ @@ -3576,6 +3576,8 @@ c_common_nodes_and_builtins () built_in_attributes[(int) ATTRS]); \ \ built_in_decls[(int) ENUM] = decl; \ + if (IMPLICIT) \ + implicit_built_in_decls[(int) ENUM] = decl; \ } #include "builtins.def" #undef DEF_BUILTIN @@ -4507,9 +4509,9 @@ c_expand_builtin_printf (arglist, target, tmode, modifier, ignore, unlocked) int unlocked; { tree fn_putchar = unlocked ? - built_in_decls[BUILT_IN_PUTCHAR_UNLOCKED] : built_in_decls[BUILT_IN_PUTCHAR]; + implicit_built_in_decls[BUILT_IN_PUTCHAR_UNLOCKED] : implicit_built_in_decls[BUILT_IN_PUTCHAR]; tree fn_puts = unlocked ? - built_in_decls[BUILT_IN_PUTS_UNLOCKED] : built_in_decls[BUILT_IN_PUTS]; + implicit_built_in_decls[BUILT_IN_PUTS_UNLOCKED] : implicit_built_in_decls[BUILT_IN_PUTS]; tree fn, format_arg, stripped_string; /* If the return value is used, or the replacement _DECL isn't @@ -4611,9 +4613,9 @@ c_expand_builtin_fprintf (arglist, target, tmode, modifier, ignore, unlocked) int unlocked; { tree fn_fputc = unlocked ? - built_in_decls[BUILT_IN_FPUTC_UNLOCKED] : built_in_decls[BUILT_IN_FPUTC]; + implicit_built_in_decls[BUILT_IN_FPUTC_UNLOCKED] : implicit_built_in_decls[BUILT_IN_FPUTC]; tree fn_fputs = unlocked ? - built_in_decls[BUILT_IN_FPUTS_UNLOCKED] : built_in_decls[BUILT_IN_FPUTS]; + implicit_built_in_decls[BUILT_IN_FPUTS_UNLOCKED] : implicit_built_in_decls[BUILT_IN_FPUTS]; tree fn, format_arg, stripped_string; /* If the return value is used, or the replacement _DECL isn't diff --git a/gcc/config/linux.h b/gcc/config/linux.h index 2b1e50f3bde..948ae495687 100644 --- a/gcc/config/linux.h +++ b/gcc/config/linux.h @@ -110,3 +110,10 @@ Boston, MA 02111-1307, USA. */ /* Define this so we can compile MS code for use with WINE. */ #define HANDLE_PRAGMA_PACK_PUSH_POP + + +/* Determine whether the the entire c99 runtime + is present in the runtime library. */ +#ifndef USE_GNULIBC_1 +#define TARGET_C99_FUNCTIONS 1 +#endif diff --git a/gcc/defaults.h b/gcc/defaults.h index 07a4bbc8886..2dc9d749858 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -638,4 +638,10 @@ You Lose! You must define PREFERRED_DEBUGGING_TYPE! #define EXTRA_CONSTRAINT_STR(OP, C,STR) EXTRA_CONSTRAINT (OP, C) #endif +/* Determine whether the the entire c99 runtime + is present in the runtime library. */ +#ifndef TARGET_C99_FUNCTIONS +#define TARGET_C99_FUNCTIONS 0 +#endif + #endif /* ! GCC_DEFAULTS_H */ diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 24efe145d85..e66f7686634 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -4779,6 +4779,15 @@ Define this macro if GCC should generate calls to the ISO C (and System V) library functions @code{memcpy}, @code{memmove} and @code{memset} rather than the BSD functions @code{bcopy} and @code{bzero}. +@findex TARGET_C99_FUNCTIONS +@cindex C99 math functions, implicit usage +@item TARGET_C99_FUNCTIONS +When this macro is nonzero, GCC will implicitly optimize @code{sin} calls into +@code{sinf} and similary for other functions defined by C99 standard. The +default is nonzero that should be proper value for most modern systems, however +number of existing systems lacks support for these functions in the runtime so +they needs this macro to be redefined to 0. + @findex LIBGCC_NEEDS_DOUBLE @item LIBGCC_NEEDS_DOUBLE Define this macro if @code{float} arguments cannot be passed to library diff --git a/gcc/java/builtins.c b/gcc/java/builtins.c index 2aec8fd04b2..1e388d887e1 100644 --- a/gcc/java/builtins.c +++ b/gcc/java/builtins.c @@ -70,7 +70,7 @@ static tree sqrt_builtin (tree, tree); static tree java_build_function_call_expr (tree, tree); static void define_builtin (enum built_in_function, const char *, - enum built_in_class, tree, int); + enum built_in_class, tree, int, int); static tree define_builtin_type (int, int, int, int, int); @@ -189,7 +189,8 @@ define_builtin (enum built_in_function val, const char *name, enum built_in_class class, tree type, - int fallback_p) + int fallback_p, + int implicit) { tree decl; @@ -209,6 +210,8 @@ define_builtin (enum built_in_function val, DECL_BUILT_IN_CLASS (decl) = class; DECL_FUNCTION_CODE (decl) = val; built_in_decls[val] = decl; + if (implicit) + implicit_built_in_decls[val] = decl; } /* Compute the type for a builtin. */ @@ -306,8 +309,8 @@ initialize_builtins (void) #include "builtin-types.def" #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, \ - FALLBACK_P, NONANSI_P, ATTRS) \ - define_builtin (ENUM, NAME, CLASS, builtin_types[TYPE], FALLBACK_P); + FALLBACK_P, NONANSI_P, ATTRS, IMPLICIT) \ + define_builtin (ENUM, NAME, CLASS, builtin_types[TYPE], FALLBACK_P, IMPLICIT); #include "builtins.def" } diff --git a/gcc/tree.h b/gcc/tree.h index 212cfa427c7..626c49d44cf 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -84,7 +84,7 @@ extern const char *const built_in_class_names[4]; /* Codes that identify the various built in functions so that expand_call can identify them quickly. */ -#define DEF_BUILTIN(ENUM, N, C, T, LT, B, F, NA, AT) ENUM, +#define DEF_BUILTIN(ENUM, N, C, T, LT, B, F, NA, AT, IM) ENUM, enum built_in_function { #include "builtins.def" @@ -99,6 +99,7 @@ extern const char *const built_in_names[(int) END_BUILTINS]; /* An array of _DECL trees for the above. */ extern GTY(()) tree built_in_decls[(int) END_BUILTINS]; +extern GTY(()) tree implicit_built_in_decls[(int) END_BUILTINS]; /* The definition of tree nodes fills the next several pages. */ @@ -2928,6 +2929,8 @@ extern tree invert_truthvalue PARAMS ((tree)); extern tree fold_builtin PARAMS ((tree)); extern enum built_in_function builtin_mathfn_code PARAMS ((tree)); extern tree build_function_call_expr PARAMS ((tree, tree)); +extern tree mathfn_built_in PARAMS ((tree, enum built_in_function fn)); +extern tree strip_float_extensions PARAMS ((tree)); /* In convert.c */ extern tree strip_float_extensions PARAMS ((tree)); -- 2.11.0