public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][PR65823] Fix va_arg ap_copy nop detection
@ 2015-04-22  7:41 Tom de Vries
  2015-04-22  8:06 ` Richard Biener
  0 siblings, 1 reply; 7+ messages in thread
From: Tom de Vries @ 2015-04-22  7:41 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 2106 bytes --]

Hi,

this patch fixes PR65823.

The problem is a verify_gimple ICE during compilation of 
gcc.c-torture/execute/stdarg-2.c for arm at -O0/-O1:
...
In function 'f3':
src/gcc/testsuite/gcc.c-torture/execute/stdarg-2.c:61:1:
error: incorrect sharing of tree nodes
aps[4]
# .MEM_5 = VDEF <.MEM_11>
aps[4] = aps[4];
...


Before gimplification, f3 looks like this in the original dump:
...
   struct va_list aps[10];

     struct va_list aps[10];
   __builtin_va_start ((struct  &) (struct  *) &aps[4], i);
   x = VA_ARG_EXPR <aps[4]>;
   __builtin_va_end ((struct  &) (struct  *) &aps[4]);
...

After gimplification, it looks like:
...
f3 (int i)
{
   long intD.5 x.0D.4231;
   struct va_listD.4222 apsD.4227[10];

   try
     {
       # USE = anything
       # CLB = anything
       __builtin_va_startD.1052 (&apsD.4227[4], 0);
       # USE = anything
       # CLB = anything
       x.0D.4231 = VA_ARG (&apsD.4227[4], 0B);
       apsD.4227[4] = apsD.4227[4];
       xD.4223 = x.0D.4231;
       # USE = anything
       # CLB = anything
       __builtin_va_endD.1051 (&apsD.4227[4]);
     }
   finally
     {
       apsD.4227 = {CLOBBER};
     }
}
...

The nop 'apsD.4227[4] = apsD.4227[4]' introduced during gimplification is not 
meant to be there.


There is already a test 'TREE_OPERAND (ap, 0) != TREE_OPERAND (ap_copy, 0))' in 
gimplify_modify_expr to prevent this nop:
...
   /* When gimplifying the &ap argument of va_arg, we might end up with
        ap.1 = ap
        va_arg (&ap.1, 0B)
      We need to assign ap.1 back to ap, otherwise va_arg has no effect on
      ap.  */
   if (ap != NULL_TREE
       && TREE_CODE (ap) == ADDR_EXPR
       && TREE_CODE (ap_copy) == ADDR_EXPR
       && TREE_OPERAND (ap, 0) != TREE_OPERAND (ap_copy, 0))
     gimplify_assign (TREE_OPERAND (ap, 0), TREE_OPERAND (ap_copy, 0), pre_p);
...

But the test is a pointer equality test, and it fails in this case.

The patches fixes the problem by using operand_equal_p to do the equality test.


Bootstrapped and reg-tested on x86_64.

Did minimal non-bootstrap build on arm and reg-tested.

OK for trunk?

Thanks,
- Tom

[-- Attachment #2: 0001-Fix-va_arg-ap_copy-nop-detection.patch --]
[-- Type: text/x-patch, Size: 862 bytes --]

Fix va_arg ap_copy nop detection

2015-04-22  Tom de Vries  <tom@codesourcery.com>

	PR tree-optimization/65823
	* gimplify.c (gimplify_modify_expr): Use operand_equal_p to test for
	equality between ap_copy and ap.
---
 gcc/gimplify.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 0a8ef84..c68bd47 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -4792,7 +4792,7 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
   if (ap != NULL_TREE
       && TREE_CODE (ap) == ADDR_EXPR
       && TREE_CODE (ap_copy) == ADDR_EXPR
-      && TREE_OPERAND (ap, 0) != TREE_OPERAND (ap_copy, 0))
+      && !operand_equal_p (TREE_OPERAND (ap, 0), TREE_OPERAND (ap_copy, 0), 0))
     gimplify_assign (TREE_OPERAND (ap, 0), TREE_OPERAND (ap_copy, 0), pre_p);
 
   if (want_value)
-- 
1.9.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-04-28  9:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-22  7:41 [PATCH][PR65823] Fix va_arg ap_copy nop detection Tom de Vries
2015-04-22  8:06 ` Richard Biener
2015-04-22 13:38   ` Tom de Vries
2015-04-22 13:50     ` Richard Biener
2015-04-27  7:45       ` Tom de Vries
2015-04-28  9:40         ` Tom de Vries
2015-04-28  9:54           ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).