builtins.c (fold_builtin_strncpy): Make sure len is a constant before comparing it...
authorAlexandre Oliva <aoliva@redhat.com>
Fri, 9 Jul 2004 03:37:13 +0000 (03:37 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Fri, 9 Jul 2004 03:37:13 +0000 (03:37 +0000)
* builtins.c (fold_builtin_strncpy): Make sure len is a constant
before comparing it as such.

From-SVN: r84343

gcc/ChangeLog
gcc/builtins.c

index bfeb09aeab33693313dead431f4f070b2e32971e..04f778f7bccdff2e4ed350e960f614a0b1b6beaf 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-09  Alexandre Oliva  <aoliva@redhat.com>
+
+       * builtins.c (fold_builtin_strncpy): Make sure len is a constant
+       before comparing it as such.
+
 2004-07-08  Richard Henderson  <rth@redhat.com>
 
        * builtins.c (std_gimplify_va_arg_expr): Hoist valist into a
index ecb7841ec6d8848963f6831860a6718a0f09a1fc..11e1f05a0f9d25dc20fdae50b25e09f6e02dbf22 100644 (file)
@@ -7385,6 +7385,11 @@ fold_builtin_strncpy (tree exp, tree slen)
   if (integer_zerop (len))
     return omit_one_operand (TREE_TYPE (exp), dest, src);
 
+  /* We can't compare slen with len as constants below if len is not a
+     constant.  */
+  if (len == 0 || TREE_CODE (len) != INTEGER_CST)
+    return 0;
+
   if (!slen)
     slen = c_strlen (src, 1);