public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64786] New: Eliminate exceptions thrown/caught inside a function
@ 2015-01-25 14:01 olegendo at gcc dot gnu.org
  2015-01-25 14:27 ` [Bug c++/64786] " glisse at gcc dot gnu.org
  2024-03-19 22:23 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: olegendo at gcc dot gnu.org @ 2015-01-25 14:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64786
           Summary: Eliminate exceptions thrown/caught inside a function
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: olegendo at gcc dot gnu.org

If I'm not mistaken, in the following example:

int test (int a, int b, int* c)
{
  enum err_a_t { ERR_A };
  enum err_b_t { ERR_B };

  try
  {
    if ((a + b) == 123)
      throw ERR_A;

    if ((a - b) == 5)
      throw ERR_B;

    for (int i = 0; i < b; ++i)
      c[i] = 4;

    return 0;
  }
  catch (err_a_t)
  {
    c[0] = 0;
    return -1;
  }
  catch (err_b_t)
  {
    c[0] = 1;
    return -1;
  }
  catch (...)
  {
    __builtin_abort ();
  }
}

... the exceptions can be eliminated and converted into something like this
unless -fnon-call-exceptions is used (the mem accesses could throw).

int test (int a, int b, int* c)
{
  if ((a + b) == 123)
  {
    c[0] = 0;
    return -1;
  }

  if ((a - b) == 5)
  {
    c[0] = 0;
    return -1;
  }

  for (int i = 0; i < b; ++i)
    c[i] = 4;

  return 0;
}

.. because all possible exceptions are known and are also known to be caught in
the function itself and there's nothing to stack-unwind.


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

* [Bug c++/64786] Eliminate exceptions thrown/caught inside a function
  2015-01-25 14:01 [Bug c++/64786] New: Eliminate exceptions thrown/caught inside a function olegendo at gcc dot gnu.org
@ 2015-01-25 14:27 ` glisse at gcc dot gnu.org
  2024-03-19 22:23 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-01-25 14:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
See also PR53294 and PR64501.


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

* [Bug c++/64786] Eliminate exceptions thrown/caught inside a function
  2015-01-25 14:01 [Bug c++/64786] New: Eliminate exceptions thrown/caught inside a function olegendo at gcc dot gnu.org
  2015-01-25 14:27 ` [Bug c++/64786] " glisse at gcc dot gnu.org
@ 2024-03-19 22:23 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-19 22:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.

*** This bug has been marked as a duplicate of bug 38658 ***

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

end of thread, other threads:[~2024-03-19 22:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-25 14:01 [Bug c++/64786] New: Eliminate exceptions thrown/caught inside a function olegendo at gcc dot gnu.org
2015-01-25 14:27 ` [Bug c++/64786] " glisse at gcc dot gnu.org
2024-03-19 22:23 ` 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).