public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106163] New: generic-match does not honor -fnon-call-exceptions -fno-delete-dead-exceptions
@ 2022-07-01 22:32 ian at airs dot com
  2022-07-01 22:34 ` [Bug tree-optimization/106163] " ian at airs dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ian at airs dot com @ 2022-07-01 22:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106163
           Summary: generic-match does not honor -fnon-call-exceptions
                    -fno-delete-dead-exceptions
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ian at airs dot com
  Target Milestone: ---

When using -fnon-call-exceptions -fno-delete-dead-exceptions memory operations
that are not marked TREE_THIS_NOTRAP should not be removed from the execution
path.  However, the generic_simplify function, at least, does not honor this.

This test case, when compiled with -fnon-call-exceptions
-fno-delete-dead-exceptions, should exit with a zero status.  However, it
currently fails, because "i = *p ^ *p;" is simplified to "i = 0;".

// { dg-do run { target { i?86-*-linux* i?86-*-gnu* x86_64-*-linux* } } }
// { dg-additional-options "-fexceptions -fnon-call-exceptions
-fno-delete-dead-exceptions" }

#include <signal.h>
#include <stdlib.h>
#include <string.h>

static void
sighandler (int signo, siginfo_t* si, void* uc)
{
  throw (5);
}

struct S { void *p1, *p2; };

struct S v;

__attribute__ ((noinline))
int
dosegv ()
{
  int *p = 0;
  int i __attribute__((unused)) = 0;
  i = *p ^ *p;
  return 0;
}

int main ()
{
  struct sigaction sa;

  memset (&sa, 0, sizeof sa);
  sa.sa_sigaction = sighandler;
  sigaction (SIGSEGV, &sa, NULL);
  sigaction (SIGBUS, &sa, NULL);

  try {
    dosegv ();
  }
  catch (int x) {
    return (x != 5);
  }

  return 1;
}

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

* [Bug tree-optimization/106163] generic-match does not honor -fnon-call-exceptions -fno-delete-dead-exceptions
  2022-07-01 22:32 [Bug tree-optimization/106163] New: generic-match does not honor -fnon-call-exceptions -fno-delete-dead-exceptions ian at airs dot com
@ 2022-07-01 22:34 ` ian at airs dot com
  2022-07-01 22:43 ` pinskia at gcc dot gnu.org
  2022-07-04  6:31 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ian at airs dot com @ 2022-07-01 22:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Ian Lance Taylor <ian at airs dot com> ---
This was originally reported against gccgo at https://go.dev/issue/53019.

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

* [Bug tree-optimization/106163] generic-match does not honor -fnon-call-exceptions -fno-delete-dead-exceptions
  2022-07-01 22:32 [Bug tree-optimization/106163] New: generic-match does not honor -fnon-call-exceptions -fno-delete-dead-exceptions ian at airs dot com
  2022-07-01 22:34 ` [Bug tree-optimization/106163] " ian at airs dot com
@ 2022-07-01 22:43 ` pinskia at gcc dot gnu.org
  2022-07-04  6:31 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-07-01 22:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Most likely the code here needs to be changed slightly.
                  fprintf_indent (f, indent,
                                  "if (TREE_SIDE_EFFECTS (captures[%d]))\n",
                                  i);


Or maybe the code which sets TREE_SIDE_EFFECTS should be fixed ...

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

* [Bug tree-optimization/106163] generic-match does not honor -fnon-call-exceptions -fno-delete-dead-exceptions
  2022-07-01 22:32 [Bug tree-optimization/106163] New: generic-match does not honor -fnon-call-exceptions -fno-delete-dead-exceptions ian at airs dot com
  2022-07-01 22:34 ` [Bug tree-optimization/106163] " ian at airs dot com
  2022-07-01 22:43 ` pinskia at gcc dot gnu.org
@ 2022-07-04  6:31 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-04  6:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-07-04
             Status|UNCONFIRMED                 |NEW
                 CC|                            |rguenth at gcc dot gnu.org
           Keywords|                            |wrong-code

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  It's not entirely clear to me if exceptions need to be marked as
side-effect in GENERIC (when there's no explicit CFG or EH representation).
In genmatch it's probably

/* Generate matching code for the decision tree operand which is
   a capture-match.  */

unsigned
dt_operand::gen_match_op (FILE *f, int indent, const char *opname, bool)
{
  char match_opname[20];
  match_dop->get_name (match_opname);
  if (value_match)
    fprintf_indent (f, indent, "if ((%s == %s && ! TREE_SIDE_EFFECTS (%s)) "
                    "|| operand_equal_p (%s, %s, 0))\n",
                    opname, match_opname, opname, opname, match_opname);
  else
    fprintf_indent (f, indent, "if ((%s == %s && ! TREE_SIDE_EFFECTS (%s)) "
                    "|| (operand_equal_p (%s, %s, 0) "
                    "&& types_match (%s, %s)))\n",
                    opname, match_opname, opname, opname, match_opname,
                    opname, match_opname);
  fprintf_indent (f, indent + 2, "{\n");
  return 1;

where you can see the that we defer to operand_equal_p or do what that does
for the case of tree sharing (test TREE_SIDE_EFFECTS).

The issue is probably latent since even before match.pd (for GENERIC, that is),
so the fix probably needs to extend to operand_equal_p.

That said, there's somewhat of a point in the trees lacking TREE_SIDE_EFFECTS,
but of course an explicit honoring of tree_could_throw_p might be possible
as well.

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

end of thread, other threads:[~2022-07-04  6:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01 22:32 [Bug tree-optimization/106163] New: generic-match does not honor -fnon-call-exceptions -fno-delete-dead-exceptions ian at airs dot com
2022-07-01 22:34 ` [Bug tree-optimization/106163] " ian at airs dot com
2022-07-01 22:43 ` pinskia at gcc dot gnu.org
2022-07-04  6:31 ` rguenth 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).