public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/109528] New: Calling exit() at the end of function triggers infinite recursion warning
@ 2023-04-15 17:12 stavros9899 at gmail dot com
2023-04-15 19:10 ` [Bug c/109528] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: stavros9899 at gmail dot com @ 2023-04-15 17:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109528
Bug ID: 109528
Summary: Calling exit() at the end of function triggers
infinite recursion warning
Product: gcc
Version: 12.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: stavros9899 at gmail dot com
Target Milestone: ---
Created attachment 54868
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54868&action=edit
code that triggers the warning
Hello, this codem falsy -imo- triggers infinite-recursion warning. The
interesting thing is that the error goes away when the last exit(), at the near
end of the function gets removed.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/109528] Calling exit() at the end of function triggers infinite recursion warning
2023-04-15 17:12 [Bug c/109528] New: Calling exit() at the end of function triggers infinite recursion warning stavros9899 at gmail dot com
@ 2023-04-15 19:10 ` pinskia at gcc dot gnu.org
2023-04-15 19:15 ` [Bug c/109528] function with _Noreturn triggers infinite recursion warning while using the attribute does not pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-15 19:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109528
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|analyzer |c
Keywords| |diagnostic
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually it looks more like _Noreturn is not take effect on the declaration.
If I use __attribute__((noreturn)) or [[gnu::noreturn]] (or on the trunk
[[noreturn]] which is part of C23) instead, it just works.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/109528] function with _Noreturn triggers infinite recursion warning while using the attribute does not
2023-04-15 17:12 [Bug c/109528] New: Calling exit() at the end of function triggers infinite recursion warning stavros9899 at gmail dot com
2023-04-15 19:10 ` [Bug c/109528] " pinskia at gcc dot gnu.org
@ 2023-04-15 19:15 ` pinskia at gcc dot gnu.org
2023-04-15 19:19 ` [Bug middle-end/109528] " pinskia at gcc dot gnu.org
2023-04-16 5:21 ` stavros9899 at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-15 19:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109528
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Summary|Calling exit() at the end |function with _Noreturn
|of function triggers |triggers infinite recursion
|infinite recursion warning |warning while using the
| |attribute does not
Status|UNCONFIRMED |NEW
Last reconfirmed| |2023-04-15
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
#if 1
#define noreturn _Noreturn
#else
#define noreturn [[gnu::noreturn]]
#endif
struct tree_node {
unsigned nr_children;
char name[16];
struct tree_node *children;
};
noreturn void fork_my_tree(const struct tree_node* pRoot)
{
for (unsigned i = 0u; i < pRoot->nr_children; i++)
fork_my_tree(pRoot->children + i);
__builtin_exit(0);
}
```
Changing `#if 1` to `#if 0` fixes the warning.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/109528] function with _Noreturn triggers infinite recursion warning while using the attribute does not
2023-04-15 17:12 [Bug c/109528] New: Calling exit() at the end of function triggers infinite recursion warning stavros9899 at gmail dot com
2023-04-15 19:10 ` [Bug c/109528] " pinskia at gcc dot gnu.org
2023-04-15 19:15 ` [Bug c/109528] function with _Noreturn triggers infinite recursion warning while using the attribute does not pinskia at gcc dot gnu.org
@ 2023-04-15 19:19 ` pinskia at gcc dot gnu.org
2023-04-16 5:21 ` stavros9899 at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-15 19:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109528
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c |middle-end
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
/* Avoid diagnosing an apparently infinitely recursive function that
doesn't return where the infinite recursion might be avoided by
a call to another noreturn function. */
noreturn_p = lookup_attribute ("noreturn", DECL_ATTRIBUTES (m_func->decl));
This is the wrong check. It should use "flags_from_decl_or_type (m_func->decl)
& ECF_NOTHROW" instead or even just TREE_THIS_VOLATILE here.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/109528] function with _Noreturn triggers infinite recursion warning while using the attribute does not
2023-04-15 17:12 [Bug c/109528] New: Calling exit() at the end of function triggers infinite recursion warning stavros9899 at gmail dot com
` (2 preceding siblings ...)
2023-04-15 19:19 ` [Bug middle-end/109528] " pinskia at gcc dot gnu.org
@ 2023-04-16 5:21 ` stavros9899 at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: stavros9899 at gmail dot com @ 2023-04-16 5:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109528
--- Comment #4 from Stavros Avramidis <stavros9899 at gmail dot com> ---
The warning makes a bit more sense now, I was thinking gcc was getting confused
about function ending after calling the internal exits().
Anyways, I can confirm that it works with `[[gnu::noreturn]]`
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-04-16 5:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-15 17:12 [Bug c/109528] New: Calling exit() at the end of function triggers infinite recursion warning stavros9899 at gmail dot com
2023-04-15 19:10 ` [Bug c/109528] " pinskia at gcc dot gnu.org
2023-04-15 19:15 ` [Bug c/109528] function with _Noreturn triggers infinite recursion warning while using the attribute does not pinskia at gcc dot gnu.org
2023-04-15 19:19 ` [Bug middle-end/109528] " pinskia at gcc dot gnu.org
2023-04-16 5:21 ` stavros9899 at gmail dot com
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).