]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/54486 (Spurious printf format warning mentions nonexistent...
authorJakub Jelinek <jakub@redhat.com>
Wed, 3 Apr 2013 17:57:32 +0000 (19:57 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 3 Apr 2013 17:57:32 +0000 (19:57 +0200)
Backported from mainline
2012-09-05  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/54486
* builtins.c (fold_builtin_strspn, fold_builtin_strcspn): Use
build_int_cst with size_type_node instead of size_int.

* c-c++-common/pr54486.c: New test.

From-SVN: r197444

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr54486.c [new file with mode: 0644]

index 641bd65aa563c01dad8cf11349022bb28b36b801..4c49df5801bdd22c3dd7d644c0a9995e32a599a5 100644 (file)
@@ -1,6 +1,12 @@
 2013-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2012-09-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/54486
+       * builtins.c (fold_builtin_strspn, fold_builtin_strcspn): Use
+       build_int_cst with size_type_node instead of size_int.
+
        2012-08-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/54363
index fd996113e873236a07b24c958cdb36aa3b3cebb1..4d8c1b7da93b02cf99037ded2e51eb1ca8cf1f7b 100644 (file)
@@ -11575,7 +11575,7 @@ fold_builtin_strspn (location_t loc, tree s1, tree s2)
       if (p1 && p2)
        {
          const size_t r = strspn (p1, p2);
-         return size_int (r);
+         return build_int_cst (size_type_node, r);
        }
 
       /* If either argument is "", return NULL_TREE.  */
@@ -11620,7 +11620,7 @@ fold_builtin_strcspn (location_t loc, tree s1, tree s2)
       if (p1 && p2)
        {
          const size_t r = strcspn (p1, p2);
-         return size_int (r);
+         return build_int_cst (size_type_node, r);
        }
 
       /* If the first argument is "", return NULL_TREE.  */
index d51c2564e678203c366a55966bfc46d0ddf9f755..99e28b1b92972f560b9614e0ddd8fc639ba5f498 100644 (file)
@@ -1,6 +1,11 @@
 2013-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2012-09-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/54486
+       * c-c++-common/pr54486.c: New test.
+
        2012-08-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/54363
diff --git a/gcc/testsuite/c-c++-common/pr54486.c b/gcc/testsuite/c-c++-common/pr54486.c
new file mode 100644 (file)
index 0000000..e8125fc
--- /dev/null
@@ -0,0 +1,32 @@
+/* PR middle-end/54486 */
+/* { dg-do compile } */
+/* { dg-options "-Wformat" } */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef __SIZE_TYPE__ size_t;
+extern int printf (const char *, ...);
+extern size_t strspn (const char *, const char *);
+extern size_t strcspn (const char *, const char *);
+extern size_t strlen (const char *);
+#ifdef __cplusplus
+}
+#endif
+
+void
+foo (void)
+{
+  printf ("%zu\n", strspn ("abc", "abcdefg"));
+  printf ("%zu\n", (size_t) strspn ("abc", "abcdefg"));
+  printf ("%zu\n", __builtin_strspn ("abc", "abcdefg"));
+  printf ("%zu\n", (size_t) __builtin_strspn ("abc", "abcdefg"));
+  printf ("%zu\n", strcspn ("abc", "abcdefg"));
+  printf ("%zu\n", (size_t) strcspn ("abc", "abcdefg"));
+  printf ("%zu\n", __builtin_strcspn ("abc", "abcdefg"));
+  printf ("%zu\n", (size_t) __builtin_strcspn ("abc", "abcdefg"));
+  printf ("%zu\n", strlen ("abc"));
+  printf ("%zu\n", (size_t) strlen ("abc"));
+  printf ("%zu\n", __builtin_strlen ("abc"));
+  printf ("%zu\n", (size_t) __builtin_strlen ("abc"));
+}