gimple-fold.c (gimple_fold_builtin_printf): Don't create a not NUL terminated STRING_...
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 23 Jul 2018 13:20:38 +0000 (13:20 +0000)
committerBernd Edlinger <edlinger@gcc.gnu.org>
Mon, 23 Jul 2018 13:20:38 +0000 (13:20 +0000)
2018-07-23  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * gimple-fold.c (gimple_fold_builtin_printf): Don't create a not NUL
        terminated STRING_CST object.

From-SVN: r262932

gcc/ChangeLog
gcc/gimple-fold.c

index 13cc870ed5466dfc9d540487c440ee42ffe10f75..2cbe833dcfd3d8cc85afa34bf8e5632be9ab1f72 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-23  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       * gimple-fold.c (gimple_fold_builtin_printf): Don't create a not NUL
+       terminated STRING_CST object.
+
 2018-07-23  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
        hsa-dump.c (dump_hsa_symbol): Avoid out of scope access to buf.
index 027ca4da97c78f2550de203aa8b88d2d20ea0299..c3fa57064c271a5b3e516f7c5ed06bbcc375fdec 100644 (file)
@@ -3433,23 +3433,13 @@ gimple_fold_builtin_printf (gimple_stmt_iterator *gsi, tree fmt,
              && (int) len > 0)
            {
              char *newstr;
-             tree offset_node, string_cst;
 
              /* Create a NUL-terminated string that's one char shorter
                 than the original, stripping off the trailing '\n'.  */
-             newarg = build_string_literal (len, str);
-             string_cst = string_constant (newarg, &offset_node);
-             gcc_checking_assert (string_cst
-                                  && (TREE_STRING_LENGTH (string_cst)
-                                      == (int) len)
-                                  && integer_zerop (offset_node)
-                                  && (unsigned char)
-                                     TREE_STRING_POINTER (string_cst)[len - 1]
-                                     == target_newline);
-             /* build_string_literal creates a new STRING_CST,
-                modify it in place to avoid double copying.  */
-             newstr = CONST_CAST (char *, TREE_STRING_POINTER (string_cst));
+             newstr = xstrdup (str);
              newstr[len - 1] = '\0';
+             newarg = build_string_literal (len, newstr);
+             free (newstr);
              if (fn_puts)
                {
                  gcall *repl = gimple_build_call (fn_puts, 1, newarg);