Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable -Wimplicit-fallthrough warning for Modules/expat #125506

Open
sobolevn opened this issue Oct 15, 2024 · 5 comments
Open

Disable -Wimplicit-fallthrough warning for Modules/expat #125506

sobolevn opened this issue Oct 15, 2024 · 5 comments
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Oct 15, 2024

Bug report

Right now compilers produce a lot of warnings for vendored modules:

But, there's not much we can do about them, since they are vendored. For example, siphash has explicit fall-through comments:

case 7:
b |= (uint64_t)H->buf[6] << 48;
/* fall through */
case 6:
b |= (uint64_t)H->buf[5] << 40;
/* fall through */
case 5:
b |= (uint64_t)H->buf[4] << 32;
/* fall through */

But, it is still reported:

 In file included from ./Modules/expat/xmlparse.c:121:
./Modules/expat/siphash.h:238:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  case 6:
  ^
./Modules/expat/siphash.h:238:3: note: insert '__attribute__((fallthrough));' to silence this warning
  case 6:
  ^
  __attribute__((fallthrough)); 
./Modules/expat/siphash.h:238:3: note: insert 'break;' to avoid fall-through
  case 6:
  ^
  break; 
./Modules/expat/siphash.h:241:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  case 5:
  ^
./Modules/expat/siphash.h:241:3: note: insert '__attribute__((fallthrough));' to silence this warning
  case 5:
  ^
  __attribute__((fallthrough)); 
./Modules/expat/siphash.h:241:3: note: insert 'break;' to avoid fall-through
  case 5:
  ^
  break; 
./Modules/expat/siphash.h:244:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  case 4:
  ^
./Modules/expat/siphash.h:244:3: note: insert '__attribute__((fallthrough));' to silence this warning
  case 4:
  ^
  __attribute__((fallthrough)); 
./Modules/expat/siphash.h:244:3: note: insert 'break;' to avoid fall-through
  case 4:
  ^
  break; 
./Modules/expat/siphash.h:247:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  case 3:
  ^
./Modules/expat/siphash.h:247:3: note: insert '__attribute__((fallthrough));' to silence this warning
  case 3:
  ^
  __attribute__((fallthrough)); 
./Modules/expat/siphash.h:247:3: note: insert 'break;' to avoid fall-through
  case 3:
  ^
  break; 
./Modules/expat/siphash.h:250:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  case 2:
  ^
./Modules/expat/siphash.h:250:3: note: insert '__attribute__((fallthrough));' to silence this warning
  case 2:
  ^
  __attribute__((fallthrough)); 
./Modules/expat/siphash.h:250:3: note: insert 'break;' to avoid fall-through
  case 2:
  ^
  break; 
./Modules/expat/siphash.h:253:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  case 1:
  ^
./Modules/expat/siphash.h:253:3: note: insert '__attribute__((fallthrough));' to silence this warning
  case 1:
  ^
  __attribute__((fallthrough)); 
./Modules/expat/siphash.h:253:3: note: insert 'break;' to avoid fall-through
  case 1:
  ^
  break; 
./Modules/expat/siphash.h:256:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  case 0:
  ^
./Modules/expat/siphash.h:256:3: note: insert 'break;' to avoid fall-through
  case 0:
  ^
  break; 
./Modules/expat/xmlparse.c:1944:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  default:
  ^
./Modules/expat/xmlparse.c:1944:3: note: insert '__attribute__((fallthrough));' to silence this warning
  default:
  ^
  __attribute__((fallthrough)); 
./Modules/expat/xmlparse.c:1944:3: note: insert 'break;' to avoid fall-through
  default:
  ^
  break; 
./Modules/expat/xmlparse.c:2067:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  default:
  ^
./Modules/expat/xmlparse.c:2067:3: note: insert '__attribute__((fallthrough));' to silence this warning
  default:
  ^
  __attribute__((fallthrough)); 
./Modules/expat/xmlparse.c:2067:3: note: insert 'break;' to avoid fall-through
  default:
  ^
  break; 
./Modules/expat/xmlparse.c:2096:5: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
    default:; /* should not happen */
    ^
./Modules/expat/xmlparse.c:2096:5: note: insert '__attribute__((fallthrough));' to silence this warning
    default:; /* should not happen */
    ^
    __attribute__((fallthrough)); 
./Modules/expat/xmlparse.c:2096:5: note: insert 'break;' to avoid fall-through
    default:; /* should not happen */
    ^
    break; 
./Modules/expat/xmlparse.c:2292:5: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
    default:;
    ^
./Modules/expat/xmlparse.c:2292:5: note: insert '__attribute__((fallthrough));' to silence this warning
    default:;
    ^
    __attribute__((fallthrough)); 
./Modules/expat/xmlparse.c:2292:5: note: insert 'break;' to avoid fall-through
    default:;
    ^
    break; 
./Modules/expat/xmlparse.c:4864:5: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
    case XML_ROLE_ENTITY_PUBLIC_ID:
    ^
./Modules/expat/xmlparse.c:4864:5: note: insert '__attribute__((fallthrough));' to silence this warning
    case XML_ROLE_ENTITY_PUBLIC_ID:
    ^
    __attribute__((fallthrough)); 
./Modules/expat/xmlparse.c:4864:5: note: insert 'break;' to avoid fall-through
    case XML_ROLE_ENTITY_PUBLIC_ID:
    ^
    break; 
./Modules/expat/xmlparse.c:5192:5: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
    case XML_ROLE_ENTITY_SYSTEM_ID:
    ^
./Modules/expat/xmlparse.c:5192:5: note: insert '__attribute__((fallthrough));' to silence this warning
    case XML_ROLE_ENTITY_SYSTEM_ID:
    ^
    __attribute__((fallthrough)); 
./Modules/expat/xmlparse.c:5192:5: note: insert 'break;' to avoid fall-through
    case XML_ROLE_ENTITY_SYSTEM_ID:
    ^
    break; 
./Modules/expat/xmlparse.c:6050:5: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
    case XML_TOK_ATTRIBUTE_VALUE_S:
    ^
./Modules/expat/xmlparse.c:6050:5: note: insert '__attribute__((fallthrough));' to silence this warning
    case XML_TOK_ATTRIBUTE_VALUE_S:
    ^
    __attribute__((fallthrough)); 
./Modules/expat/xmlparse.c:6050:5: note: insert 'break;' to avoid fall-through
    case XML_TOK_ATTRIBUTE_VALUE_S:
    ^
    break; 
./Modules/expat/xmlparse.c:6303:5: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
    case XML_TOK_DATA_NEWLINE:
    ^
./Modules/expat/xmlparse.c:6303:5: note: insert '__attribute__((fallthrough));' to silence this warning
    case XML_TOK_DATA_NEWLINE:
    ^
    __attribute__((fallthrough)); 
./Modules/expat/xmlparse.c:6303:5: note: insert 'break;' to avoid fall-through
    case XML_TOK_DATA_NEWLINE:
    ^
    break; 

My opinion is that we only should show actionable warnings, that we can actually fix.

CC @hugovk

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error extension-modules C modules in the Modules dir labels Oct 15, 2024
@hugovk
Copy link
Member

hugovk commented Oct 15, 2024

cc @nohlson @sethmlarson

@rruuaanng
Copy link
Contributor

rruuaanng commented Oct 15, 2024

In fact, We can add -Wno-implicit-fallthrough to suppress it, Because this warning only means that the case statement has no break.
(Although this will result in no warning being triggered if the user writes a statement without a break).

@sobolevn
Copy link
Member Author

sobolevn commented Oct 15, 2024

@rruuaanng

We can add -Wno-implicit-fallthrough to suppress it

I think that we should not add anything here, because we are working with a vendored module that cannot be modified (without a very strong reason to).

Although this will result in no warning being triggered if the user writes a statement without a break

Again, developers should not touch vendored libs without a very strong reason. Fixing such a warning is not good enough reason to do so.

@sethmlarson
Copy link
Contributor

I'm in agreement that we shouldn't be warning on code we don't control. Our current setup for warning tooling applies the warning to all code covered by CFLAGS_NODIST, so even if the warnings don't cause CI to fail they still show up in logs. I don't know if there's an easy way to ignore whole directories that we vendor at the configure level to not apply warnings to those files?

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Oct 15, 2024

I don't know if there's an easy way to ignore whole directories that we vendor at the configure level to not apply warnings to those files?

We don't have such functionality in configure.ac, but you should be fine with adding -Wno-implicit-fallthrough after -Wimplicit-fallthrough. I don't remember from the top of my head if LIBEXPAT_CFLAGS are added before or after CFLAGS_NODIST, but if LIBEXPAT_CFLAGS are added post CFLAGS_NODIST, getting rid of those warnings for libexpat should be pretty trivial1.

PoC hack
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 07c8a4d2014..fa9faad0c9b 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1351,7 +1351,7 @@ $(LIBMPDEC_A): $(LIBMPDEC_OBJS)
 
 ##########################################################################
 # Build static libexpat.a
-LIBEXPAT_CFLAGS=@LIBEXPAT_CFLAGS@ $(PY_STDMODULE_CFLAGS) $(CCSHARED)
+LIBEXPAT_CFLAGS=@LIBEXPAT_CFLAGS@ $(PY_STDMODULE_CFLAGS) -Wno-implicit-fallthrough $(CCSHARED)
 
 Modules/expat/xmlparse.o: $(srcdir)/Modules/expat/xmlparse.c $(LIBEXPAT_HEADERS) $(PYTHON_HEADERS)
        $(CC) -c $(LIBEXPAT_CFLAGS) -o $@ $(srcdir)/Modules/expat/xmlparse.c

Footnotes

  1. a trivial, but dirty, hack in Makefile.pre.in, that is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants