diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-10 11:45:16 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-14 01:03:41 +0100 |
| commit | ebe086222f89521de5390bc204ed31976f4b97f4 (patch) | |
| tree | aac32f8f002e36a65bd943c6e087b7aa02512291 | |
| parent | fd3528aa0409874386610ce63bb647fff8312fd9 (diff) | |
| download | sparse-dev-ebe086222f89521de5390bc204ed31976f4b97f4.tar.gz | |
arch: fix the signedness of plain chars
Some architectures, like ARM or PPC, use 'unsigned' for
plain chars while others, like the Intel's, use signed ones.
Sparse understands -funsigned-char but by default uses the
native signedness.
Fix this by setting the proper signedness of plain chars
for the archs that Sparse know about.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | lib.c | 2 | ||||
| -rw-r--r-- | machine.h | 6 | ||||
| -rw-r--r-- | target.c | 18 | ||||
| -rw-r--r-- | validation/char-signed-native.c | 9 | ||||
| -rw-r--r-- | validation/char-unsigned-native.c | 11 | ||||
| -rw-r--r-- | validation/char-unsigned.c | 2 |
6 files changed, 40 insertions, 8 deletions
@@ -313,7 +313,7 @@ unsigned long long fmemcpy_max_count = 100000; unsigned long fpasses = ~0UL; int fpic = 0; int fpie = 0; -int funsigned_char = UNSIGNED_CHAR; +int funsigned_char = -1; int preprocess_only; @@ -70,10 +70,4 @@ enum machine { #define MACH_NATIVE MACH_UNKNOWN #endif -#if defined(__CHAR_UNSIGNED__) -#define UNSIGNED_CHAR 1 -#else -#define UNSIGNED_CHAR 0 -#endif - #endif @@ -137,6 +137,24 @@ void init_target(void) break; } + switch (arch_mach) { + case MACH_ARM: + case MACH_ARM64: + case MACH_PPC32: + case MACH_PPC64: + case MACH_RISCV32: + case MACH_RISCV64: + case MACH_S390: + case MACH_S390X: + if (funsigned_char == -1) + funsigned_char = 1; + break; + default: + if (funsigned_char == -1) + funsigned_char = 0; + break; + } + switch (arch_m64) { case ARCH_X32: max_int_alignment = 8; diff --git a/validation/char-signed-native.c b/validation/char-signed-native.c new file mode 100644 index 00000000..5185fce9 --- /dev/null +++ b/validation/char-signed-native.c @@ -0,0 +1,9 @@ +void foo(void) +{ + _Static_assert((char) -1 == -1, "plain char is not signed"); +} + +/* + * check-name: char-signed-native + * check-command: sparse --arch=i386 -Wno-decl $file + */ diff --git a/validation/char-unsigned-native.c b/validation/char-unsigned-native.c new file mode 100644 index 00000000..b8645842 --- /dev/null +++ b/validation/char-unsigned-native.c @@ -0,0 +1,11 @@ +#define MASK ((1 << __CHAR_BIT__) - 1) + +void foo(void) +{ + _Static_assert((char) -1 == (-1 & MASK), "plain char is not unsigned"); +} + +/* + * check-name: char-unsigned-native + * check-command: sparse --arch=arm -Wno-decl $file + */ diff --git a/validation/char-unsigned.c b/validation/char-unsigned.c index 19cadbda..354aa40d 100644 --- a/validation/char-unsigned.c +++ b/validation/char-unsigned.c @@ -6,6 +6,6 @@ void foo(void) } /* - * check-name: fsigned-char + * check-name: funsigned-char * check-command: sparse -funsigned-char -Wno-decl $file */ |
