re PR tree-optimization/56205 (stdarg pass confused by jump threading)

PR tree-optimization/56205
	* tree-stdarg.c (check_all_va_list_escapes): Return true if
	there are any PHI nodes that set non-va_list_escape_vars SSA_NAME
	and some va_list_escape_vars SSA_NAME appears in some PHI argument.

	* gcc.dg/tree-ssa/stdarg-6.c: New test.
	* gcc.c-torture/execute/pr56205.c: New test.

From-SVN: r195760
This commit is contained in:
Jakub Jelinek 2013-02-05 16:54:39 +01:00 committed by Jakub Jelinek
parent 14ac6aa24e
commit 11f1e3ab23
5 changed files with 140 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2013-02-05 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/56205
* tree-stdarg.c (check_all_va_list_escapes): Return true if
there are any PHI nodes that set non-va_list_escape_vars SSA_NAME
and some va_list_escape_vars SSA_NAME appears in some PHI argument.
2013-02-05 Richard Biener <rguenther@suse.de>
PR tree-optimization/53342

View File

@ -1,3 +1,9 @@
2013-02-05 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/56205
* gcc.dg/tree-ssa/stdarg-6.c: New test.
* gcc.c-torture/execute/pr56205.c: New test.
2013-02-05 Richard Biener <rguenther@suse.de>
PR tree-optimization/53342

View File

@ -0,0 +1,61 @@
/* PR tree-optimization/56205 */
#include <stdarg.h>
int a, b;
char c[128];
__attribute__((noinline, noclone)) static void
f1 (const char *fmt, ...)
{
va_list ap;
asm volatile ("" : : : "memory");
if (__builtin_strcmp (fmt, "%s %d %s") != 0)
__builtin_abort ();
va_start (ap, fmt);
if (__builtin_strcmp (va_arg (ap, const char *), "foo") != 0
|| va_arg (ap, int) != 1
|| __builtin_strcmp (va_arg (ap, const char *), "bar") != 0)
__builtin_abort ();
va_end (ap);
}
__attribute__((noinline, noclone)) static void
f2 (const char *fmt, va_list ap)
{
asm volatile ("" : : : "memory");
if (__builtin_strcmp (fmt, "baz") != 0
|| __builtin_strcmp (va_arg (ap, const char *), "foo") != 0
|| va_arg (ap, double) != 12.0
|| va_arg (ap, int) != 26)
__builtin_abort ();
}
static void
f3 (int x, char const *y, va_list z)
{
f1 ("%s %d %s", x ? "" : "foo", ++a, (y && *y) ? "bar" : "");
if (y && *y)
f2 (y, z);
}
__attribute__((noinline, noclone)) void
f4 (int x, char const *y, ...)
{
va_list z;
va_start (z, y);
if (!x && *c == '\0')
++b;
f3 (x, y, z);
va_end (z);
}
int
main ()
{
asm volatile ("" : : : "memory");
f4 (0, "baz", "foo", 12.0, 26);
if (a != 1 || b != 1)
__builtin_abort ();
return 0;
}

View File

@ -0,0 +1,35 @@
/* PR tree-optimization/56205 */
/* { dg-do compile } */
/* { dg-options "-O3 -fdump-tree-stdarg" } */
#include <stdarg.h>
int a, b;
char c[128];
static inline void
foo (int x, char const *y, va_list z)
{
__builtin_printf ("%s %d %s", x ? "" : "foo", ++a, (y && *y) ? "bar" : "");
if (y && *y)
__builtin_vprintf (y, z);
}
void
bar (int x, char const *y, ...)
{
va_list z;
va_start (z, y);
if (!x && *c == '\0')
++b;
foo (x, y, z);
va_end (z);
}
/* { dg-final { scan-tree-dump "bar: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 } } } } } } */
/* { dg-final { scan-tree-dump "bar: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target { powerpc*-*-linux* && ilp32 } } } } */
/* { dg-final { scan-tree-dump "bar: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target alpha*-*-linux* } } } */
/* { dg-final { scan-tree-dump "bar: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" { target s390*-*-linux* } } } */
/* { dg-final { scan-tree-dump "bar: va_list escapes 1, needs to save all GPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && ia32 } } } } */
/* { dg-final { scan-tree-dump "bar: va_list escapes 1, needs to save all GPR units" "stdarg" { target ia64-*-* } } } */
/* { dg-final { scan-tree-dump "bar: va_list escapes 1, needs to save all GPR units" "stdarg" { target { powerpc*-*-* && lp64 } } } } */

View File

@ -526,6 +526,37 @@ check_all_va_list_escapes (struct stdarg_info *si)
{
gimple_stmt_iterator i;
for (i = gsi_start_phis (bb); !gsi_end_p (i); gsi_next (&i))
{
tree lhs;
use_operand_p uop;
ssa_op_iter soi;
gimple phi = gsi_stmt (i);
lhs = PHI_RESULT (phi);
if (virtual_operand_p (lhs)
|| bitmap_bit_p (si->va_list_escape_vars,
SSA_NAME_VERSION (lhs)))
continue;
FOR_EACH_PHI_ARG (uop, phi, soi, SSA_OP_USE)
{
tree rhs = USE_FROM_PTR (uop);
if (TREE_CODE (rhs) == SSA_NAME
&& bitmap_bit_p (si->va_list_escape_vars,
SSA_NAME_VERSION (rhs)))
{
if (dump_file && (dump_flags & TDF_DETAILS))
{
fputs ("va_list escapes in ", dump_file);
print_gimple_stmt (dump_file, phi, 0, dump_flags);
fputc ('\n', dump_file);
}
return true;
}
}
}
for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
{
gimple stmt = gsi_stmt (i);