From 0fa00483026f58848767c1577e3d76ef2fb2568b Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Fri, 4 Oct 2019 17:08:06 +0100 Subject: [PATCH] Mark C2x built-in functions as such. Various built-in functions that GCC has as extensions are now standard functions in C2x. This patch adds DEF_C2X_BUILTIN and uses it to mark them as such. Some of the so-marked functions were previously DEF_EXT_LIB_BUILTIN, while some DFP ones were DEF_GCC_BUILTIN (i.e. __builtin_* only); both sets become DEF_C2X_BUILTIN. This in turn requires flag_isoc2x to be defined in various front ends using builtins.def. As the semantics of the built-in functions should already be tested, the tests added only verify that they are declared in C2x mode but not in C11 mode. The test of DFP built-in functions being declared for C2x goes in gcc.dg/dfp/, as while such built-in functions currently don't depend on whether DFP is supported, that looks like a bug to me (see bug 91985), so it seems best for the tests not to depend on exactly how that bug might be fixed. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc: * builtins.def (DEF_C2X_BUILTIN): New macro. (exp10, exp10f, exp10l, fabsd32, fabsd64, fabsd128, nand32) (nand64, nand128, roundeven, roundevenf, roundevenl, strdup) (strndup): Use DEF_C2X_BUILTIN. * coretypes.h (enum function_class): Add function_c2x_misc. gcc/ada: * gcc-interface/utils.c (flag_isoc2x): New variable. gcc/brig: * brig-lang.c (flag_isoc2x): New variable. gcc/lto: * lto-lang.c (flag_isoc2x): New variable. gcc/testsuite: * gcc.dg/c11-builtins-1.c, gcc.dg/c2x-builtins-1.c, gcc.dg/dfp/c2x-builtins-dfp-1.c: New tests. From-SVN: r276588 --- gcc/ChangeLog | 8 +++++ gcc/ada/ChangeLog | 4 +++ gcc/ada/gcc-interface/utils.c | 1 + gcc/brig/ChangeLog | 4 +++ gcc/brig/brig-lang.c | 1 + gcc/builtins.def | 35 +++++++++++-------- gcc/coretypes.h | 3 +- gcc/lto/ChangeLog | 4 +++ gcc/lto/lto-lang.c | 1 + gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.dg/c11-builtins-1.c | 19 ++++++++++ gcc/testsuite/gcc.dg/c2x-builtins-1.c | 13 +++++++ gcc/testsuite/gcc.dg/dfp/c2x-builtins-dfp-1.c | 11 ++++++ 13 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/c11-builtins-1.c create mode 100644 gcc/testsuite/gcc.dg/c2x-builtins-1.c create mode 100644 gcc/testsuite/gcc.dg/dfp/c2x-builtins-dfp-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1274b648b8b..a9f8da9c894 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-10-04 Joseph Myers + + * builtins.def (DEF_C2X_BUILTIN): New macro. + (exp10, exp10f, exp10l, fabsd32, fabsd64, fabsd128, nand32) + (nand64, nand128, roundeven, roundevenf, roundevenl, strdup) + (strndup): Use DEF_C2X_BUILTIN. + * coretypes.h (enum function_class): Add function_c2x_misc. + 2019-10-04 Maya Rashish * ira-color.c (update_costs_from_allocno): Call diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 6a84b7b80f5..0463038f63a 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,7 @@ +2019-10-04 Joseph Myers + + * gcc-interface/utils.c (flag_isoc2x): New variable. + 2019-10-01 Maciej W. Rozycki * gcc-interface/Makefile.in (ADA_RTL_DSO_DIR): New variable. diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index b9d5af771e8..d2891f250a7 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -6901,6 +6901,7 @@ def_builtin_1 (enum built_in_function fncode, static int flag_isoc94 = 0; static int flag_isoc99 = 0; static int flag_isoc11 = 0; +static int flag_isoc2x = 0; /* Install what the common builtins.def offers plus our local additions. diff --git a/gcc/brig/ChangeLog b/gcc/brig/ChangeLog index 462cbab05af..9f824e2173c 100644 --- a/gcc/brig/ChangeLog +++ b/gcc/brig/ChangeLog @@ -1,3 +1,7 @@ +2019-10-04 Joseph Myers + + * brig-lang.c (flag_isoc2x): New variable. + 2019-08-23 Jakub Jelinek PR middle-end/91283 diff --git a/gcc/brig/brig-lang.c b/gcc/brig/brig-lang.c index 96c6c572e94..505a83d9123 100644 --- a/gcc/brig/brig-lang.c +++ b/gcc/brig/brig-lang.c @@ -587,6 +587,7 @@ static GTY(()) tree signed_size_type_node; int flag_isoc94; int flag_isoc99; int flag_isoc11; +int flag_isoc2x; static void def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...) diff --git a/gcc/builtins.def b/gcc/builtins.def index 5b9b706665a..d8233f5f760 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -154,6 +154,13 @@ along with GCC; see the file COPYING3. If not see DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ true, true, !flag_isoc11, ATTRS, targetm.libc_has_function (function_c11_misc), true) +/* Like DEF_LIB_BUILTIN, except that the function is only a part of + the standard in C2x or above. */ +#undef DEF_C2X_BUILTIN +#define DEF_C2X_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ + DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ + true, true, !flag_isoc2x, ATTRS, targetm.libc_has_function (function_c2x_misc), true) + /* Like DEF_C99_BUILTIN, but for complex math functions. */ #undef DEF_C99_COMPL_BUILTIN #define DEF_C99_COMPL_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ @@ -335,9 +342,9 @@ DEF_C99_BUILTIN (BUILT_IN_ERFCL, "erfcl", BT_FN_LONGDOUBLE_LONGDOUBLE, AT DEF_C99_BUILTIN (BUILT_IN_ERFF, "erff", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING) DEF_C99_BUILTIN (BUILT_IN_ERFL, "erfl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING) DEF_LIB_BUILTIN (BUILT_IN_EXP, "exp", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) -DEF_EXT_LIB_BUILTIN (BUILT_IN_EXP10, "exp10", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) -DEF_EXT_LIB_BUILTIN (BUILT_IN_EXP10F, "exp10f", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO) -DEF_EXT_LIB_BUILTIN (BUILT_IN_EXP10L, "exp10l", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) +DEF_C2X_BUILTIN (BUILT_IN_EXP10, "exp10", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) +DEF_C2X_BUILTIN (BUILT_IN_EXP10F, "exp10f", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO) +DEF_C2X_BUILTIN (BUILT_IN_EXP10L, "exp10l", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_BUILTIN (BUILT_IN_EXP2, "exp2", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_BUILTIN (BUILT_IN_EXP2F, "exp2f", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_BUILTIN (BUILT_IN_EXP2L, "exp2l", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) @@ -352,9 +359,9 @@ DEF_C99_C90RES_BUILTIN (BUILT_IN_FABSL, "fabsl", BT_FN_LONGDOUBLE_LONGDOUBLE, AT #define FABS_TYPE(F) BT_FN_##F##_##F DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_FABS, "fabs", FABS_TYPE, ATTR_CONST_NOTHROW_LEAF_LIST) #undef FABS_TYPE -DEF_GCC_BUILTIN (BUILT_IN_FABSD32, "fabsd32", BT_FN_DFLOAT32_DFLOAT32, ATTR_CONST_NOTHROW_LEAF_LIST) -DEF_GCC_BUILTIN (BUILT_IN_FABSD64, "fabsd64", BT_FN_DFLOAT64_DFLOAT64, ATTR_CONST_NOTHROW_LEAF_LIST) -DEF_GCC_BUILTIN (BUILT_IN_FABSD128, "fabsd128", BT_FN_DFLOAT128_DFLOAT128, ATTR_CONST_NOTHROW_LEAF_LIST) +DEF_C2X_BUILTIN (BUILT_IN_FABSD32, "fabsd32", BT_FN_DFLOAT32_DFLOAT32, ATTR_CONST_NOTHROW_LEAF_LIST) +DEF_C2X_BUILTIN (BUILT_IN_FABSD64, "fabsd64", BT_FN_DFLOAT64_DFLOAT64, ATTR_CONST_NOTHROW_LEAF_LIST) +DEF_C2X_BUILTIN (BUILT_IN_FABSD128, "fabsd128", BT_FN_DFLOAT128_DFLOAT128, ATTR_CONST_NOTHROW_LEAF_LIST) DEF_C99_BUILTIN (BUILT_IN_FDIM, "fdim", BT_FN_DOUBLE_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_BUILTIN (BUILT_IN_FDIMF, "fdimf", BT_FN_FLOAT_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_BUILTIN (BUILT_IN_FDIML, "fdiml", BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) @@ -501,9 +508,9 @@ DEF_C99_BUILTIN (BUILT_IN_NANF, "nanf", BT_FN_FLOAT_CONST_STRING, ATTR_CO DEF_C99_BUILTIN (BUILT_IN_NANL, "nanl", BT_FN_LONGDOUBLE_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) #define NAN_TYPE(F) BT_FN_##F##_CONST_STRING DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_NAN, "nan", NAN_TYPE, ATTR_CONST_NOTHROW_NONNULL) -DEF_GCC_BUILTIN (BUILT_IN_NAND32, "nand32", BT_FN_DFLOAT32_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) -DEF_GCC_BUILTIN (BUILT_IN_NAND64, "nand64", BT_FN_DFLOAT64_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) -DEF_GCC_BUILTIN (BUILT_IN_NAND128, "nand128", BT_FN_DFLOAT128_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) +DEF_C2X_BUILTIN (BUILT_IN_NAND32, "nand32", BT_FN_DFLOAT32_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) +DEF_C2X_BUILTIN (BUILT_IN_NAND64, "nand64", BT_FN_DFLOAT64_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) +DEF_C2X_BUILTIN (BUILT_IN_NAND128, "nand128", BT_FN_DFLOAT128_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) DEF_GCC_BUILTIN (BUILT_IN_NANS, "nans", BT_FN_DOUBLE_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) DEF_GCC_BUILTIN (BUILT_IN_NANSF, "nansf", BT_FN_FLOAT_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) DEF_GCC_BUILTIN (BUILT_IN_NANSL, "nansl", BT_FN_LONGDOUBLE_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) @@ -542,9 +549,9 @@ DEF_C99_BUILTIN (BUILT_IN_RINTL, "rintl", BT_FN_LONGDOUBLE_LONGDOUBLE, AT #define RINT_TYPE(F) BT_FN_##F##_##F DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_RINT, "rint", RINT_TYPE, ATTR_CONST_NOTHROW_LEAF_LIST) #undef RINT_TYPE -DEF_EXT_LIB_BUILTIN (BUILT_IN_ROUNDEVEN, "roundeven", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST) -DEF_EXT_LIB_BUILTIN (BUILT_IN_ROUNDEVENF, "roundevenf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST) -DEF_EXT_LIB_BUILTIN (BUILT_IN_ROUNDEVENL, "roundevenl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST) +DEF_C2X_BUILTIN (BUILT_IN_ROUNDEVEN, "roundeven", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST) +DEF_C2X_BUILTIN (BUILT_IN_ROUNDEVENF, "roundevenf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST) +DEF_C2X_BUILTIN (BUILT_IN_ROUNDEVENL, "roundevenl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST) DEF_C99_BUILTIN (BUILT_IN_ROUND, "round", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST) DEF_C99_BUILTIN (BUILT_IN_ROUNDF, "roundf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST) DEF_C99_BUILTIN (BUILT_IN_ROUNDL, "roundl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST) @@ -706,8 +713,8 @@ DEF_LIB_BUILTIN (BUILT_IN_STRCHR, "strchr", BT_FN_STRING_CONST_STRING_INT DEF_LIB_BUILTIN (BUILT_IN_STRCMP, "strcmp", BT_FN_INT_CONST_STRING_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF) DEF_LIB_BUILTIN (BUILT_IN_STRCPY, "strcpy", BT_FN_STRING_STRING_CONST_STRING, ATTR_RET1_NOTHROW_NONNULL_LEAF) DEF_LIB_BUILTIN (BUILT_IN_STRCSPN, "strcspn", BT_FN_SIZE_CONST_STRING_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF) -DEF_EXT_LIB_BUILTIN (BUILT_IN_STRDUP, "strdup", BT_FN_STRING_CONST_STRING, ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF) -DEF_EXT_LIB_BUILTIN (BUILT_IN_STRNDUP, "strndup", BT_FN_STRING_CONST_STRING_SIZE, ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF) +DEF_C2X_BUILTIN (BUILT_IN_STRDUP, "strdup", BT_FN_STRING_CONST_STRING, ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF) +DEF_C2X_BUILTIN (BUILT_IN_STRNDUP, "strndup", BT_FN_STRING_CONST_STRING_SIZE, ATTR_MALLOC_WARN_UNUSED_RESULT_NOTHROW_NONNULL_LEAF) DEF_LIB_BUILTIN (BUILT_IN_STRLEN, "strlen", BT_FN_SIZE_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL_LEAF) DEF_EXT_LIB_BUILTIN (BUILT_IN_STRNCASECMP, "strncasecmp", BT_FN_INT_CONST_STRING_CONST_STRING_SIZE, ATTR_PURE_NOTHROW_NONNULL_LEAF) DEF_LIB_BUILTIN (BUILT_IN_STRNCAT, "strncat", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF) diff --git a/gcc/coretypes.h b/gcc/coretypes.h index 257de226326..b683f129880 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -378,7 +378,8 @@ enum function_class { function_c99_misc, function_c99_math_complex, function_sincos, - function_c11_misc + function_c11_misc, + function_c2x_misc }; /* Enumerate visibility settings. This is deliberately ordered from most diff --git a/gcc/lto/ChangeLog b/gcc/lto/ChangeLog index a73cbc4ca9f..e4102320795 100644 --- a/gcc/lto/ChangeLog +++ b/gcc/lto/ChangeLog @@ -1,3 +1,7 @@ +2019-10-04 Joseph Myers + + * lto-lang.c (flag_isoc2x): New variable. + 2019-09-18 Richard Biener PR lto/91763 diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c index 414eaf2075a..0d781da5768 100644 --- a/gcc/lto/lto-lang.c +++ b/gcc/lto/lto-lang.c @@ -247,6 +247,7 @@ static GTY(()) tree signed_size_type_node; int flag_isoc94; int flag_isoc99; int flag_isoc11; +int flag_isoc2x; /* Attribute handlers. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c5ead9fb30f..68ca51e824b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-04 Joseph Myers + + * gcc.dg/c11-builtins-1.c, gcc.dg/c2x-builtins-1.c, + gcc.dg/dfp/c2x-builtins-dfp-1.c: New tests. + 2019-10-04 Mark Eggleston * gfortran.dg/auto_in_equiv_1.f90: Replaced. diff --git a/gcc/testsuite/gcc.dg/c11-builtins-1.c b/gcc/testsuite/gcc.dg/c11-builtins-1.c new file mode 100644 index 00000000000..bfadf704714 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-builtins-1.c @@ -0,0 +1,19 @@ +/* Test C11 built-in functions: test functions new in C2x are not + declared as built-in for C11. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11" } */ + +int exp10 (void); +int exp10f (void); +int exp10l (void); +int fabsd32 (void); +int fabsd64 (void); +int fabsd128 (void); +int nand32 (void); +int nand64 (void); +int nand128 (void); +int roundeven (void); +int roundevenf (void); +int roundevenl (void); +int strdup (void); +int strndup (void); diff --git a/gcc/testsuite/gcc.dg/c2x-builtins-1.c b/gcc/testsuite/gcc.dg/c2x-builtins-1.c new file mode 100644 index 00000000000..74760592cf8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-builtins-1.c @@ -0,0 +1,13 @@ +/* Test C2x built-in functions: test functions new in C2x are indeed + declared as built-in as expected. Non-DFP tests. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x" } */ + +int exp10 (void); /* { dg-warning "conflicting types for built-in function" } */ +int exp10f (void); /* { dg-warning "conflicting types for built-in function" } */ +int exp10l (void); /* { dg-warning "conflicting types for built-in function" } */ +int roundeven (void); /* { dg-warning "conflicting types for built-in function" } */ +int roundevenf (void); /* { dg-warning "conflicting types for built-in function" } */ +int roundevenl (void); /* { dg-warning "conflicting types for built-in function" } */ +int strdup (void); /* { dg-warning "conflicting types for built-in function" } */ +int strndup (void); /* { dg-warning "conflicting types for built-in function" } */ diff --git a/gcc/testsuite/gcc.dg/dfp/c2x-builtins-dfp-1.c b/gcc/testsuite/gcc.dg/dfp/c2x-builtins-dfp-1.c new file mode 100644 index 00000000000..88b8b334e71 --- /dev/null +++ b/gcc/testsuite/gcc.dg/dfp/c2x-builtins-dfp-1.c @@ -0,0 +1,11 @@ +/* Test C2x built-in functions: test functions new in C2x are indeed + declared as built-in as expected. DFP tests. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x" } */ + +int fabsd32 (void); /* { dg-warning "conflicting types for built-in function" } */ +int fabsd64 (void); /* { dg-warning "conflicting types for built-in function" } */ +int fabsd128 (void); /* { dg-warning "conflicting types for built-in function" } */ +int nand32 (void); /* { dg-warning "conflicting types for built-in function" } */ +int nand64 (void); /* { dg-warning "conflicting types for built-in function" } */ +int nand128 (void); /* { dg-warning "conflicting types for built-in function" } */ -- 2.30.2