Page MenuHomePhabricator

[Sema] Add -Wpointer-to-enum-cast and -Wvoid-pointer-to-enum-cast

Authored by nathanchance on Mar 6 2020, 9:24 AM.



GCC does not warn on casts from pointers to enumerators, while clang
currently does:

This causes a bunch of extra warnings in the Linux kernel, where
certain structs contain a void pointer to avoid using a gigantic
union for all of the various types of driver data, such as

Add a diagnostic that allows certain projects like the kernel to
disable the warning just for enums, which allows those projects to
keep full compatibility with GCC but keeps the intention of treating
casts to integers and enumerators the same by default so that other
projects have the opportunity to catch issues not noticed before (or
follow suite and disable the warning).


Diff Detail

Event Timeline

nathanchance created this revision.Mar 6 2020, 9:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2020, 9:24 AM

Thanks, Verified that this fixes the kernel warnings in my local builds with!

xbolva00 added inline comments.

You can reuse warning text:


I think..

nathanchance edited the summary of this revision. (Show Details)
nathanchance marked 2 inline comments as done.
nathanchance added inline comments.

Thanks, that is indeed cleaner!

rjmccall accepted this revision.Mar 7 2020, 1:55 PM
This revision is now accepted and ready to land.Mar 7 2020, 1:55 PM
nathanchance marked an inline comment as done.Mar 7 2020, 2:08 PM

Thanks for the review and accepting. I do not have commit rights, would you mind doing that on my behalf?

MaskRay added a subscriber: MaskRay.Mar 7 2020, 4:43 PM
MaskRay added inline comments.

A ternary operator is better here. I'll fix it.

This revision was automatically updated to reflect the committed changes.