mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-22 03:46:53 -05:00
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: r121503
This commit is contained in:
committed by
Jakub Jelinek
parent
b62d2548ac
commit
39b0fe152a
@@ -1,3 +1,9 @@
|
||||
2007-02-02 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR middle-end/30473
|
||||
* builtins.c (fold_builtin_sprintf): Do not attempt to optimize
|
||||
sprintf (str, "%s"). Do not optimize sprintf (str, "nopercent", p++).
|
||||
|
||||
2007-02-01 Guy Martin <gmsoft@gentoo.org>
|
||||
|
||||
* pa.md (tp_load): Correct mfctl instruction syntax.
|
||||
|
||||
@@ -9911,6 +9911,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);
|
||||
@@ -9931,6 +9932,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);
|
||||
@@ -9949,8 +9954,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)
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
2007-02-02 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR middle-end/30473
|
||||
* gcc.dg/pr30473.c: New test.
|
||||
* gcc.c-torture/execute/20070201-1.c: New test.
|
||||
|
||||
2007-01-30 Geoffrey Keating <geoffk@apple.com>
|
||||
|
||||
* g++.dg/eh/simd-4.C (main): Also catch SIGSEGV.
|
||||
|
||||
20
gcc/testsuite/gcc.c-torture/execute/20070201-1.c
Normal file
20
gcc/testsuite/gcc.c-torture/execute/20070201-1.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* PR middle-end/30473 */
|
||||
|
||||
extern int sprintf (char *, const char *, ...);
|
||||
extern void abort (void);
|
||||
|
||||
char *
|
||||
foo (char *buf, char *p)
|
||||
{
|
||||
sprintf (buf, "abcde", p++);
|
||||
return p;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
char buf[6];
|
||||
if (foo (buf, &buf[2]) != &buf[3])
|
||||
abort ();
|
||||
return 0;
|
||||
}
|
||||
13
gcc/testsuite/gcc.dg/pr30473.c
Normal file
13
gcc/testsuite/gcc.dg/pr30473.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* PR middle-end/30473 */
|
||||
/* Make sure this doesn't ICE. */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O2" } */
|
||||
|
||||
extern int sprintf (char *, const char *, ...);
|
||||
|
||||
void
|
||||
foo (char *buf1, char *buf2)
|
||||
{
|
||||
sprintf (buf1, "%s", "abcde");
|
||||
sprintf (buf2, "%s");
|
||||
}
|
||||
Reference in New Issue
Block a user