Page MenuHomeFreeBSD

Don't fail the build due to clang integer constant range warnings
AbandonedPublic

Authored by arichardson on Nov 2 2017, 3:10 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 8 2024, 11:11 AM
Unknown Object (File)
Dec 20 2023, 3:07 AM
Unknown Object (File)
Dec 11 2023, 3:59 AM
Unknown Object (File)
Sep 4 2023, 10:38 PM
Unknown Object (File)
Sep 4 2023, 10:37 PM
Unknown Object (File)
Sep 4 2023, 10:37 PM
Unknown Object (File)
Sep 4 2023, 10:36 PM
Unknown Object (File)
Aug 30 2023, 10:29 AM
Subscribers

Details

Summary

This warning checks whether a constant is out of range of the integer
type. An example is comparison of 'u_int' > 4294967295 is always false
and in this case the warning makes sense.
However, when the type is a typedef that can be either 64 or 32 bits the
if condition is only tautological in some configurations so this should
not be a warning that fails the build.

Test Plan

Build no longer fails due to -Werror

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Adding dim@ who normally manages updates to llvm in the base. Dimitry, Alex is building CheriBSD with a top-of-tree-ish clang. I'm not sure if you are currently building FreeBSD with clang 6 and have hit the same build failures already? Does disabling errors for this warning seem sensible to you?

How many warnings of this type does the build produce?

I think there were about 5-8 warnings in 4 directories. https://github.com/CTSRD-CHERI/cheribsd/commit/8bd5978bcdd4d66fbc65a24a743fa571d6e40c97 is the workaround I used for CheriBSD.

I wouldn't put it in this place, but a little higher, where the different WARNS levels are handled. For example, you might want to suppress these for WARNS <= 3. E.g., in the block:

.if ${WARNS} <= 3
CWARNFLAGS.clang+=      -Wno-tautological-compare -Wno-unused-value\
                -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion
.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600
CWARNFLAGS.clang+=      -Wno-unused-local-typedef
.endif
.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 40000
CWARNFLAGS.clang+=      -Wno-address-of-packed-member
.endif
.endif # WARNS <= 3

add a new stanza for 60000 and higher.

moved block to the right location

This revision is now accepted and ready to land.Nov 29 2017, 11:43 AM
share/mk/bsd.sys.mk
85 ↗(On Diff #35948)

I just noticed this is slightly different. For consistency should I also use CWARNFLAGS.clang here?

(And you can mark approved by me now)

share/mk/bsd.sys.mk
85 ↗(On Diff #35948)

Yes.

This revision was automatically updated to reflect the committed changes.

I just realized that after moving the line further up the build fails again for me. I forgot to do a clean build after making the change...

The problem is that the .if defined(WFORMAT) block further down adds another -Werror to the command line which overrides the -Wno-error that I added. Any objections to moving that block further up? I though about moving it just below the other block that sets -Werror (line 37)

Isn't this OBE at this point?

I believe this should probably be reverted now since the warning has been changed to off-by-default because lots of other projects also had issues with it.

Yeah, upstream also dropped it from the default -Wextra flags, due to too many false positives, here: https://reviews.llvm.org/rL322901. This got merged to the 6.0 branch in https://reviews.llvm.org/rL322931, which came into our tree with rS328381. I think this should be no longer necessary.