[PATCH] Use __UINT{16,32,64}_TYPE__ for builtins when available (PR c/37743)

Jakub Jelinek jakub@redhat.com
Wed Feb 19 21:13:00 GMT 2014


Hi!

This patch changes the return type of the __builtin_bswap{16,32,64} builtins
to the __UINT{16,32,64}_TYPE__ types if the target defines them, instead
of a nonstandard integer type, which is a problem for -Wformat warnings
or for C++ overload resolution.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2014-02-19  Jakub Jelinek  <jakub@redhat.com>

	PR c/37743
	* c-common.c (c_common_nodes_and_builtins): When initializing
	c_uint{16,32,64}_type_node, also set corresponding
	uint{16,32,64}_type_node to the same value.

	* g++.dg/ext/builtin-bswap1.C: New test.
	* c-c++-common/pr37743.c: New test.

--- gcc/c-family/c-common.c.jj	2014-02-19 17:42:46.000000000 +0100
+++ gcc/c-family/c-common.c	2014-02-19 19:00:43.038726087 +0100
@@ -5610,13 +5610,13 @@ c_common_nodes_and_builtins (void)
     uint8_type_node =
       TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE)));
   if (UINT16_TYPE)
-    c_uint16_type_node =
+    c_uint16_type_node = uint16_type_node =
       TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE)));
   if (UINT32_TYPE)
-    c_uint32_type_node =
+    c_uint32_type_node = uint32_type_node =
       TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE)));
   if (UINT64_TYPE)
-    c_uint64_type_node =
+    c_uint64_type_node = uint64_type_node =
       TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE)));
   if (INT_LEAST8_TYPE)
     int_least8_type_node =
--- gcc/testsuite/g++.dg/ext/builtin-bswap1.C.jj	2014-02-19 18:51:07.012975025 +0100
+++ gcc/testsuite/g++.dg/ext/builtin-bswap1.C	2014-02-19 18:53:54.160029098 +0100
@@ -0,0 +1,22 @@
+// PR c/37743
+// { dg-do compile }
+
+#if defined(__UINT32_TYPE__) && defined(__INT32_TYPE__)
+
+void foo (__UINT32_TYPE__);
+void foo (__INT32_TYPE__);
+
+void
+bar (__UINT32_TYPE__ x)
+{
+  foo (__builtin_bswap32 (x));
+}
+
+#else
+
+void
+bar ()
+{
+}
+
+#endif
--- gcc/testsuite/c-c++-common/pr37743.c.jj	2014-02-19 18:55:09.947603407 +0100
+++ gcc/testsuite/c-c++-common/pr37743.c	2014-02-19 18:58:23.153511710 +0100
@@ -0,0 +1,13 @@
+/* PR c/37743 */
+/* This needs to be run only on targets where __UINT32_TYPE__ is defined
+   to unsigned int.  */
+/* { dg-do compile { target *-*-linux-gnu* } } */
+/* { dg-options "-Wformat" } */
+
+int foo (const char *, ...) __attribute__ ((format (printf, 1, 2)));
+
+void
+bar (unsigned int x)
+{
+  foo ("%x", __builtin_bswap32 (x));
+}

	Jakub



More information about the Gcc-patches mailing list