public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111245] New: miscompilation: missing assignment when exception thrown
@ 2023-08-30 20:19 briangreenery at gmail dot com
  2023-08-30 20:26 ` [Bug ipa/111245] " briangreenery at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: briangreenery at gmail dot com @ 2023-08-30 20:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111245
           Summary: miscompilation: missing assignment when exception
                    thrown
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: briangreenery at gmail dot com
  Target Milestone: ---

gcc version 13.2.0 (Compiler-Explorer-Build-gcc--binutils-2.40) 
Target: x86_64-linux-gnu

It looks like initialization is incorrectly skipped when:

* The initialization is overwritten by an unconditional assignment from a
function
* However, that function throws an exception which avoids the assignment

The following code should return 5, but it returns random garbage on -O1 or
-O2.

https://godbolt.org/z/T3qTnheYW

# 0 "/app/example.cpp"
# 1 "/app//"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "/app/example.cpp"
struct Int {
  int value;
};

__attribute__((noipa)) Int always_throws() { throw 123; }

void foo(Int &x) {
  try {
    x = always_throws();
  } catch (...) {
  }
}

int main() {
  Int x;
  x.value = 5;
  foo(x);
  return x.value;
}

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

end of thread, other threads:[~2024-06-20  9:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-30 20:19 [Bug c++/111245] New: miscompilation: missing assignment when exception thrown briangreenery at gmail dot com
2023-08-30 20:26 ` [Bug ipa/111245] " briangreenery at gmail dot com
2023-08-30 21:42 ` [Bug ipa/111245] [12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-08-30 22:26 ` jakub at gcc dot gnu.org
2023-08-31 10:48 ` [Bug ipa/111245] [12/13/14 Regression] miscompilation: missing assignment when exception thrown since r12-5244-g64f3e71c302b4a13e61656ee509e7050b9bce978 rguenth at gcc dot gnu.org
2024-06-20  9:13 ` [Bug ipa/111245] [12/13/14/15 " 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).