Re: [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning

From: Nick Desaulniers
Date: Fri Aug 25 2023 - 18:53:29 EST


On Fri, Aug 25, 2023 at 3:49 PM Justin Stitt <justinstitt@xxxxxxxxxx> wrote:
>
> On Fri, Aug 25, 2023 at 3:17 PM Wolfram Sang <wsa@xxxxxxxxxx> wrote:
> >
> >
> > > Note: I think something like this may be more readable:
> > > | *i2c_types = (enum pxa_i2c_types)(uintptr_t)of_id->data;
> > >
> > > Thoughts on this approach against the one present in this patch?
> >
> > On the one hand, I think this is more explicit and, thus, more readable.
> > On the other hand, we still have the loss of precision, between the
> > first and the second cast. Which gives it a bit of a "let's hide it
> > somewhat so the compiler will be happy" feeling?
> >
> There was some discussion [1] wherein it was ultimately decided that
> this warning should probably be turned off (contrary to what the title
> of the GitHub issue says).
>
> The state of these patches [2] is in some sort of limbo until I get a
> patch in to disable the warning from W=1 (keep in mind GCC doesn't
> even support this specific warning). I want to make the patch but am
> seeking some guidance about what exactly is to be done -- I feel a
> simply _demotion_ from W=1 to W=2 would suffice as CI robots aren't
> testing w/ that AFAIK.
>
> Nick, do you have anything to add here as we had previously discussed
> this off-list/IRL.

Mostly that we should make -fsanitize=enum not totally suck (i.e.
actually do anything for C code, then check for bad conversions from
values that aren't valid enumeration values including truncations),
then disable this warning in favor of folks testing with that
sanitizer enabled.

>
> [1]: https://github.com/ClangBuiltLinux/linux/issues/1910
> [2]: https://lore.kernel.org/all/?q=b%3Apointer-to-enum-cast



--
Thanks,
~Nick Desaulniers