* [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default
@ 2019-10-22 2:02 Marcos Paulo de Souza
2019-10-22 2:02 ` [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough) Marcos Paulo de Souza
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Marcos Paulo de Souza @ 2019-10-22 2:02 UTC (permalink / raw)
To: dsterba, linux-btrfs; +Cc: Marcos Paulo de Souza
From: Marcos Paulo de Souza <mpdesouza@suse.com>
While compiling btrfs-progs using clang I found an issue using
__attribute__(fallthrough), which does not seems to work in clang.
To solve this issue, the code was changed to use /* fallthrough */, which is the
same notation adopted by linux kernel.
Once these places were changed, -Wimplicit-fallthrough was set in Makefile, to
avoid further implicit-fallthrough cases being added in the future.
Marcos Paulo de Souza (2):
btrfs-progs: utils: Replace __attribute__(fallthrough)
btrfs-progs: Makefile: Add -Wimplicit-fallthrough
Makefile | 1 +
common/utils.c | 12 ++++++------
2 files changed, 7 insertions(+), 6 deletions(-)
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough)
2019-10-22 2:02 [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default Marcos Paulo de Souza
@ 2019-10-22 2:02 ` Marcos Paulo de Souza
2019-10-22 6:59 ` Nikolay Borisov
2019-10-22 2:02 ` [PATCH 2/2] btrfs-progs: Makefile: Add -Wimplicit-fallthrough Marcos Paulo de Souza
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Marcos Paulo de Souza @ 2019-10-22 2:02 UTC (permalink / raw)
To: dsterba, linux-btrfs; +Cc: Marcos Paulo de Souza
From: Marcos Paulo de Souza <mpdesouza@suse.com>
When compiling with clang, this warning is shown:
common/utils.c:404:3: warning: declaration does not declare anything [-Wmissing-declarations]
__attribute__ ((fallthrough));
This attribute seems to silence the same warning in GCC. Changing this
attribute with /* fallthrough */ fixes the warning for both gcc and
clang.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
common/utils.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/common/utils.c b/common/utils.c
index 2cf15c33..a88336b3 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -401,15 +401,15 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_size, unsigned unit_mod
case UNITS_TBYTES:
base *= mult;
num_divs++;
- __attribute__ ((fallthrough));
+ /* fallthrough */
case UNITS_GBYTES:
base *= mult;
num_divs++;
- __attribute__ ((fallthrough));
+ /* fallthrough */
case UNITS_MBYTES:
base *= mult;
num_divs++;
- __attribute__ ((fallthrough));
+ /* fallthrough */
case UNITS_KBYTES:
num_divs++;
break;
@@ -1135,14 +1135,14 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
default:
case 4:
allowed |= BTRFS_BLOCK_GROUP_RAID10;
- __attribute__ ((fallthrough));
+ /* fallthrough */
case 3:
allowed |= BTRFS_BLOCK_GROUP_RAID6;
- __attribute__ ((fallthrough));
+ /* fallthrough */
case 2:
allowed |= BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 |
BTRFS_BLOCK_GROUP_RAID5;
- __attribute__ ((fallthrough));
+ /* fallthrough */
case 1:
allowed |= BTRFS_BLOCK_GROUP_DUP;
}
--
2.23.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] btrfs-progs: Makefile: Add -Wimplicit-fallthrough
2019-10-22 2:02 [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default Marcos Paulo de Souza
2019-10-22 2:02 ` [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough) Marcos Paulo de Souza
@ 2019-10-22 2:02 ` Marcos Paulo de Souza
2019-10-22 12:41 ` [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default David Sterba
2019-10-22 12:45 ` Nikolay Borisov
3 siblings, 0 replies; 9+ messages in thread
From: Marcos Paulo de Souza @ 2019-10-22 2:02 UTC (permalink / raw)
To: dsterba, linux-btrfs; +Cc: Marcos Paulo de Souza
From: Marcos Paulo de Souza <mpdesouza@suse.com>
Avoid introducing new cases of implicit fallthrough by having this flag
always set.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/Makefile b/Makefile
index 21bf2717..2f04e880 100644
--- a/Makefile
+++ b/Makefile
@@ -86,6 +86,7 @@ CFLAGS = $(SUBST_CFLAGS) \
-D_XOPEN_SOURCE=700 \
-fno-strict-aliasing \
-fPIC \
+ -Wimplicit-fallthrough \
-I$(TOPDIR) \
-I$(TOPDIR)/libbtrfsutil \
$(DISABLE_WARNING_FLAGS) \
--
2.23.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough)
2019-10-22 2:02 ` [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough) Marcos Paulo de Souza
@ 2019-10-22 6:59 ` Nikolay Borisov
2019-10-22 7:01 ` Nikolay Borisov
0 siblings, 1 reply; 9+ messages in thread
From: Nikolay Borisov @ 2019-10-22 6:59 UTC (permalink / raw)
To: Marcos Paulo de Souza, dsterba, linux-btrfs; +Cc: Marcos Paulo de Souza
On 22.10.19 г. 5:02 ч., Marcos Paulo de Souza wrote:
> From: Marcos Paulo de Souza <mpdesouza@suse.com>
>
> When compiling with clang, this warning is shown:
>
> common/utils.c:404:3: warning: declaration does not declare anything [-Wmissing-declarations]
> __attribute__ ((fallthrough));
>
> This attribute seems to silence the same warning in GCC. Changing this
> attribute with /* fallthrough */ fixes the warning for both gcc and
> clang.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Which clang version are you using? According to
https://clang.llvm.org/docs/AttributeReference.html#fallthrough this
attribute is supported even with the GNU syntax.
> ---
> common/utils.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/common/utils.c b/common/utils.c
> index 2cf15c33..a88336b3 100644
> --- a/common/utils.c
> +++ b/common/utils.c
> @@ -401,15 +401,15 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_size, unsigned unit_mod
> case UNITS_TBYTES:
> base *= mult;
> num_divs++;
> - __attribute__ ((fallthrough));
> + /* fallthrough */
> case UNITS_GBYTES:
> base *= mult;
> num_divs++;
> - __attribute__ ((fallthrough));
> + /* fallthrough */
> case UNITS_MBYTES:
> base *= mult;
> num_divs++;
> - __attribute__ ((fallthrough));
> + /* fallthrough */
> case UNITS_KBYTES:
> num_divs++;
> break;
> @@ -1135,14 +1135,14 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
> default:
> case 4:
> allowed |= BTRFS_BLOCK_GROUP_RAID10;
> - __attribute__ ((fallthrough));
> + /* fallthrough */
> case 3:
> allowed |= BTRFS_BLOCK_GROUP_RAID6;
> - __attribute__ ((fallthrough));
> + /* fallthrough */
> case 2:
> allowed |= BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 |
> BTRFS_BLOCK_GROUP_RAID5;
> - __attribute__ ((fallthrough));
> + /* fallthrough */
> case 1:
> allowed |= BTRFS_BLOCK_GROUP_DUP;
> }
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough)
2019-10-22 6:59 ` Nikolay Borisov
@ 2019-10-22 7:01 ` Nikolay Borisov
2019-10-22 12:18 ` Marcos Paulo de Souza
0 siblings, 1 reply; 9+ messages in thread
From: Nikolay Borisov @ 2019-10-22 7:01 UTC (permalink / raw)
To: Marcos Paulo de Souza, dsterba, linux-btrfs; +Cc: Marcos Paulo de Souza
On 22.10.19 г. 9:59 ч., Nikolay Borisov wrote:
>
>
> On 22.10.19 г. 5:02 ч., Marcos Paulo de Souza wrote:
>> From: Marcos Paulo de Souza <mpdesouza@suse.com>
>>
>> When compiling with clang, this warning is shown:
>>
>> common/utils.c:404:3: warning: declaration does not declare anything [-Wmissing-declarations]
>> __attribute__ ((fallthrough));
>>
>> This attribute seems to silence the same warning in GCC. Changing this
>> attribute with /* fallthrough */ fixes the warning for both gcc and
>> clang.
>>
>> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
>
> Which clang version are you using? According to
> https://clang.llvm.org/docs/AttributeReference.html#fallthrough this
> attribute is supported even with the GNU syntax.
Looking at the documentation the gnu syntax is supported in the
'current' / 10, unreleased version. All others, up to version 9 does not
support this syntax.
>
>> ---
>> common/utils.c | 12 ++++++------
>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/common/utils.c b/common/utils.c
>> index 2cf15c33..a88336b3 100644
>> --- a/common/utils.c
>> +++ b/common/utils.c
>> @@ -401,15 +401,15 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_size, unsigned unit_mod
>> case UNITS_TBYTES:
>> base *= mult;
>> num_divs++;
>> - __attribute__ ((fallthrough));
>> + /* fallthrough */
>> case UNITS_GBYTES:
>> base *= mult;
>> num_divs++;
>> - __attribute__ ((fallthrough));
>> + /* fallthrough */
>> case UNITS_MBYTES:
>> base *= mult;
>> num_divs++;
>> - __attribute__ ((fallthrough));
>> + /* fallthrough */
>> case UNITS_KBYTES:
>> num_divs++;
>> break;
>> @@ -1135,14 +1135,14 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
>> default:
>> case 4:
>> allowed |= BTRFS_BLOCK_GROUP_RAID10;
>> - __attribute__ ((fallthrough));
>> + /* fallthrough */
>> case 3:
>> allowed |= BTRFS_BLOCK_GROUP_RAID6;
>> - __attribute__ ((fallthrough));
>> + /* fallthrough */
>> case 2:
>> allowed |= BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 |
>> BTRFS_BLOCK_GROUP_RAID5;
>> - __attribute__ ((fallthrough));
>> + /* fallthrough */
>> case 1:
>> allowed |= BTRFS_BLOCK_GROUP_DUP;
>> }
>>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough)
2019-10-22 7:01 ` Nikolay Borisov
@ 2019-10-22 12:18 ` Marcos Paulo de Souza
0 siblings, 0 replies; 9+ messages in thread
From: Marcos Paulo de Souza @ 2019-10-22 12:18 UTC (permalink / raw)
To: Nikolay Borisov, Marcos Paulo de Souza, dsterba, linux-btrfs
Cc: Marcos Paulo de Souza
On Tue, 2019-10-22 at 10:01 +0300, Nikolay Borisov wrote:
>
> On 22.10.19 г. 9:59 ч., Nikolay Borisov wrote:
> >
> >
> > On 22.10.19 г. 5:02 ч., Marcos Paulo de Souza wrote:
> >> From: Marcos Paulo de Souza <mpdesouza@suse.com>
> >>
> >> When compiling with clang, this warning is shown:
> >>
> >> common/utils.c:404:3: warning: declaration does not declare
> anything [-Wmissing-declarations]
> >> __attribute__ ((fallthrough));
> >>
> >> This attribute seems to silence the same warning in GCC. Changing
> this
> >> attribute with /* fallthrough */ fixes the warning for both gcc
> and
> >> clang.
> >>
> >> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> >
> > Which clang version are you using? According to
> > https://clang.llvm.org/docs/AttributeReference.html#fallthrough
> this
> > attribute is supported even with the GNU syntax.
>
> Looking at the documentation the gnu syntax is supported in the
> 'current' / 10, unreleased version. All others, up to version 9 does
> not
> support this syntax.
I'm using the default clang in Tumbleweed (20191009):
clang --version
clang version 8.0.1 (tags/RELEASE_801/final 366581)
>
> >
> >> ---
> >> common/utils.c | 12 ++++++------
> >> 1 file changed, 6 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/common/utils.c b/common/utils.c
> >> index 2cf15c33..a88336b3 100644
> >> --- a/common/utils.c
> >> +++ b/common/utils.c
> >> @@ -401,15 +401,15 @@ int pretty_size_snprintf(u64 size, char
> *str, size_t str_size, unsigned unit_mod
> >> case UNITS_TBYTES:
> >> base *= mult;
> >> num_divs++;
> >> - __attribute__ ((fallthrough));
> >> + /* fallthrough */
> >> case UNITS_GBYTES:
> >> base *= mult;
> >> num_divs++;
> >> - __attribute__ ((fallthrough));
> >> + /* fallthrough */
> >> case UNITS_MBYTES:
> >> base *= mult;
> >> num_divs++;
> >> - __attribute__ ((fallthrough));
> >> + /* fallthrough */
> >> case UNITS_KBYTES:
> >> num_divs++;
> >> break;
> >> @@ -1135,14 +1135,14 @@ int test_num_disk_vs_raid(u64
> metadata_profile, u64 data_profile,
> >> default:
> >> case 4:
> >> allowed |= BTRFS_BLOCK_GROUP_RAID10;
> >> - __attribute__ ((fallthrough));
> >> + /* fallthrough */
> >> case 3:
> >> allowed |= BTRFS_BLOCK_GROUP_RAID6;
> >> - __attribute__ ((fallthrough));
> >> + /* fallthrough */
> >> case 2:
> >> allowed |= BTRFS_BLOCK_GROUP_RAID0 |
> BTRFS_BLOCK_GROUP_RAID1 |
> >> BTRFS_BLOCK_GROUP_RAID5;
> >> - __attribute__ ((fallthrough));
> >> + /* fallthrough */
> >> case 1:
> >> allowed |= BTRFS_BLOCK_GROUP_DUP;
> >> }
> >>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default
2019-10-22 2:02 [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default Marcos Paulo de Souza
2019-10-22 2:02 ` [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough) Marcos Paulo de Souza
2019-10-22 2:02 ` [PATCH 2/2] btrfs-progs: Makefile: Add -Wimplicit-fallthrough Marcos Paulo de Souza
@ 2019-10-22 12:41 ` David Sterba
2019-10-22 12:45 ` Nikolay Borisov
3 siblings, 0 replies; 9+ messages in thread
From: David Sterba @ 2019-10-22 12:41 UTC (permalink / raw)
To: Marcos Paulo de Souza; +Cc: dsterba, linux-btrfs, Marcos Paulo de Souza
On Mon, Oct 21, 2019 at 11:02:26PM -0300, Marcos Paulo de Souza wrote:
> From: Marcos Paulo de Souza <mpdesouza@suse.com>
>
> While compiling btrfs-progs using clang I found an issue using
> __attribute__(fallthrough), which does not seems to work in clang.
>
> To solve this issue, the code was changed to use /* fallthrough */, which is the
> same notation adopted by linux kernel.
I'd suggest to follow what kernel does, IIRC there's some whole-tree
cleanup of all the fall through statements with a unified conversion to
the right(tm) annotation.
> Once these places were changed, -Wimplicit-fallthrough was set in Makefile, to
> avoid further implicit-fallthrough cases being added in the future.
That would be good to add by default, but I'm a bit worried about the
differences between compilers and that we'd have to switch the
annotations again once the attribute support lands. Maybe that's not a
big deal.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default
2019-10-22 2:02 [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default Marcos Paulo de Souza
` (2 preceding siblings ...)
2019-10-22 12:41 ` [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default David Sterba
@ 2019-10-22 12:45 ` Nikolay Borisov
2019-10-22 13:10 ` David Sterba
3 siblings, 1 reply; 9+ messages in thread
From: Nikolay Borisov @ 2019-10-22 12:45 UTC (permalink / raw)
To: Marcos Paulo de Souza, dsterba, linux-btrfs; +Cc: Marcos Paulo de Souza
On 22.10.19 г. 5:02 ч., Marcos Paulo de Souza wrote:
> From: Marcos Paulo de Souza <mpdesouza@suse.com>
>
> While compiling btrfs-progs using clang I found an issue using
> __attribute__(fallthrough), which does not seems to work in clang.
>
> To solve this issue, the code was changed to use /* fallthrough */, which is the
> same notation adopted by linux kernel.
>
> Once these places were changed, -Wimplicit-fallthrough was set in Makefile, to
> avoid further implicit-fallthrough cases being added in the future.
>
> Marcos Paulo de Souza (2):
> btrfs-progs: utils: Replace __attribute__(fallthrough)
> btrfs-progs: Makefile: Add -Wimplicit-fallthrough
>
> Makefile | 1 +
> common/utils.c | 12 ++++++------
> 2 files changed, 7 insertions(+), 6 deletions(-)
>
Overall the patch looks good, it just changes the fallthrough to the
least common denominator which seems to be a simple comment. In clang 10
the currently used attribute method is also going to be supported.
But we'll get most value if we just enable it now, so
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default
2019-10-22 12:45 ` Nikolay Borisov
@ 2019-10-22 13:10 ` David Sterba
0 siblings, 0 replies; 9+ messages in thread
From: David Sterba @ 2019-10-22 13:10 UTC (permalink / raw)
To: Nikolay Borisov
Cc: Marcos Paulo de Souza, dsterba, linux-btrfs, Marcos Paulo de Souza
On Tue, Oct 22, 2019 at 03:45:38PM +0300, Nikolay Borisov wrote:
>
>
> On 22.10.19 г. 5:02 ч., Marcos Paulo de Souza wrote:
> > From: Marcos Paulo de Souza <mpdesouza@suse.com>
> >
> > While compiling btrfs-progs using clang I found an issue using
> > __attribute__(fallthrough), which does not seems to work in clang.
> >
> > To solve this issue, the code was changed to use /* fallthrough */, which is the
> > same notation adopted by linux kernel.
> >
> > Once these places were changed, -Wimplicit-fallthrough was set in Makefile, to
> > avoid further implicit-fallthrough cases being added in the future.
> >
> > Marcos Paulo de Souza (2):
> > btrfs-progs: utils: Replace __attribute__(fallthrough)
> > btrfs-progs: Makefile: Add -Wimplicit-fallthrough
> >
> > Makefile | 1 +
> > common/utils.c | 12 ++++++------
> > 2 files changed, 7 insertions(+), 6 deletions(-)
> >
>
> Overall the patch looks good, it just changes the fallthrough to the
> least common denominator which seems to be a simple comment. In clang 10
> the currently used attribute method is also going to be supported.
>
> But we'll get most value if we just enable it now, so
>
> Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Agreed, I've added the note to the first patch. 1-2 in devel. Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-10-22 13:10 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-22 2:02 [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default Marcos Paulo de Souza
2019-10-22 2:02 ` [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough) Marcos Paulo de Souza
2019-10-22 6:59 ` Nikolay Borisov
2019-10-22 7:01 ` Nikolay Borisov
2019-10-22 12:18 ` Marcos Paulo de Souza
2019-10-22 2:02 ` [PATCH 2/2] btrfs-progs: Makefile: Add -Wimplicit-fallthrough Marcos Paulo de Souza
2019-10-22 12:41 ` [PATCH 0/2] btrfs-progs: Setting implicit-fallthrough by default David Sterba
2019-10-22 12:45 ` Nikolay Borisov
2019-10-22 13:10 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.