re PR c/84953 (misleading warning from strpbrk(x,""))
authorJakub Jelinek <jakub@redhat.com>
Tue, 20 Mar 2018 07:55:41 +0000 (08:55 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 20 Mar 2018 07:55:41 +0000 (08:55 +0100)
PR c/84953
* builtins.c (fold_builtin_strpbrk): For strpbrk(x, "") use type
instead of TREE_TYPE (s1) for the return value.

* gcc.dg/pr84953.c: New test.

From-SVN: r258671

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr84953.c [new file with mode: 0644]

index 6742c0b68bc5e70f8e6cb44050af44a4bc54504a..67162701d12eadd82f25de4bb3607268bb40cec0 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/84953
+       * builtins.c (fold_builtin_strpbrk): For strpbrk(x, "") use type
+       instead of TREE_TYPE (s1) for the return value.
+
 2018-03-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/84946
index 85affa74510faf96f156f2253bc2b3f169ca7a1f..487d9d58db2354958420e23308b5d5c3fd03da35 100644 (file)
@@ -9573,7 +9573,7 @@ fold_builtin_strpbrk (location_t loc, tree s1, tree s2, tree type)
       if (p2[0] == '\0')
        /* strpbrk(x, "") == NULL.
           Evaluate and ignore s1 in case it had side-effects.  */
-       return omit_one_operand_loc (loc, TREE_TYPE (s1), integer_zero_node, s1);
+       return omit_one_operand_loc (loc, type, integer_zero_node, s1);
 
       if (p2[1] != '\0')
        return NULL_TREE;  /* Really call strpbrk.  */
index 7638ca162f4d817eff888892cff8fea924c7d44b..d1c359b9e7c654ba018db56aac4afa99658e54fa 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/84953
+       * gcc.dg/pr84953.c: New test.
+
 2018-03-19  Marek Polacek  <polacek@redhat.com>
 
        PR c++/84925
diff --git a/gcc/testsuite/gcc.dg/pr84953.c b/gcc/testsuite/gcc.dg/pr84953.c
new file mode 100644 (file)
index 0000000..723a8a6
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR c/84953 */
+/* { dg-do compile } */
+
+char *strpbrk (const char *, const char *);
+
+char *
+test (char *p)
+{
+  p = strpbrk (p, ""); /* { dg-bogus "assignment discards 'const' qualifier from pointer target type" } */
+  return p;
+}