Bug 239290
Summary: | Misc compiler warnings, April 2022 edition | ||
---|---|---|---|
Product: | WebKit | Reporter: | Michael Catanzaro <mcatanzaro> |
Component: | WebKit Misc. | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED FIXED | ||
Severity: | Normal | CC: | mcatanzaro, webkit-bug-importer, ysuzuki |
Priority: | P2 | Keywords: | InRadar |
Version: | WebKit Nightly Build | ||
Hardware: | PC | ||
OS: | Linux |
Michael Catanzaro
Misc compiler warnings, April 2022 edition
I'm starting to get tired of -Wreturn-type....
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Michael Catanzaro
https://github.com/WebKit/WebKit/pull/282
EWS
Committed r292840 (249613@main): <https://commits.webkit.org/249613@main>
Reviewed commits have been landed. Closing PR #282 and removing active labels.
Radar WebKit Bug Importer
<rdar://problem/91720326>
Yusuke Suzuki
Please do not attach RELEASE_ASSERT_NOT_REACHED here. Some of them are super hot critical function, and it hurts our performance. Use 269IGNORE_RETURN_TYPE_WARNINGS_BEGIN
Yusuke Suzuki
Committed r293018 (249757@trunk): <https://commits.webkit.org/249757@trunk>
Michael Catanzaro
ack, thanks for catching it! How scary. :(
It will happen again in the future, though, because I can't know where these areas may be, and we keep introducing more and more return type warnings. These make up probably >50% of the GCC warnings that I deal with.
One option is to give up and build with -Wno-return-type, because fixing up switch statements is getting pretty old. But sadly, it does seem like a useful warning except for this pattern with switch statements, so I'm a bit hesitant to do that.
Yusuke Suzuki
(In reply to Michael Catanzaro from comment #6)
> ack, thanks for catching it! How scary. :(
>
> It will happen again in the future, though, because I can't know where these
> areas may be, and we keep introducing more and more return type warnings.
> These make up probably >50% of the GCC warnings that I deal with.
>
> One option is to give up and build with -Wno-return-type, because fixing up
> switch statements is getting pretty old. But sadly, it does seem like a
> useful warning except for this pattern with switch statements, so I'm a bit
> hesitant to do that.
Can GCC have a mechanism like this? I think it can suppress most of false positives.
1. emitting this warning for normal enum case
2. not emitting this for strongly scoped enum when switch handles all scoped enums
Michael Catanzaro
GCC does have many options (-Wswitch, -Wswitch-default, and -Wswitch-enum) to get exactly your preferred warnings for missing switch cases, but -Wreturn-type is orthogonal to those.
Michael Catanzaro
Did some searching... it seems C++23 has a solution for this, std::unreachable():
https://en.cppreference.com/w/cpp/utility/unreachable
In the meantime, we could add a WTF_UNREACHABLE() macro fairly easily, which could replace most use of RELEASE_ASSERT_NOT_REACHED() after switch statements that are intended to always return. Hopefully that would allow us to avoid the performance hit in these locations? Then we wouldn't have to worry about this happening again. (I know it takes you ages to track it down performance regressions....)
Michael Catanzaro
I see we already have UNREACHABLE_FOR_PLATFORM in Assertions.h, but it just calls RELEASE_ASSERT_NOT_REACHED() with a warning not to change that. <_<