diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-02-02 13:21:13 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2007-02-02 13:21:13 +0100 |
commit | 6b01cd54dd628d5f5b02c508032113d764759141 (patch) | |
tree | 2be40460b646c9724b96b9db0315c07f49770ee7 /gcc/builtins.c | |
parent | b198261f9c5ce8b6cec5769eec4f3d82e04eaeb8 (diff) | |
download | gcc-6b01cd54dd628d5f5b02c508032113d764759141.zip gcc-6b01cd54dd628d5f5b02c508032113d764759141.tar.gz gcc-6b01cd54dd628d5f5b02c508032113d764759141.tar.bz2 |
re PR middle-end/30473 (Internal Compiler Error with a sprintf with few arguments for format %s)
PR middle-end/30473
* builtins.c (fold_builtin_sprintf): Do not attempt to optimize
sprintf (str, "%s"). Do not optimize sprintf (str, "nopercent", p++).
* gcc.dg/pr30473.c: New test.
* gcc.c-torture/execute/20070201-1.c: New test.
From-SVN: r121495
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 73d0a11..5b9a87f 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -10553,6 +10553,7 @@ fold_builtin_sprintf (tree arglist, int ignored) /* Get the destination string and the format specifier. */ dest = TREE_VALUE (arglist); fmt = TREE_VALUE (TREE_CHAIN (arglist)); + arglist = TREE_CHAIN (TREE_CHAIN (arglist)); /* Check whether the format is a literal string constant. */ fmt_str = c_getstr (fmt); @@ -10573,6 +10574,10 @@ fold_builtin_sprintf (tree arglist, int ignored) if (!fn) return NULL_TREE; + /* Don't optimize sprintf (buf, "abc", ptr++). */ + if (arglist) + return NULL_TREE; + /* Convert sprintf (str, fmt) into strcpy (str, fmt) when 'format' is known to contain no % formats. */ arglist = build_tree_list (NULL_TREE, fmt); @@ -10591,8 +10596,12 @@ fold_builtin_sprintf (tree arglist, int ignored) if (!fn) return NULL_TREE; + /* Don't crash on sprintf (str1, "%s"). */ + if (!arglist) + return NULL_TREE; + /* Convert sprintf (str1, "%s", str2) into strcpy (str1, str2). */ - orig = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); + orig = TREE_VALUE (arglist); arglist = build_tree_list (NULL_TREE, orig); arglist = tree_cons (NULL_TREE, dest, arglist); if (!ignored) |