Skip to contentSkip to conversation

x86: sparse errors from string_32.h

PATCH Applied Harvey Harrison 3 participants 5 messages Feb 1, 2008 – Feb 2, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: sparse errors from string_32.h

include/asm/string_32.h:216:26: warning: cast truncates bits from constant value (cccccccc becomes cc) include/asm/string_32.h:219:27: warning: cast truncates bits from constant value (cccccccc becomes cccc) include/asm/string_32.h:222:27: warning: cast truncates bits from constant value (cccccccc becomes cccc) include/asm/string_32.h:223:30: warning: cast truncates bits from constant value (cccccccc becomes cc)

---
Ingo, this shows up over and over again during the build, this doesn't change anything as they are known compile-time constants at this point, the and-ing just makes the truncation explicit.

If you disagree with this method, no worries.

 include/asm-x86/string_32.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
include/asm-x86/string_32.h +4 -4
index 55bfa30..c5d13a8 100644
@@ -213,14 +213,14 @@ static __always_inline void * __constant_c_and_count_memset(void * s, unsigned l
 		case 0:
 			return s;
 		case 1:
-			*(unsigned char *)s = pattern;
+			*(unsigned char *)s = pattern & 0xff;
 			return s;
 		case 2:
-			*(unsigned short *)s = pattern;
+			*(unsigned short *)s = pattern & 0xffff;
 			return s;
 		case 3:
-			*(unsigned short *)s = pattern;
-			*(2+(unsigned char *)s) = pattern;
+			*(unsigned short *)s = pattern & 0xffff;
+			*(2+(unsigned char *)s) = pattern & 0xff;
 			return s;
 		case 4:
 			*(unsigned long *)s = pattern;
Signature · 1 line
1.5.4.rc4.1142.gf5a97
Applied
#1 lore raw

include/asm-x86/string_32.h static __always_inline void * __constant_c_and_count_memset(void * s, unsigned l · line 216

Quoted 3 lines · Harvey Harrison
include/asm-x86/string_32.h +1 -1
 		case 1:
-			*(unsigned char *)s = pattern;
+			*(unsigned char *)s = pattern & 0xff;

i've applied your fix - but wouldnt it be cleaner to just cast the pattern variable to unsigned char instead?

Ingo

#2 lore raw
Quoted 8 lines · Ingo Molnar

include/asm-x86/string_32.h static __always_inline void * __constant_c_and_count_memset(void * s, unsigned l · line 216

Quoted 3 lines · Harvey Harrison
include/asm-x86/string_32.h +1 -1
 		case 1:
-			*(unsigned char *)s = pattern;
+			*(unsigned char *)s = pattern & 0xff;

i've applied your fix - but wouldnt it be cleaner to just cast the pattern variable to unsigned char instead?

I'm not sure, I went with this solution because of the explicit length being tested in the case statements. The compiler can see it's all constant at this point anyway...if you want a cast-patch instead, just ask.

Harvey

#3 lore raw
In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar

include/asm-x86/string_32.h static __always_inline void * __constant_c_and_count_memset(void * s, unsigned l · line 216

Quoted 3 lines · Harvey Harrison
include/asm-x86/string_32.h +1 -1
 		case 1:
-			*(unsigned char *)s = pattern;
+			*(unsigned char *)s = pattern & 0xff;

i've applied your fix - but wouldnt it be cleaner to just cast the pattern variable to unsigned char instead?

Even better, since we're talking about fixed bytes, I suggest writing it as:

	*(u8 *)s = (u8)pattern;

Much more compact and the intent is a little bit more obvious.

-hpa

#4 lore raw
Quoted 11 lines · H. Peter Anvin
Quoted 9 lines · Ingo Molnar

include/asm-x86/string_32.h static __always_inline void * __constant_c_and_count_memset(void * s, unsigned l · line 216

Quoted 3 lines · Harvey Harrison
include/asm-x86/string_32.h +1 -1
 		case 1:
-			*(unsigned char *)s = pattern;
+			*(unsigned char *)s = pattern & 0xff;

i've applied your fix - but wouldnt it be cleaner to just cast the pattern variable to unsigned char instead?

Quoted 6 lines

Even better, since we're talking about fixed bytes, I suggest writing it as:

	*(u8 *)s = (u8)pattern;

Much more compact and the intent is a little bit more obvious.

While I agree that is cleaner, that will still produce sparse warnings about a cast truncating bits from a constant value. I think that explicit & is necessary (unless the cure is worse than the disease).

Harvey