public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100068] New: inconsistent handling of noreturn on nested function declarations
@ 2021-04-13 18:47 msebor at gcc dot gnu.org
  2021-04-13 18:53 ` [Bug c/100068] " msebor at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-13 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100068
           Summary: inconsistent handling of noreturn on nested function
                    declarations
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

For the test case below, in f1() GCC (in both C and C++ modes) emits just one
call to g1() while Clang, ICC emit two.  Visual C gives an error for the
noreturn mismatch between the two declarations of g1().

In f0(), all compilers emit just one call to g0() (Visual C with optimization;
without optimization it warns about the second call to g0() being unreachable).

$ cat a.c && gcc -O -S -Wall -fdump-tree-optimized=/dev/stdout a.c

void f0 (void)
{
  extern __attribute__ ((noreturn)) int g0 (void);

  {
    extern int g0 (void);
  }

  g0 ();
  g0 ();   // eliminated by all tested compilers
}

void f1 (void)
{ 
  extern int g1 (void);

  {
    extern __attribute__ ((noreturn)) int g1 (void);
  }

  g1 ();
  g1 ();   // eliminated by GCC, emitted by Clang and ICC
} 


;; Function f0 (f0, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0)
(executed once)

void f0 ()
{
  <bb 2> [local count: 1073741824]:
  g0 ();

}



;; Function f1 (f1, funcdef_no=1, decl_uid=1952, cgraph_uid=2, symbol_order=1)
(executed once)

void f1 ()
{
  <bb 2> [local count: 1073741824]:
  g1 ();

}

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

* [Bug c/100068] inconsistent handling of noreturn on nested function declarations
  2021-04-13 18:47 [Bug c/100068] New: inconsistent handling of noreturn on nested function declarations msebor at gcc dot gnu.org
@ 2021-04-13 18:53 ` msebor at gcc dot gnu.org
  2021-04-13 19:10 ` msebor at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-13 18:53 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=99420
           Keywords|                            |wrong-code

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
I noticed this while testing my fix for pr99420.  I don't think it's terribly
important so the bug is mainly to record the difference between GCC and other
compilers.  Rather than trying to change the code GCC emits to match other
compilers I would suggest to solve the problem by issuing a diagnostic for the
"mismatched" declarations.

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

* [Bug c/100068] inconsistent handling of noreturn on nested function declarations
  2021-04-13 18:47 [Bug c/100068] New: inconsistent handling of noreturn on nested function declarations msebor at gcc dot gnu.org
  2021-04-13 18:53 ` [Bug c/100068] " msebor at gcc dot gnu.org
@ 2021-04-13 19:10 ` msebor at gcc dot gnu.org
  2021-04-13 20:05 ` pinskia at gcc dot gnu.org
  2021-04-13 21:43 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-13 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |diagnostic

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
On second thought, and after reading what C and C++ say about noreturn, I don't
think it's wrong to emit just one call to either g0() or g1() in the test case.
 C in particular specifies that:

  A function declared with a _Noreturn function specifier shall not return to
its caller.

so declaring a function _Noreturn once is enough to grant the permission to
eliminate subsequent code regardless of any intervening redeclarations of the
function.  Let me change the Keywords from wrong-code to missing diagnostic.

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

* [Bug c/100068] inconsistent handling of noreturn on nested function declarations
  2021-04-13 18:47 [Bug c/100068] New: inconsistent handling of noreturn on nested function declarations msebor at gcc dot gnu.org
  2021-04-13 18:53 ` [Bug c/100068] " msebor at gcc dot gnu.org
  2021-04-13 19:10 ` msebor at gcc dot gnu.org
@ 2021-04-13 20:05 ` pinskia at gcc dot gnu.org
  2021-04-13 21:43 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-04-13 20:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
What diagnostic is missing?  That there is unreachable code after the noreturn
functions?  There are other bugs for that already?

Or diagnostic when merging the two decls and one was noreturn and the other was
not?

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

* [Bug c/100068] inconsistent handling of noreturn on nested function declarations
  2021-04-13 18:47 [Bug c/100068] New: inconsistent handling of noreturn on nested function declarations msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-04-13 20:05 ` pinskia at gcc dot gnu.org
@ 2021-04-13 21:43 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-13 21:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
The latter: in f1() warn for the redeclaration of g1() in the nested scope. 
That's where GCC and other compilers differ.

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

end of thread, other threads:[~2021-04-13 21:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 18:47 [Bug c/100068] New: inconsistent handling of noreturn on nested function declarations msebor at gcc dot gnu.org
2021-04-13 18:53 ` [Bug c/100068] " msebor at gcc dot gnu.org
2021-04-13 19:10 ` msebor at gcc dot gnu.org
2021-04-13 20:05 ` pinskia at gcc dot gnu.org
2021-04-13 21:43 ` msebor 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).