[PATCH] Add -Wno-cast-truncate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 d92418a..7a2e291 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;
@@ -316,6 +317,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 5f67a12..b542cd6 100644
--- a/lib.h
+++ b/lib.h
@@ -82,6 +82,7 @@ extern int Wcast_to_address_space;
 extern int Wenum_mismatch;
 extern int Wdecl;
 extern int Wone_bit_signed_bitfield;
+extern int Wcast_truncate;
 
 extern void declare_builtin_functions(void);
 extern void create_builtin_stream(void);


-
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

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux