]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix spurious warning for strstr (s, "").
authorJames E Wilson <wilson@specifixinc.com>
Sat, 19 Nov 2005 02:25:25 +0000 (18:25 -0800)
committerJim Wilson <wilson@gcc.gnu.org>
Sat, 19 Nov 2005 02:25:25 +0000 (18:25 -0800)
* builtins.c (fold_builtin_strstr): Pass s1 through fold_convert before
returning it.
* gcc.dg/builtin-strstr.c: New.

From-SVN: r107206

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

index c4f105fecd87918dedc0f7240154398c61d7da27..b128468e4007cd2f1b75086058758913978c540c 100644 (file)
@@ -1,3 +1,8 @@
+2005-11-18  James E Wilson  <wilson@specifix.com>
+
+       * builtins.c (fold_builtin_strstr): Pass s1 through fold_convert before
+       returning it.
+
 2005-11-18  Mike Stump  <mrs@apple.com>
 
        * c-common.c (handle_cleanup_attribute): Use a lang hook for lookup_name.
index 359ff646e987b3973046ce1604a813a4addf3378..6cca5fbe37e5b6a1c07f3166844790f67aaa45b6 100644 (file)
@@ -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;
index 046330f52ada8d9f4d232e49eabd539d2ebe3be4..570041ea26fa47c372b3ce4b23bb8ddc5789c721 100644 (file)
@@ -1,3 +1,7 @@
+2005-11-18  James E Wilson  <wilson@specifix.com>
+
+       * gcc.dg/builtin-strstr.c: New.
+
 2005-11-18  Richard Henderson  <rth@redhat.com>
 
        * 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 (file)
index 0000000..b8201f4
--- /dev/null
@@ -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, "");
+}