Mark C2x built-in functions as such.
authorJoseph Myers <joseph@codesourcery.com>
Fri, 4 Oct 2019 16:08:06 +0000 (17:08 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 4 Oct 2019 16:08:06 +0000 (17:08 +0100)
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

13 files changed:
gcc/ChangeLog
gcc/ada/ChangeLog
gcc/ada/gcc-interface/utils.c
gcc/brig/ChangeLog
gcc/brig/brig-lang.c
gcc/builtins.def
gcc/coretypes.h
gcc/lto/ChangeLog
gcc/lto/lto-lang.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c11-builtins-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-builtins-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/dfp/c2x-builtins-dfp-1.c [new file with mode: 0644]

index 1274b648b8bf3bd6279c861fb3a4e74eb97b2055..a9f8da9c8949e08b964c5f6c8670d4fa13c58d7a 100644 (file)
@@ -1,3 +1,11 @@
+2019-10-04  Joseph Myers  <joseph@codesourcery.com>
+
+       * 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  <coypu@sdf.org>
 
        * ira-color.c (update_costs_from_allocno): Call
index 6a84b7b80f57b7e30a606de179e2e4daf49b21c6..0463038f63a86412b4a8955488a71578eaa87397 100644 (file)
@@ -1,3 +1,7 @@
+2019-10-04  Joseph Myers  <joseph@codesourcery.com>
+
+       * gcc-interface/utils.c (flag_isoc2x): New variable.
+
 2019-10-01  Maciej W. Rozycki  <macro@wdc.com>
 
        * gcc-interface/Makefile.in (ADA_RTL_DSO_DIR): New variable.
index b9d5af771e80a67b534684f34f755524df3e1b34..d2891f250a7dcc2f2a953628ba78cf3fc05781db 100644 (file)
@@ -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.
 
index 462cbab05af536c4beaa5282807740e73f8cd19c..9f824e2173c955f194474cd267595194d71a5950 100644 (file)
@@ -1,3 +1,7 @@
+2019-10-04  Joseph Myers  <joseph@codesourcery.com>
+
+       * brig-lang.c (flag_isoc2x): New variable.
+
 2019-08-23  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/91283
index 96c6c572e94a6be308535126acf7a5a5dee0f366..505a83d9123d4c4f8d1b8ba6731473e7205fefc7 100644 (file)
@@ -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, ...)
index 5b9b706665a3e252301a7fb3d51e18b80746010f..d8233f5f760f8426e8ff85473ecda02aa6c2655b 100644 (file)
@@ -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)
index 257de226326f23f34f95ebaeadcbc9b66f7b19b3..b683f1298803e8e4c93a73da506e3db947caad77 100644 (file)
@@ -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
index a73cbc4ca9f0a5ffe229c11f7581b0024849dcfe..e4102320795448767eec421601bda34bb06134fc 100644 (file)
@@ -1,3 +1,7 @@
+2019-10-04  Joseph Myers  <joseph@codesourcery.com>
+
+       * lto-lang.c (flag_isoc2x): New variable.
+
 2019-09-18  Richard Biener  <rguenther@suse.de>
 
        PR lto/91763
index 414eaf2075addaa3692fa3ebac32d3f935190a57..0d781da5768fe056ecf62d9a6f9610945b192c42 100644 (file)
@@ -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.  */
 
index c5ead9fb30fdc6823909222ada4ba0800cf9656a..68ca51e824bdcbe996e94e8aa5de1cc20a01a132 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-04  Joseph Myers  <joseph@codesourcery.com>
+
+       * 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 <mark.eggleston@codethink.com>
 
        * 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 (file)
index 0000000..bfadf70
--- /dev/null
@@ -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 (file)
index 0000000..7476059
--- /dev/null
@@ -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 (file)
index 0000000..88b8b33
--- /dev/null
@@ -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" } */