serenity icon indicating copy to clipboard operation
serenity copied to clipboard

LibJS: Add noreturn attribute to functions that doesn't return

Open filiphsps opened this issue 2 years ago • 4 comments

A few LibJS functions doesn't actually return anything which causes some compilers to error out. This commit adds the gcc noreturn attribute to them.

filiphsps avatar Jul 31 '22 04:07 filiphsps

Most raw __attribute__ have (should be?) replaced with the macros from AK/Platform.h. Doesn't look like there's one for NORETURN

ADKaster avatar Jul 31 '22 04:07 ADKaster

Most raw __attribute__ have (should be?) replaced with the macros from AK/Platform.h. Doesn't look like there's one for NORETURN

Fixed 🤠

filiphsps avatar Jul 31 '22 05:07 filiphsps

I don't like this - semantically these functions don't exist, not exist but don't return anything, so noreturn is the wrong tool. If your compiler is complaining about the lack of return statements, add some after the assertion instead.

They might not exist spec-wise. They do however exist in-code, which means that they should respect their return type (there are some other cases in LibJS where we actually return even if it's unreachable through VERIFY_NOT_REACHED).

filiphsps avatar Jul 31 '22 08:07 filiphsps

The reason windows based compilers complain about this is that in the windows C library, abort() is not [[no return]] like the C++ spec says it should be. An escape hatch for your build to disable Werror or a new definition of VERIFY/VERIFY_NOT_REACHED to point to some fancy inline noretun function for those platforms might be better

ADKaster avatar Jul 31 '22 08:07 ADKaster

As I said:

VERIFY_NOT_REACHED();
return {} / nullptr / whatever;

is a simple and acceptable solution that should work everywhere.

linusg avatar Jul 31 '22 09:07 linusg