public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/109554] New: Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body
@ 2023-04-19 11:47 xvladsoft at yahoo dot com
  2023-04-19 11:54 ` [Bug c/109554] " schwab@linux-m68k.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: xvladsoft at yahoo dot com @ 2023-04-19 11:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109554
           Summary: Compiler generates incorrect code when the function
                    declared with returned parameterm but no 'return' in
                    its body
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xvladsoft at yahoo dot com
  Target Milestone: ---

Created attachment 54883
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54883&action=edit
The source file which shows issue.

Good day!

First of all, thanks alot for you efforts to create so nice compiler! It is
really nice: generates small and fast code!

But looks like I found an issue: the compiler does not generate a 'return
point' where the function is declared with not-void return parameter, but no
'return' operators in its body.

Details:
  *** 1) Operation system:
uname -a
Linux XVlad-Work 4.19.0-22-amd64 #1 SMP Debian 4.19.260-1 (2022-09-29) x86_64
GNU/Linux
  *** 2) Compiler version (according to https://gcc.godbolt.org/ issue
reproduces from 8.3.0 till the latest (12.+)):
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6'
--with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-8
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6) 

  *** 3) Command line to compile:
gcc -O3 ./SandBox_2.cpp
  *** 4) Command line to execute:
./a.out 0

Observations:
Please, look at the code in the attached file: 
 - when it is compiled as:
/GccBug$ gcc -O0 ./SandBox_2.cpp
 - program executes correctly:
/GccBug$ ./a.out 0
Hello world from SandBox-2!
8.3.0
Point-A 0, 0
 - *BUT* when it is compiled as:
/GccBug$ gcc -O3 ./SandBox_2.cpp
 - program crashes:
/GccBug$ ./a.out 0
Hello world from SandBox-2!
8.3.0
Point-A 0, 0
Point-B 1, 0
Segmentation fault    <<<!!!!!!!


Best regards,
Vladimir.

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

* [Bug c/109554] Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body
  2023-04-19 11:47 [Bug c/109554] New: Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body xvladsoft at yahoo dot com
@ 2023-04-19 11:54 ` schwab@linux-m68k.org
  2023-04-19 11:56 ` [Bug c++/109554] " xry111 at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: schwab@linux-m68k.org @ 2023-04-19 11:54 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
Failure to return a value in a non-void function invokes undefined behaviour. 
For C++ this is independent of whether the caller uses the return value.

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

* [Bug c++/109554] Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body
  2023-04-19 11:47 [Bug c/109554] New: Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body xvladsoft at yahoo dot com
  2023-04-19 11:54 ` [Bug c/109554] " schwab@linux-m68k.org
@ 2023-04-19 11:56 ` xry111 at gcc dot gnu.org
  2023-04-19 14:29 ` xvladsoft at yahoo dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-04-19 11:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
And it's clearly documented in https://gcc.gnu.org/gcc-8/changes.html:

Flowing off the end of a non-void function is considered unreachable and may be
subject to optimization on that basis. As a result of this change,
-Wreturn-type warnings are enabled by default for C++.

If you insist on ignoring the -Wreturn-type warning, you are doing things
wrong.

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

* [Bug c++/109554] Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body
  2023-04-19 11:47 [Bug c/109554] New: Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body xvladsoft at yahoo dot com
  2023-04-19 11:54 ` [Bug c/109554] " schwab@linux-m68k.org
  2023-04-19 11:56 ` [Bug c++/109554] " xry111 at gcc dot gnu.org
@ 2023-04-19 14:29 ` xvladsoft at yahoo dot com
  2023-04-19 15:15 ` schwab@linux-m68k.org
  2023-06-27 17:51 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: xvladsoft at yahoo dot com @ 2023-04-19 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

Khokholkov Vladimir <xvladsoft at yahoo dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |WONTFIX

--- Comment #3 from Khokholkov Vladimir <xvladsoft at yahoo dot com> ---
(In reply to Xi Ruoyao from comment #2)
> And it's clearly documented in https://gcc.gnu.org/gcc-8/changes.html:
> 
> Flowing off the end of a non-void function is considered unreachable and may
> be subject to optimization on that basis. As a result of this change,
> -Wreturn-type warnings are enabled by default for C++.
> 
> If you insist on ignoring the -Wreturn-type warning, you are doing things
> wrong.

I see...
Ok, thanks!
I think the issue should be closed then.
(P.S. I do not ignore that message, just accidentally found this case and
decided to investigate).

B.R.
Vladimir.

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

* [Bug c++/109554] Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body
  2023-04-19 11:47 [Bug c/109554] New: Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body xvladsoft at yahoo dot com
                   ` (2 preceding siblings ...)
  2023-04-19 14:29 ` xvladsoft at yahoo dot com
@ 2023-04-19 15:15 ` schwab@linux-m68k.org
  2023-06-27 17:51 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: schwab@linux-m68k.org @ 2023-04-19 15:15 UTC (permalink / raw)
  To: gcc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|WONTFIX                     |INVALID

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

* [Bug c++/109554] Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body
  2023-04-19 11:47 [Bug c/109554] New: Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body xvladsoft at yahoo dot com
                   ` (3 preceding siblings ...)
  2023-04-19 15:15 ` schwab@linux-m68k.org
@ 2023-06-27 17:51 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-27 17:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |DUPLICATE

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

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

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

end of thread, other threads:[~2023-06-27 17:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-19 11:47 [Bug c/109554] New: Compiler generates incorrect code when the function declared with returned parameterm but no 'return' in its body xvladsoft at yahoo dot com
2023-04-19 11:54 ` [Bug c/109554] " schwab@linux-m68k.org
2023-04-19 11:56 ` [Bug c++/109554] " xry111 at gcc dot gnu.org
2023-04-19 14:29 ` xvladsoft at yahoo dot com
2023-04-19 15:15 ` schwab@linux-m68k.org
2023-06-27 17:51 ` 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).