Skip to contentSkip to conversation

btrfs-progs: Setting implicit-fallthrough by default

PATCH In review Marcos Paulo de Souza 5 participants 9 messages Oct 22, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover btrfs-progs: Setting implicit-fallthrough by default

From: Marcos Paulo de Souza <[email protected]>

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(-)
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/2 btrfs-progs: utils: Replace __attribute__(fallthrough)

From: Marcos Paulo de Souza <[email protected]>

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.

---
 common/utils.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
common/utils.c +6 -6
index 2cf15c33..a88336b3 100644
@@ -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;
 	}
Signature · 1 line
2.23.0
#2 lore raw

Re: [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough)

Quoted 4 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

When compiling with clang, this warning is shown:

Quoted 8 lines

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.

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.

Quoted 46 lines
---
 common/utils.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
common/utils.c +6 -6
index 2cf15c33..a88336b3 100644
@@ -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;
 	}
#3 lore raw

Re: [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough)

Quoted 14 lines · Nikolay Borisov
Quoted 11 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

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.

Quoted 5 lines
Quoted 1 line

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.

Quoted 47 lines
Quoted 47 lines
---
 common/utils.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
common/utils.c +6 -6
index 2cf15c33..a88336b3 100644
@@ -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;
 	}
#4 lore raw

Re: [PATCH 1/2] btrfs-progs: utils: Replace __attribute__(fallthrough)

Quoted 23 lines · Nikolay Borisov
Quoted 8 lines · Nikolay Borisov
Quoted 5 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

When compiling with clang, this warning is shown:

common/utils.c:404:3: warning: declaration does not declare

anything [-Wmissing-declarations]

Quoted 3 lines
Quoted 3 lines
                __attribute__ ((fallthrough));

This attribute seems to silence the same warning in GCC. Changing

this

Quoted 1 line
Quoted 1 line

attribute with /* fallthrough */ fixes the warning for both gcc

and

Quoted 6 lines
Quoted 3 lines

clang.

Which clang version are you using? According to
https://clang.llvm.org/docs/AttributeReference.html#fallthrough

Quoted 7 lines

this

Quoted 1 line

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)

Quoted 51 lines
Quoted 11 lines

common/utils.c int pretty_size_snprintf(u64 size, char

Quoted 11 lines

---
 common/utils.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
common/utils.c +0 -0
index 2cf15c33..a88336b3 100644
@@ -401,15 +401,15 @@ int pretty_size_snprintf(u64 size, char

*str, size_t str_size, unsigned unit_mod

Quoted 11 lines
Quoted 11 lines
common/utils.c +2 -2
 	case UNITS_TBYTES:
 		base *= mult;
 		num_divs++;
-		__attribute__ ((fallthrough));
+		/* fallthrough */
 	case UNITS_GBYTES:
 		base *= mult;
 		num_divs++;
-		__attribute__ ((fallthrough));
+		/* fallthrough */
 	case UNITS_MBYTES:
Quoted 8 lines

common/utils.c int test_num_disk_vs_raid(u64

Quoted 8 lines
common/utils.c +1 -1
 		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,

Quoted 11 lines

common/utils.c int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,

Quoted 11 lines
common/utils.c +2 -2
 	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 |

Quoted 7 lines
Quoted 7 lines
common/utils.c +1 -1
 			BTRFS_BLOCK_GROUP_RAID5;
-		__attribute__ ((fallthrough));
+		/* fallthrough */
 	case 1:
 		allowed |= BTRFS_BLOCK_GROUP_DUP;
 	}
#5 lore raw

PATCH 2/2 btrfs-progs: Makefile: Add -Wimplicit-fallthrough

In reply to Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

Avoid introducing new cases of implicit fallthrough by having this flag always set.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 21bf2717..2f04e880 100644
@@ -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) \
Signature · 1 line
2.23.0
#6 lore raw
In reply to Marcos Paulo de Souza
Quoted 7 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

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.

Quoted 2 lines

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.

Reviewed-by on the v1 series
#7 lore raw
In reply to Marcos Paulo de Souza
Quoted 11 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

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.

Quoted 8 lines

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

#8 lore raw
Quoted 23 lines · Nikolay Borisov
Quoted 11 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

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.

Quoted 8 lines

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(-)
Quoted 7 lines

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

Agreed, I've added the note to the first patch. 1-2 in devel. Thanks.