diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-02-09 17:01:36 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-02-09 17:01:36 +0000 |
commit | 5300bef09ec5bfba9459b1d51df36a83f33f12ca (patch) | |
tree | ceda52eaeb57baf1c0dbf7e40eb9bd2804179661 | |
parent | 2f4777f3a5642980e54dbae3c6a0b62df9f2163a (diff) | |
download | gcc-5300bef09ec5bfba9459b1d51df36a83f33f12ca.tar.gz |
PR target/64979
* tree-stdarg.c (pass_stdarg::execute): Scan phi node args for
va_list escapes.
* gcc.dg/tree-ssa/stdarg-7.c: New test.
* gcc.c-torture/execute/pr64979.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220543 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/pr64979.c | 36 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/stdarg-7.c | 22 | ||||
-rw-r--r-- | gcc/tree-stdarg.c | 47 |
5 files changed, 103 insertions, 16 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5d12a5d34d4..78c1af1e2e4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-02-09 Jakub Jelinek <jakub@redhat.com> + + PR target/64979 + * tree-stdarg.c (pass_stdarg::execute): Scan phi node args for + va_list escapes. + 2015-02-09 Richard Biener <rguenther@suse.de> * genmatch.c (replace_id): Copy expr_type. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 258b9a67dd7..4fd039790e5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,10 @@ -2015-02-29 Alan Lawrence <alan.lawrence@arm.com> +2015-02-09 Jakub Jelinek <jakub@redhat.com> + + PR target/64979 + * gcc.dg/tree-ssa/stdarg-7.c: New test. + * gcc.c-torture/execute/pr64979.c: New test. + +2015-02-09 Alan Lawrence <alan.lawrence@arm.com> * gcc.target/arm/macro_defs0.c: Remove extraneous "target" diff --git a/gcc/testsuite/gcc.c-torture/execute/pr64979.c b/gcc/testsuite/gcc.c-torture/execute/pr64979.c new file mode 100644 index 00000000000..ccb46087e02 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr64979.c @@ -0,0 +1,36 @@ +/* PR target/64979 */ + +#include <stdarg.h> + +void __attribute__((noinline, noclone)) +bar (int x, va_list *ap) +{ + if (ap) + { + int i; + for (i = 0; i < 10; i++) + if (i != va_arg (*ap, int)) + __builtin_abort (); + if (va_arg (*ap, double) != 0.5) + __builtin_abort (); + } +} + +void __attribute__((noinline, noclone)) +foo (int x, ...) +{ + va_list ap; + int n; + + va_start (ap, x); + n = va_arg (ap, int); + bar (x, (va_list *) ((n == 0) ? ((void *) 0) : &ap)); + va_end (ap); +} + +int +main () +{ + foo (100, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0.5); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/stdarg-7.c b/gcc/testsuite/gcc.dg/tree-ssa/stdarg-7.c new file mode 100644 index 00000000000..9b497c07270 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/stdarg-7.c @@ -0,0 +1,22 @@ +/* PR target/64979 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-stdarg" } */ + +#include <stdarg.h> + +void bar (int x, va_list *ap); + +void +foo (int x, ...) +{ + va_list ap; + int n; + + va_start (ap, x); + n = va_arg (ap, int); + bar (x, (va_list *) ((n == 0) ? ((void *) 0) : &ap)); + va_end (ap); +} + +/* { dg-final { scan-tree-dump "foo: va_list escapes 1, needs to save all GPR units and all FPR units" "stdarg" } } */ +/* { dg-final { cleanup-tree-dump "stdarg" } } */ diff --git a/gcc/tree-stdarg.c b/gcc/tree-stdarg.c index 883c692e8c6..2cf0ca3ec8f 100644 --- a/gcc/tree-stdarg.c +++ b/gcc/tree-stdarg.c @@ -856,22 +856,23 @@ pass_stdarg::execute (function *fun) /* For va_list_simple_ptr, we have to check PHI nodes too. We treat them as assignments for the purpose of escape analysis. This is not needed for non-simple va_list because virtual phis don't perform - any real data movement. */ - if (va_list_simple_ptr) - { - tree lhs, rhs; - use_operand_p uop; - ssa_op_iter soi; + any real data movement. Also, check PHI nodes for taking address of + the va_list vars. */ + tree lhs, rhs; + use_operand_p uop; + ssa_op_iter soi; - for (gphi_iterator i = gsi_start_phis (bb); !gsi_end_p (i); - gsi_next (&i)) - { - gphi *phi = i.phi (); - lhs = PHI_RESULT (phi); + for (gphi_iterator i = gsi_start_phis (bb); !gsi_end_p (i); + gsi_next (&i)) + { + gphi *phi = i.phi (); + lhs = PHI_RESULT (phi); - if (virtual_operand_p (lhs)) - continue; + if (virtual_operand_p (lhs)) + continue; + if (va_list_simple_ptr) + { FOR_EACH_PHI_ARG (uop, phi, soi, SSA_OP_USE) { rhs = USE_FROM_PTR (uop); @@ -894,6 +895,22 @@ pass_stdarg::execute (function *fun) } } } + + for (unsigned j = 0; !va_list_escapes + && j < gimple_phi_num_args (phi); ++j) + if ((!va_list_simple_ptr + || TREE_CODE (gimple_phi_arg_def (phi, j)) != SSA_NAME) + && walk_tree (gimple_phi_arg_def_ptr (phi, j), + find_va_list_reference, &wi, NULL)) + { + 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); + } + va_list_escapes = true; + } } for (gimple_stmt_iterator i = gsi_start_bb (bb); @@ -916,8 +933,8 @@ pass_stdarg::execute (function *fun) if (is_gimple_assign (stmt)) { - tree lhs = gimple_assign_lhs (stmt); - tree rhs = gimple_assign_rhs1 (stmt); + lhs = gimple_assign_lhs (stmt); + rhs = gimple_assign_rhs1 (stmt); if (va_list_simple_ptr) { |