public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls
@ 2012-03-01 11:05 jakub at gcc dot gnu.org
  2012-03-01 11:22 ` [Bug tree-optimization/52448] " rguenth at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-03-01 11:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

             Bug #: 52448
           Summary: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jakub@gcc.gnu.org


extern void abort (void);
extern void *malloc (__SIZE_TYPE__);
extern void free (void *);

__attribute__((noinline, noclone)) void
bar (char *x, int y)
{
  if (*x != '\n')
    abort ();
  if (y == 0)
    free (x);
}

__attribute__((noinline, noclone)) void
foo (char *x, int y)
{
  *x = '\n';
  bar (x, y);
  if (y)
    *x = '\0';
}

int
main ()
{
  char *p = malloc (1);
  if (p)
    {
      foo (p, 1);
      if (*p != '\0')
        abort ();
      foo (p, 0);
    }
  return 0;
}

The above testcase is miscompiled, starting with 4.3 with just -O2, before that
(including 3.2) with -O2 -ftree-cselim.  If you run the testcase under
valgrind, it will complain loudly, I could rewrite it (less portably) using
mmap/munmap to show it crash even without valgrind.

I'm afraid we need to invalidate the set of non-trapping MEMs on non-pure/const
calls (perhaps with the exception of selected builtins, e.g. none of the
string/mem builtins should actually unmap/mprotect/free any memory).


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

* [Bug tree-optimization/52448] [4.4/4.5/4.6/4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
@ 2012-03-01 11:22 ` rguenth at gcc dot gnu.org
  2012-03-01 12:06 ` matz at gcc dot gnu.org
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-03-01 11:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-03-01
                 CC|                            |matz at gcc dot gnu.org
   Target Milestone|---                         |4.4.7
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-03-01 11:21:54 UTC ---
Confirmed.


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

* [Bug tree-optimization/52448] [4.4/4.5/4.6/4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
  2012-03-01 11:22 ` [Bug tree-optimization/52448] " rguenth at gcc dot gnu.org
@ 2012-03-01 12:06 ` matz at gcc dot gnu.org
  2012-03-01 12:12 ` rguenth at gcc dot gnu.org
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: matz at gcc dot gnu.org @ 2012-03-01 12:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

Michael Matz <matz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #2 from Michael Matz <matz at gcc dot gnu.org> 2012-03-01 12:05:43 UTC ---
Working on it.


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

* [Bug tree-optimization/52448] [4.4/4.5/4.6/4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
  2012-03-01 11:22 ` [Bug tree-optimization/52448] " rguenth at gcc dot gnu.org
  2012-03-01 12:06 ` matz at gcc dot gnu.org
@ 2012-03-01 12:12 ` rguenth at gcc dot gnu.org
  2012-03-01 12:58 ` matz at gcc dot gnu.org
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-03-01 12:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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

* [Bug tree-optimization/52448] [4.4/4.5/4.6/4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-03-01 12:12 ` rguenth at gcc dot gnu.org
@ 2012-03-01 12:58 ` matz at gcc dot gnu.org
  2012-03-01 14:10 ` matz at gcc dot gnu.org
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: matz at gcc dot gnu.org @ 2012-03-01 12:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

--- Comment #3 from Michael Matz <matz at gcc dot gnu.org> 2012-03-01 12:56:40 UTC ---
Created attachment 26802
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26802
candidate fix

This fixes the problem by remembering the last seen call and checking if
it's before or after the candidate stmt that might make us non-trapping.
It'll conflict with the patch from PR 52445 for now.


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

* [Bug tree-optimization/52448] [4.4/4.5/4.6/4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2012-03-01 12:58 ` matz at gcc dot gnu.org
@ 2012-03-01 14:10 ` matz at gcc dot gnu.org
  2012-03-01 16:08 ` matz at gcc dot gnu.org
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: matz at gcc dot gnu.org @ 2012-03-01 14:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

--- Comment #4 from Michael Matz <matz at gcc dot gnu.org> 2012-03-01 14:10:08 UTC ---
Bah, no.  That won't generally work.  In particular it might be calls that
don't necessarily dominate the "non-trapping" stmt that make it trapping
again:

*X = a;
if (cond)
  free_everything();
if (bla)
  *X = b;

The call doesn't dominate the second store, but the latter still might
trap (when cond is true).  Hmm, this needs a different approach.  If there's
any path from the dominating access to the access in question, which contains
a (problematic) call, it makes it trapping again.  We can ignore back edges,
hence the path between both accesses are acyclic, so we might still get away
with a non-iterating algorithm.  I'm still working on it.


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

* [Bug tree-optimization/52448] [4.4/4.5/4.6/4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2012-03-01 14:10 ` matz at gcc dot gnu.org
@ 2012-03-01 16:08 ` matz at gcc dot gnu.org
  2012-03-13 15:36 ` [Bug tree-optimization/52448] [4.5/4.6/4.7/4.8 " jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: matz at gcc dot gnu.org @ 2012-03-01 16:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

--- Comment #5 from Michael Matz <matz at gcc dot gnu.org> 2012-03-01 16:08:18 UTC ---
(In reply to comment #4)
> We can ignore back edges,
> hence the path between both accesses are acyclic, so we might still get away
> with a non-iterating algorithm.

Of course we cannot ignore back edges.  If we want to retain a non-iterating
algorithm we have to punt.  That wouldn't be too bad, as the situations
in which this helps usually is where the first access is in near proximity
to the second access.  If we punt in that way the following wouldn't
be handled anymore:

*X = a;
for ()
  if (cond)
    *X = b;


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

* [Bug tree-optimization/52448] [4.5/4.6/4.7/4.8 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2012-03-01 16:08 ` matz at gcc dot gnu.org
@ 2012-03-13 15:36 ` jakub at gcc dot gnu.org
  2012-07-02 12:27 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-03-13 15:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.7                       |4.5.4

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-03-13 12:48:27 UTC ---
4.4 branch is being closed, moving to 4.5.4 target.


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

* [Bug tree-optimization/52448] [4.5/4.6/4.7/4.8 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2012-03-13 15:36 ` [Bug tree-optimization/52448] [4.5/4.6/4.7/4.8 " jakub at gcc dot gnu.org
@ 2012-07-02 12:27 ` rguenth at gcc dot gnu.org
  2013-01-10 16:49 ` [Bug tree-optimization/52448] [4.6/4.7/4.8 " jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-02 12:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.5.4                       |4.6.4

--- Comment #7 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-02 12:27:11 UTC ---
The 4.5 branch is being closed, adjusting target milestone.


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

* [Bug tree-optimization/52448] [4.6/4.7/4.8 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2012-07-02 12:27 ` rguenth at gcc dot gnu.org
@ 2013-01-10 16:49 ` jakub at gcc dot gnu.org
  2013-02-08 12:32 ` matz at gcc dot gnu.org
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-10 16:49 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-10 16:49:26 UTC ---
Any progress with this?


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

* [Bug tree-optimization/52448] [4.6/4.7/4.8 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2013-01-10 16:49 ` [Bug tree-optimization/52448] [4.6/4.7/4.8 " jakub at gcc dot gnu.org
@ 2013-02-08 12:32 ` matz at gcc dot gnu.org
  2013-02-08 12:54 ` [Bug tree-optimization/52448] [4.6/4.7 " rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: matz at gcc dot gnu.org @ 2013-02-08 12:32 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

--- Comment #9 from Michael Matz <matz at gcc dot gnu.org> 2013-02-08 12:31:28 UTC ---
Author: matz
Date: Fri Feb  8 12:31:19 2013
New Revision: 195883

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195883
Log:
    PR tree-optimization/52448

    * tree-ssa-phiopt.c (struct name_to_bb): Add phase member.
    (nt_call_phase): New static.
    (add_or_mark_expr): Only mark accesses with newer phase than any
    call seen.
    (nonfreeing_call_p): New.
    (nt_init_block): Update nt_call_phase, mark blocks as visited.
    (nt_fini_block): Keep blocks marked as visited.
    (get_non_trapping): Initialize nt_call_phase, and reset aux pointer.

testsuite/
    PR tree-optimization/52448
    * gcc.dg/pr52448.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr52448.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-phiopt.c


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

* [Bug tree-optimization/52448] [4.6/4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2013-02-08 12:32 ` matz at gcc dot gnu.org
@ 2013-02-08 12:54 ` rguenth at gcc dot gnu.org
  2013-04-12 15:18 ` [Bug tree-optimization/52448] [4.7 " jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-02-08 12:54 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.8.0

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> 2013-02-08 12:53:48 UTC ---
Fixed on trunk sofar.


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

* [Bug tree-optimization/52448] [4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2013-02-08 12:54 ` [Bug tree-optimization/52448] [4.6/4.7 " rguenth at gcc dot gnu.org
@ 2013-04-12 15:18 ` jakub at gcc dot gnu.org
  2014-06-12 13:05 ` rguenth at gcc dot gnu.org
  2022-01-05 10:17 ` pinskia at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-12 15:18 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.6.4                       |4.7.4

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-12 15:17:15 UTC ---
GCC 4.6.4 has been released and the branch has been closed.


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

* [Bug tree-optimization/52448] [4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (11 preceding siblings ...)
  2013-04-12 15:18 ` [Bug tree-optimization/52448] [4.7 " jakub at gcc dot gnu.org
@ 2014-06-12 13:05 ` rguenth at gcc dot gnu.org
  2022-01-05 10:17 ` pinskia at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-06-12 13:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|4.7.4                       |4.8.0
      Known to fail|                            |4.7.4

--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed for 4.8.0.


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

* [Bug tree-optimization/52448] [4.7 Regression] cselim broken with calls
  2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
                   ` (12 preceding siblings ...)
  2014-06-12 13:05 ` rguenth at gcc dot gnu.org
@ 2022-01-05 10:17 ` pinskia at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-05 10:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52448

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chrbr at gcc dot gnu.org

--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 41486 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2022-01-05 10:17 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-01 11:05 [Bug tree-optimization/52448] New: [4.4/4.5/4.6/4.7 Regression] cselim broken with calls jakub at gcc dot gnu.org
2012-03-01 11:22 ` [Bug tree-optimization/52448] " rguenth at gcc dot gnu.org
2012-03-01 12:06 ` matz at gcc dot gnu.org
2012-03-01 12:12 ` rguenth at gcc dot gnu.org
2012-03-01 12:58 ` matz at gcc dot gnu.org
2012-03-01 14:10 ` matz at gcc dot gnu.org
2012-03-01 16:08 ` matz at gcc dot gnu.org
2012-03-13 15:36 ` [Bug tree-optimization/52448] [4.5/4.6/4.7/4.8 " jakub at gcc dot gnu.org
2012-07-02 12:27 ` rguenth at gcc dot gnu.org
2013-01-10 16:49 ` [Bug tree-optimization/52448] [4.6/4.7/4.8 " jakub at gcc dot gnu.org
2013-02-08 12:32 ` matz at gcc dot gnu.org
2013-02-08 12:54 ` [Bug tree-optimization/52448] [4.6/4.7 " rguenth at gcc dot gnu.org
2013-04-12 15:18 ` [Bug tree-optimization/52448] [4.7 " jakub at gcc dot gnu.org
2014-06-12 13:05 ` rguenth at gcc dot gnu.org
2022-01-05 10:17 ` pinskia at gcc dot gnu.org

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