public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] fix PR middle-end/17885, gimplifing of volatile &a->b
@ 2004-10-18 19:41 Richard Kenner
  2004-10-18 19:46 ` Jason Merrill
  0 siblings, 1 reply; 12+ messages in thread
From: Richard Kenner @ 2004-10-18 19:41 UTC (permalink / raw)
  To: pinskia; +Cc: gcc-patches

    Because the COMPONENT_REF has its TREE_SIDE_EFFECTS set then by
    recompute_tree_invarant_for_addr_expr so does the ADDR_EXPR, this
    might be a bug in that function though.

I think it is.  But the TREE_SIDE_EFFECTS bit in the COMPONENT_REF is
ignored; the issue is that the operand of the COMPONENT_REF also must have
TREE_SIDE_EFFECTS set.  But I agree that shouldn't set TREE_SIDE_EFFECTS of
an ADDR_EXPR: only if the computation of the *address* has side-effects should
TREE_SIDE_EFFECTS be set.

Specifically, I think the line

      se |= TREE_SIDE_EFFECTS (node);

should be deleted.

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [PATCH] fix PR middle-end/17885, gimplifing of volatile &a->b
@ 2004-10-18 21:00 Richard Kenner
  0 siblings, 0 replies; 12+ messages in thread
From: Richard Kenner @ 2004-10-18 21:00 UTC (permalink / raw)
  To: pinskia; +Cc: gcc-patches

    Yes but we don't UPDATE_TITCSE on the INDRIECT_REF for the case which I 
    am looking at.

    We have <COMPONENT_REF <INDIRECT_REF <VAR_DECL <VOLATILE> SIDE_EFFECTS>
    SIDE_EFFECTS> in my case.  

That's *exactly* the case I'm talking about!  But in this case since
the VAR_DECL is volatile, the ADDR_EXPR *should* have
TREE_SIDE_EFFECTS since it's basically the volatile var plus a
constant.  But I still think the code should be looking at the operand
of the INDIRECT_REF (the result would be the same, though).

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [PATCH] fix PR middle-end/17885, gimplifing of volatile &a->b
@ 2004-10-18 19:57 Richard Kenner
  2004-10-18 20:39 ` Andrew Pinski
  0 siblings, 1 reply; 12+ messages in thread
From: Richard Kenner @ 2004-10-18 19:57 UTC (permalink / raw)
  To: jason; +Cc: gcc-patches

    I think that should still be the general case; if we're taking the address
    of, say, a struct returned from a function, we want to propagate
    TREE_SIDE_EFFECTS from the call to the ADDR_EXPR.

I wonder if the problem isn't here:

  if (TREE_CODE (node) == INDIRECT_REF)
    {
      /* If this is &((T*)0)->field, then this is a form of addition.  */
      if (TREE_CODE (TREE_OPERAND (node, 0)) != INTEGER_CST)
	UPDATE_TITCSE (node);

Shouldn't that last "node" be TREE_OPERAND (node, 0)?  We don't care about
the INDIRECT_REF here: all we care about is its operand.

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [PATCH] fix PR middle-end/17885, gimplifing of volatile &a->b
@ 2004-10-18 19:50 Richard Kenner
  0 siblings, 0 replies; 12+ messages in thread
From: Richard Kenner @ 2004-10-18 19:50 UTC (permalink / raw)
  To: jason; +Cc: gcc-patches

    I think that should still be the general case; if we're taking the address
    of, say, a struct returned from a function, we want to propagate
    TREE_SIDE_EFFECTS from the call to the ADDR_EXPR.

Oh, you're right.  I misread the code.  It only does that if the innermost
object is not a decl.  So I agree it should be there.

    But we should special-case COMPONENT_REF so that TREE_SIDE_EFFECTS is
    propagated from op0 to the ADDR_EXPR, not from the ref itself.  With
    appropriate recursion.

But that's what the code does: it ignores the TREE_SIDE_EFFECTS of the
COMPONENT_REF!

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH] fix PR middle-end/17885, gimplifing of volatile &a->b
@ 2004-10-18 14:25 Andrew Pinski
  2004-10-18 17:56 ` Richard Henderson
  2004-10-18 19:49 ` Jeffrey A Law
  0 siblings, 2 replies; 12+ messages in thread
From: Andrew Pinski @ 2004-10-18 14:25 UTC (permalink / raw)
  To: gcc-patches@gcc.gnu.org Patches

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

The problem here is that we don't handle taking the address of
volatile pointers to structs' members, aka we don't handle
when we have volatile types but the expression it self is not
volatile. This fixes the problem by handling them.

OK? Bootstrapped and tested on powerpc-darwin with no regressions.

Thanks,
Andrew Pinski

ChangeLog:
	* gimplify.c (gimplify_expr): Handle ADDR_EXPR when
	we have volatile types but the expression it self is
	not volatile.

testsuite/ChangeLog:
	* gcc.dg/pr17885.c: New test.


[-- Attachment #2: temp.diff.txt --]
[-- Type: text/plain, Size: 1160 bytes --]

Index: testsuite/gcc.dg/pr17885.c
===================================================================
RCS file: testsuite/gcc.dg/pr17885.c
diff -N testsuite/gcc.dg/pr17885.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/pr17885.c	18 Oct 2004 14:24:30 -0000
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* We used to ICE in the gimplifier because
+   we have volatile types but the ADDR_EXPR 
+   it self is not volatile.  */
+
+struct lock {
+ int lk_interlock;
+};
+void
+acquire(volatile struct lock *lkp)
+{
+  &lkp->lk_interlock;
+}
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.83
diff -u -p -r2.83 gimplify.c
--- gimplify.c	11 Oct 2004 12:57:09 -0000	2.83
+++ gimplify.c	18 Oct 2004 14:24:31 -0000
@@ -3973,6 +3995,10 @@ gimplify_expr (tree *expr_p, tree *pre_p
 			     gimple_test_f, fallback);
 	      break;
 
+	    case ADDR_EXPR:
+	      gimplify_addr_expr (expr_p, pre_p, post_p);
+	      break;
+
 	    default:
 	       /* Anything else with side-effects must be converted to
 	       	  a valid statement before we get here.  */

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

end of thread, other threads:[~2004-10-18 21:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-18 19:41 [PATCH] fix PR middle-end/17885, gimplifing of volatile &a->b Richard Kenner
2004-10-18 19:46 ` Jason Merrill
  -- strict thread matches above, loose matches on Subject: below --
2004-10-18 21:00 Richard Kenner
2004-10-18 19:57 Richard Kenner
2004-10-18 20:39 ` Andrew Pinski
2004-10-18 19:50 Richard Kenner
2004-10-18 14:25 Andrew Pinski
2004-10-18 17:56 ` Richard Henderson
2004-10-18 18:41   ` Andrew Pinski
2004-10-18 21:22     ` Richard Henderson
2004-10-18 21:35     ` Richard Henderson
2004-10-18 19:49 ` Jeffrey A Law

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).