On Wed, 5 Jul 2023, 14:13 Julian Waters, <tanksherma...@gmail.com> wrote:
> Hi Jonathan, > > Thanks for the reply, is there a place in gcc's source code I could look > at for this? > This is a commit where I added four new warnings, and then changed the code that issues those warnings to use the new OPT_Wxxx variables: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=ee336ecb2a7161bc28f6c5343d97870a8d15e177 You would want you do something similar. Define a warning in c.opt, then find where that warning is printed and change the 0 to OPT_Wreturn_in_noreturn (or whatever you call the new flag). More generally, new options go in gcc/c-fsmily/c.opt so there are several examples of adding new warnings in the history for that file: https://gcc.gnu.org/git/?p=gcc.git;a=history;f=gcc/c-family/c.opt;h=4abdc8d0e77c6bded20829e35ac550c3a1b994dd;hb=refs/heads/master As for the returning an explicit value from noreturn, I'm unfortunately not > the one who wrote the code that way; I'm merely a build systems developer > trying to get it to work with gcc :/ > > best regards, > Julian > > On Wed, 5 Jul 2023, 19:26 Jonathan Wakely, <jwakely....@gmail.com> wrote: > >> On Wed, 5 Jul 2023 at 12:01, Julian Waters via Gcc <gcc@gcc.gnu.org> >> wrote: >> > >> > I see, thanks Andrew. >> > >> > Anyone else have opinions on this besides Liu or Andrew? The responses >> have >> > been surprisingly quiet thus far >> >> IMHO all warnings should have an option controlling them, so that you >> can disable them via pragmas. >> >> But I agree that you shouldn't need to return from a noreturn >> function, it can either throw or use __builtin_unreachable() on the >> line where you currently return. >> >> >> > >> > best regards, >> > Julian >> > >> > On Wed, 5 Jul 2023, 09:40 Andrew Pinski, <pins...@gmail.com> wrote: >> > >> > > On Tue, Jul 4, 2023 at 6:32 PM Julian Waters <tanksherma...@gmail.com >> > >> > > wrote: >> > > > >> > > > Hi Andrew, thanks for the quick response, >> > > > >> > > > What if the method has a return value? I know it sounds >> > > counterintuitive, but in some places HotSpot relies on the noreturn >> > > attribute being applied to methods that do return a value in an >> unreachable >> > > code path. Does the unreachable builtin cover that case too? >> > > >> > > It is wrong to use noreturn on a function other than one which has a >> > > return type of void as documented. >> > > >> > > >> https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute >> > > : >> > > ``` >> > > It does not make sense for a noreturn function to have a return type >> > > other than void. >> > > ``` >> > > >> > > Thanks, >> > > Andrew Pinski >> > > >> > > >> > > > >> > > > best regards. >> > > > Julian >> > > > >> > > > On Wed, Jul 5, 2023 at 9:07 AM Andrew Pinski <pins...@gmail.com> >> wrote: >> > > >> >> > > >> On Tue, Jul 4, 2023 at 5:54 PM Julian Waters via Gcc < >> gcc@gcc.gnu.org> >> > > wrote: >> > > >> > >> > > >> > Hi all, >> > > >> > >> > > >> > Currently to disable the warning that a noreturn method does >> return, >> > > it's >> > > >> > required to disable warnings entirely. This can be very >> inconvenient >> > > when >> > > >> > -Werror is enabled with a noreturn method that isn't specifically >> > > calling >> > > >> > something like std::abort() at the end, when one wants all other >> > > -Wall and >> > > >> > -Wextra warnings to be reported, for instance in the Java >> HotSpot VM >> > > (which >> > > >> > I'm currently adapting to compile with gcc on all supported >> > > platforms). Is >> > > >> > there a possibility we can add a disable warning option >> specifically >> > > for >> > > >> > this case? Something like -Wno-returning-noreturn. I'm >> interested in >> > > adding >> > > >> > this myself if it's not convenient for gcc's maintainers to do >> so at >> > > the >> > > >> > moment, but I'd need some guidance on where to look and what the >> > > relevant >> > > >> > code is >> > > >> >> > > >> You could just add >> > > >> __builtin_unreachable(); (or std::unreachable(); if you are C++23 >> or >> > > >> unreachable() if you are using C23). >> > > >> Or even add while(true) ; >> > > >> >> > > >> I am pretty sure not having an option is on purpose and not really >> > > >> interested in adding an option here because of the above >> workarounds. >> > > >> >> > > >> Thanks, >> > > >> Andrew Pinski >> > > >> >> > > >> > >> > > >> > best regards, >> > > >> > Julian >> > > >> >