Re: [PATCH] perf/x86/intel: Mark expected switch fall-throughs
From: Gustavo A. R. Silva
Date: Mon Jun 24 2019 - 16:53:20 EST
On 6/24/19 3:37 PM, Peter Zijlstra wrote:
> On Mon, Jun 24, 2019 at 12:45:54PM -0700, Joe Perches wrote:
>> On Mon, 2019-06-24 at 21:31 +0200, Peter Zijlstra wrote:
>>> On Mon, Jun 24, 2019 at 11:19:13AM -0500, Gustavo A. R. Silva wrote:
>>>> In preparation to enabling -Wimplicit-fallthrough, mark switch
>>>> cases where we are expecting to fall through.
>>>>
>>>> This patch fixes the following warnings:
>>>>
>>>> arch/x86/events/intel/core.c: In function âintel_pmu_initâ:
>>>> arch/x86/events/intel/core.c:4959:8: warning: this statement may fall through [-Wimplicit-fallthrough=]
>>>> pmem = true;
>>>> ~~~~~^~~~~~
>>>> arch/x86/events/intel/core.c:4960:2: note: here
>>>> case INTEL_FAM6_SKYLAKE_MOBILE:
>>>> ^~~~
>>>> arch/x86/events/intel/core.c:5008:8: warning: this statement may fall through [-Wimplicit-fallthrough=]
>>>> pmem = true;
>>>> ~~~~~^~~~~~
>>>> arch/x86/events/intel/core.c:5009:2: note: here
>>>> case INTEL_FAM6_ICELAKE_MOBILE:
>>>> ^~~~
>>>>
>>>> Warning level 3 was used: -Wimplicit-fallthrough=3
>>>>
>>>> This patch is part of the ongoing efforts to enable
>>>> -Wimplicit-fallthrough.
>>>>
>>>> Signed-off-by: Gustavo A. R. Silva <gustavo@xxxxxxxxxxxxxx>
>>>
>>> I still consider it an abomination that the C parser looks at comments
>>> -- other than to delete them, but OK I suppose, I'll take it.
>>
>> I still believe Arnaldo's/Miguel's/Shawn's/my et al. suggestion of
>>
>> #define __fallthrough __attribute__((fallthrough))
>>
>> is far better.
>>
>> https://lkml.org/lkml/2017/2/9/845
>> https://lkml.org/lkml/2017/2/10/485
>> https://lore.kernel.org/lkml/20181021171414.22674-2-miguel.ojeda.sandonis@xxxxxxxxx/
>> https://lore.kernel.org/lkml/20190617155643.GA32544@amd/
>
> Oh yes, worlds better. Please, can we haz that instead?
>
Once the C++17 `__attribute__((fallthrough))` is more widely handled by C compilers,
static analyzers, and IDEs, we can switch to using that instead. Also, we are a few
warnings away (less than five) from being able to enable -Wimplicit-fallthrough. After
this option has been finally enabled (in v5.3) we can easily go and replace the comments
to whatever we agree upon.
Thanks
--
Gustavo