This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow][NFC] Fix reachability warning.
ClosedPublic

Authored by ymandel on Oct 14 2022, 11:35 AM.

Details

Summary

While cases of the switch return (or are unreachable), if a non-enum integer was cast into the enum, it's possible for this switch to fall through without returning, hence allowing control to reach the end of a non-void function. So, we explicitly mark with llvm_unreachable after the switch.

Diff Detail

Event Timeline

ymandel created this revision.Oct 14 2022, 11:35 AM
Herald added a project: Restricted Project. · View Herald Transcript
ymandel requested review of this revision.Oct 14 2022, 11:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2022, 11:35 AM
xazax.hun accepted this revision.Oct 14 2022, 11:38 AM

I'd argue the warning is correct as you could store "non-enum" integer values into an enum typed variable (and people do that fairly often with bitwise enums).

This revision is now accepted and ready to land.Oct 14 2022, 11:38 AM

I'd argue the warning is correct as you could store "non-enum" integer values into an enum typed variable (and people do that fairly often with bitwise enums).

Good point. Feels wrong, but is perfectly legal in C++. :(

ymandel edited the summary of this revision. (Show Details)Oct 14 2022, 12:30 PM
This revision was automatically updated to reflect the committed changes.