]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/84953 (misleading warning from strpbrk(x,""))
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Jun 2018 17:35:29 +0000 (19:35 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Jun 2018 17:35:29 +0000 (19:35 +0200)
Backported from mainline
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.

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

From-SVN: r262080

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

index 7f3b127258d31cdc6663d2b32032752d995aa2ac..321c20592f1e1620e744158c29d24d07d2355873 100644 (file)
@@ -1,6 +1,12 @@
 2018-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       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-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/84899
index c70c0f5004c4c529b64f6627194adf12cd5aa0ff..3c94a58c3d82d637d6780851404b95b20727c7a1 100644 (file)
@@ -8794,7 +8794,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 79f69dfc9276f4a36005d5bd37d1e76d8b9dfc41..658c662ff16cbe41224f3190b58d4d19eb4d7fe8 100644 (file)
@@ -1,6 +1,11 @@
 2018-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-03-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/84953
+       * gcc.dg/pr84953.c: New test.
+
        2018-03-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/84899
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;
+}