public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jan.zizka at nokia dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/110437] New: SIGILL when return missing in a C++ function with a condition
Date: Tue, 27 Jun 2023 17:03:38 +0000	[thread overview]
Message-ID: <bug-110437-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2023-06-27 17:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27 17:03 jan.zizka at nokia dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110437-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).