]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/84953 (misleading warning from strpbrk(x,""))
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Jun 2018 20:52:44 +0000 (22:52 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Jun 2018 20:52:44 +0000 (22:52 +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: r261931

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

index 61772122ef37bce54bcc49cda129e271d1e0e32c..83af672bc0d82677bd838c9c247c39a4e5a66657 100644 (file)
 
        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.
+
        PR target/84990
        * dwarf2asm.c (dw2_output_indirect_constant_1): Temporarily turn off
        flag_section_anchors.
index 75342b786defa3c7365f6fcb11a51af85a4d1092..767093f539f9cc0436423443aad309122c228e17 100644 (file)
@@ -9270,7 +9270,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 7fbcb42af6fb623a3b5e73a5112f7a6e6119d725..ce51bb094f77345d9a7dd4a1619650c03738f8c4 100644 (file)
@@ -1,6 +1,11 @@
 2018-06-22  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-19  Maxim Ostapenko  <m.ostapenko@samsung.com>
 
        PR sanitizer/78651
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;
+}