diff mbox series

[2/3] arch: teach sparse about -fshort-wchar

Message ID 20191115012515.53725-3-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series make wchar_t be correct on Cygwin via cgcc | expand

Commit Message

Luc Van Oostenryck Nov. 15, 2019, 1:25 a.m. UTC
This is useful in cgcc for supporting Cygwin which doesn't
use a 32-bit type for wchar_t.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c                         | 2 ++
 lib.h                         | 1 +
 target.c                      | 2 ++
 validation/arch/short-wchar.c | 6 ++++++
 4 files changed, 11 insertions(+)
 create mode 100644 validation/arch/short-wchar.c
diff mbox series

Patch

diff --git a/lib.c b/lib.c
index 350d881a9..47dd7029d 100644
--- a/lib.c
+++ b/lib.c
@@ -313,6 +313,7 @@  unsigned long long fmemcpy_max_count = 100000;
 unsigned long fpasses = ~0UL;
 int fpic = 0;
 int fpie = 0;
+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 00c608125..3d596a529 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/target.c b/target.c
index 9ce21272d..7aaad1c40 100644
--- a/target.c
+++ b/target.c
@@ -106,6 +106,8 @@  void init_target(void)
 	default:
 		break;
 	}
+	if (fshort_wchar)
+		wchar_ctype = &ushort_ctype;
 
 	switch (arch_mach) {
 	case MACH_MIPS64:
diff --git a/validation/arch/short-wchar.c b/validation/arch/short-wchar.c
new file mode 100644
index 000000000..de05313c6
--- /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
+ */