Skip to contentSkip to conversation

Add -Wno-cast-truncate

PATCH RESEND New Josh Triplett 1 participant 1 message Aug 30, 2006 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 3/3 Add -Wno-cast-truncate

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.

---
 expand.c |    4 ++++
 lib.c    |    2 ++
 lib.h    |    1 +
 3 files changed, 7 insertions(+), 0 deletions(-)
expand.c +4 -0
index 474344d..882d80e 100644
@@ -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);
lib.c +2 -0
index 8fac8ae..fb5e54e 100644
@@ -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 },
lib.h +1 -0
index 0b45c67..207a8ec 100644
@@ -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);
Signature · 1 line
1.4.1.1