From: James E Wilson Date: Sat, 19 Nov 2005 02:25:25 +0000 (-0800) Subject: Fix spurious warning for strstr (s, ""). X-Git-Tag: releases/gcc-4.1.0~704 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=817f9ef2e52bbe4568264487acfa86c5bb2882d4;p=thirdparty%2Fgcc.git Fix spurious warning for strstr (s, ""). * builtins.c (fold_builtin_strstr): Pass s1 through fold_convert before returning it. * gcc.dg/builtin-strstr.c: New. From-SVN: r107206 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c4f105fecd87..b128468e4007 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-11-18 James E Wilson + + * builtins.c (fold_builtin_strstr): Pass s1 through fold_convert before + returning it. + 2005-11-18 Mike Stump * c-common.c (handle_cleanup_attribute): Use a lang hook for lookup_name. diff --git a/gcc/builtins.c b/gcc/builtins.c index 359ff646e987..6cca5fbe37e5 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -9199,8 +9199,10 @@ fold_builtin_strstr (tree arglist, tree type) return fold_convert (type, tem); } + /* The argument is const char *, and the result is char *, so we need + a type conversion here to avoid a warning. */ if (p2[0] == '\0') - return s1; + return fold_convert (type, s1); if (p2[1] != '\0') return 0; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 046330f52ada..570041ea26fa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-11-18 James E Wilson + + * gcc.dg/builtin-strstr.c: New. + 2005-11-18 Richard Henderson * gcc.target/ia64/20010423-1.c, gcc.target/ia64/20020313-1.c, diff --git a/gcc/testsuite/gcc.dg/builtin-strstr.c b/gcc/testsuite/gcc.dg/builtin-strstr.c new file mode 100644 index 000000000000..b8201f416426 --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtin-strstr.c @@ -0,0 +1,8 @@ +/* The strstr call is expanded to just "s", which should not result in a + warning about discarding qualifiers in an assignment. */ +/* { dg-do compile } */ +extern char * strstr (const char *s1, const char * s2); +void foo(const char *s){ + char * cp; + cp = strstr(s, ""); +}