Add the ability to turn off checks for casts that truncate constant values using -Wno-cast-truncate, helpful when attempting to track down a particular class of warnings only without losing them amongst others. Checks for truncating casts default to on, so this does not change the default behavior of sparse. Signed-off-by: Josh Triplett <josh@xxxxxxxxxxxxxxx> --- expand.c | 4 ++++ lib.c | 2 ++ lib.h | 1 + 3 files changed, 7 insertions(+), 0 deletions(-) diff --git a/expand.c b/expand.c index 474344d..882d80e 100644 --- a/expand.c +++ b/expand.c @@ -94,6 +94,10 @@ Int: mask = signmask | (signmask-1); expr->value = value & mask; + // Stop here unless checking for truncation + if (!Wcast_truncate) + return; + // Check if we dropped any bits.. oldsignmask = 1ULL << (old_size-1); oldmask = oldsignmask | (oldsignmask-1); diff --git a/lib.c b/lib.c index 8fac8ae..fb5e54e 100644 --- a/lib.c +++ b/lib.c @@ -169,6 +169,7 @@ static char pre_buffer[8192]; int Wdefault_bitfield_sign = 0; int Wone_bit_signed_bitfield = 1; +int Wcast_truncate = 1; int Wbitwise = 0; int Wtypesign = 0; int Wcontext = 0; @@ -317,6 +318,7 @@ static const struct warning { { "cast-to-as", &Wcast_to_address_space }, { "decl", &Wdecl }, { "one-bit-signed-bitfield", &Wone_bit_signed_bitfield }, + { "cast-truncate", &Wcast_truncate }, { "ptr-subtraction-blows", &Wptr_subtraction_blows }, { "default-bitfield-sign", &Wdefault_bitfield_sign }, { "undef", &Wundefined_preprocessor }, diff --git a/lib.h b/lib.h index 0b45c67..207a8ec 100644 --- a/lib.h +++ b/lib.h @@ -83,6 +83,7 @@ extern int Wenum_mismatch; extern int Wdecl; extern int Wone_bit_signed_bitfield; extern int Wshadow; +extern int Wcast_truncate; extern void declare_builtin_functions(void); extern void create_builtin_stream(void); -- 1.4.1.1 - To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html