@@ -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;
new file mode 100644
@@ -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
+ */
new file mode 100644
@@ -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
+ */
@@ -6,6 +6,6 @@ void foo(void)
}
/*
- * check-name: fsigned-char
+ * check-name: funsigned-char
* check-command: sparse -funsigned-char -Wno-decl $file
*/
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> --- lib.c | 2 +- machine.h | 6 ------ target.c | 18 ++++++++++++++++++ validation/char-signed-native.c | 9 +++++++++ validation/char-unsigned-native.c | 11 +++++++++++ validation/char-unsigned.c | 2 +- 6 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 validation/char-signed-native.c create mode 100644 validation/char-unsigned-native.c