aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-11-26 23:59:30 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-11-26 23:59:30 +0100
commit50438f45934d885aa00b126dd9359895e05fd056 (patch)
treef8cc5177c314fa48c551ec2c02093dabd153a7d4
parent467d8d026c8b0a7eee93f31559cccf9157588d12 (diff)
parent16a575e1758b49e0e0f6db6c26c6fbd44c2db98e (diff)
downloadsparse-50438f45934d885aa00b126dd9359895e05fd056.tar.gz
Merge branch 'arch-cygwin' into master
-rwxr-xr-xcgcc1
-rw-r--r--lib.c4
-rw-r--r--lib.h1
-rw-r--r--machine.h6
-rw-r--r--target.c49
-rw-r--r--validation/arch/short-wchar.c6
-rw-r--r--validation/char-signed-native.c9
-rw-r--r--validation/char-unsigned-native.c11
-rw-r--r--validation/char-unsigned.c2
9 files changed, 66 insertions, 23 deletions
diff --git a/cgcc b/cgcc
index 201fbc9a..239f713d 100755
--- a/cgcc
+++ b/cgcc
@@ -252,6 +252,7 @@ sub add_specs {
return ' -Dunix=1 -D__unix=1 -D__unix__=1';
} elsif ( $spec =~ /^cygwin/) {
return &add_specs ('unix') .
+ ' -fshort-wchar' .
' -D__CYGWIN__=1 -D__CYGWIN32__=1' .
" -D'_cdecl=__attribute__((__cdecl__))'" .
" -D'__cdecl=__attribute__((__cdecl__))'" .
diff --git a/lib.c b/lib.c
index 332eebeb..47dd7029 100644
--- a/lib.c
+++ b/lib.c
@@ -313,7 +313,8 @@ unsigned long long fmemcpy_max_count = 100000;
unsigned long fpasses = ~0UL;
int fpic = 0;
int fpie = 0;
-int funsigned_char = UNSIGNED_CHAR;
+int fshort_wchar = 0;
+int funsigned_char = -1;
int preprocess_only;
@@ -995,6 +996,7 @@ static struct flag fflags[] = {
{ "pie", &fpie, handle_switch_setval, 1 },
{ "PIE", &fpie, handle_switch_setval, 2 },
{ "signed-char", &funsigned_char, NULL, OPT_INVERSE },
+ { "short-wchar", &fshort_wchar },
{ "unsigned-char", &funsigned_char, NULL, },
{ },
};
diff --git a/lib.h b/lib.h
index 00c60812..3d596a52 100644
--- a/lib.h
+++ b/lib.h
@@ -202,6 +202,7 @@ extern unsigned long long fmemcpy_max_count;
extern unsigned long fpasses;
extern int fpic;
extern int fpie;
+extern int fshort_wchar;
extern int funsigned_char;
extern int arch_m64;
diff --git a/machine.h b/machine.h
index e24822a7..22b05d91 100644
--- a/machine.h
+++ b/machine.h
@@ -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
diff --git a/target.c b/target.c
index 90097818..7aaad1c4 100644
--- a/target.c
+++ b/target.c
@@ -79,11 +79,21 @@ void init_target(void)
}
switch (arch_mach) {
- case MACH_X86_64:
- if (arch_m64 == ARCH_LP64)
- break;
- /* fall through */
case MACH_I386:
+ wchar_ctype = &long_ctype;
+ /* fall through */
+ case MACH_X86_64:
+#if defined(__APPLE__)
+ int64_ctype = &llong_ctype;
+ uint64_ctype = &ullong_ctype;
+#endif
+#if defined(__FreeBSD__) || defined(__APPLE__)
+ wint_ctype = &int_ctype;
+#endif
+#if defined(__CYGWIN__)
+ wchar_ctype = &ushort_ctype;
+#endif
+ break;
case MACH_M68K:
case MACH_SPARC32:
case MACH_PPC32:
@@ -96,6 +106,8 @@ void init_target(void)
default:
break;
}
+ if (fshort_wchar)
+ wchar_ctype = &ushort_ctype;
switch (arch_mach) {
case MACH_MIPS64:
@@ -137,6 +149,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;
@@ -171,15 +201,4 @@ void init_target(void)
pointer_alignment = 8;
break;
}
-
-#if defined(__CYGWIN__)
- wchar_ctype = &ushort_ctype;
-#endif
-#if defined(__FreeBSD__) || defined(__APPLE__)
- wint_ctype = &int_ctype;
-#endif
-#if defined(__APPLE__)
- int64_ctype = &llong_ctype;
- uint64_ctype = &ullong_ctype;
-#endif
}
diff --git a/validation/arch/short-wchar.c b/validation/arch/short-wchar.c
new file mode 100644
index 00000000..de05313c
--- /dev/null
+++ b/validation/arch/short-wchar.c
@@ -0,0 +1,6 @@
+_Static_assert([__WCHAR_TYPE__] == [unsigned short], "short wchar");
+
+/*
+ * check-name: short-wchar
+ * check-command: sparse -fshort-wchar $file
+ */
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
*/