public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110437] New: SIGILL when return missing in a C++ function with a condition
@ 2023-06-27 17:03 jan.zizka at nokia dot com
  2023-06-27 17:13 ` [Bug c++/110437] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: jan.zizka at nokia dot com @ 2023-06-27 17:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110437
           Summary: SIGILL when return missing in a C++ function with a
                    condition
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jan.zizka at nokia dot com
  Target Milestone: ---

Created attachment 55404
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55404&action=edit
Reproducer fails with g++

With gcc 13 following code triggers SIGILL:

#include<iostream>

int func1() {
        int value = 1;
        if (value == 1) {
                std::cout << "ONE" << std::endl;
        } else {
                std::cout << "ZERO" << std::endl;
        }
}

int main() {
        func1();
}

To reproduce:

g++ -o reproduce reproduce.cpp
./reproduce

Resulting with:

ONE
[1]    19714 illegal hardware instruction (core dumped)  ./reproduce

Warning is generated by compiler:

reproduce.cpp: In function ‘int func1()’:
reproduce.cpp:10:1: warning: no return statement in function returning non-void
[-Wreturn-type]
   10 | }
      | ^

With similar C code the SIGILL is not triggered:

#include<stdio.h>

int func1() {
        int value = 1;
        if (value == 1) {
                printf("ONE\n");
        } else {
                printf("ZERO\n");
        }
}

int main() {
        func1();
}

Warning is still generated with -Wall.

Is there some reason this behaves differently in C and C++? And shouldn't
rather compiler throw error instead of warning if this will crash in runtime?
We have caught this on some very old legacy code which just had missing return
statement and with upgrade to gcc 13.1.1 we have started to see SIGILL in
runtime.

Based on disassembled code the compiler emits ud2 instruction triggering
SIGILL.

With gcc 12.2 at least the same code doesn't trigger SIGILL. I didn't check the
disassembly.

I have run this on Fedora 38 and I didn't try to bisect which exact commit
triggers this. If it would be useful I can run bisect.

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

end of thread, other threads:[~2023-06-28  8:32 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-27 17:03 [Bug c++/110437] New: SIGILL when return missing in a C++ function with a condition jan.zizka at nokia dot com
2023-06-27 17:13 ` [Bug c++/110437] " pinskia at gcc dot gnu.org
2023-06-27 17:19 ` pinskia at gcc dot gnu.org
2023-06-27 17:28 ` jan.zizka at nokia dot com
2023-06-27 17:30 ` pinskia at gcc dot gnu.org
2023-06-27 17:31 ` pinskia at gcc dot gnu.org
2023-06-27 17:46 ` jan.zizka at nokia dot com
2023-06-27 17:52 ` pinskia at gcc dot gnu.org
2023-06-27 18:02 ` jan.zizka at nokia dot com
2023-06-27 20:10 ` redi at gcc dot gnu.org
2023-06-27 20:22 ` jan.zizka at nokia dot com
2023-06-28  7:55 ` xry111 at gcc dot gnu.org
2023-06-28  8:02 ` jan.zizka at nokia dot com
2023-06-28  8:32 ` redi 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).