public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "hpa at zytor dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/96054] New: RFE: __attribute__((fatal)) Date: Sat, 04 Jul 2020 05:26:15 +0000 [thread overview] Message-ID: <bug-96054-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96054 Bug ID: 96054 Summary: RFE: __attribute__((fatal)) Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: hpa at zytor dot com Target Milestone: --- __attribute__((error)) and __attribute__((warning)) are useful, but have, in some places, poor semantics. It would be really good to have a function attribute which would trigger if "all roads lead to Rome", but would allow the function to be called dynamically at runtime under other circumstances. A good example on when this applies is a failure case in a default statement of a switch, or as a way to trap assert() at compile time. Specifically, to avoid impossible-to-analyze conditions involving functions never called and functions potentially not returning (e.g. calling longjmp()), I propose the following semantics: "For any function that is itself not marked "fatal", if the compiler can determine at compile time that there exists no control flow path between function entry and function return that does not call a function marked "fatal", issue a compile-time diagnostic." This diagnostic would presumably be a warning, that the user can promote to error during development. There may be better way to accomplish this, but something like it would be very useful. For example: extern void __attribute__((noreturn,fatal)) panic(void); extern void myfunc(void); extern int stuff(void); extern int more_stuff(void); int foo(int x) { x &= 3; myfunc(); switch (x) { case 4: x = stuff(); break; case 5: x = more_stuff(); break; case 6: break; /* leave x unchanged */ default: panic(); break; /* we can catch this error at compile time! */ } return x; }
next reply other threads:[~2020-07-04 5:26 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-04 5:26 hpa at zytor dot com [this message] 2021-12-18 11:42 ` [Bug c/96054] " egallager at gcc dot gnu.org 2022-11-14 20:04 ` hpa at zytor dot com
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-96054-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: linkBe 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).