From a8ed1cbd67ebb44c14f65432524892b384ba11e9 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 20 Mar 2018 08:55:41 +0100 Subject: [PATCH] re PR c/84953 (misleading warning from strpbrk(x,"")) 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 | 6 ++++++ gcc/builtins.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr84953.c | 11 +++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr84953.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6742c0b68bc..67162701d12 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-03-20 Jakub Jelinek + + 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 PR tree-optimization/84946 diff --git a/gcc/builtins.c b/gcc/builtins.c index 85affa74510..487d9d58db2 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7638ca162f4..d1c359b9e7c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-20 Jakub Jelinek + + PR c/84953 + * gcc.dg/pr84953.c: New test. + 2018-03-19 Marek Polacek PR c++/84925 diff --git a/gcc/testsuite/gcc.dg/pr84953.c b/gcc/testsuite/gcc.dg/pr84953.c new file mode 100644 index 00000000000..723a8a67dda --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr84953.c @@ -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; +} -- 2.30.2