Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] teach sparse about __STDC_HOSTED__
@ 2020-06-22 23:12 Luc Van Oostenryck
  0 siblings, 0 replies; only message in thread
From: Luc Van Oostenryck @ 2020-06-22 23:12 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

It seems that some system libraries expect __STDC_HOSTED__ to
be always defined.

So, teach sparse the options flags -f[no-]{hosted,freestanding}
and define __STDC_HOSTED__ accordingly.
---
 lib.c                                  |  4 ++++
 lib.h                                  |  1 +
 validation/preprocessor/freestanding.c | 11 +++++++++++
 validation/preprocessor/hosted.c       | 11 +++++++++++
 4 files changed, 27 insertions(+)
 create mode 100644 validation/preprocessor/freestanding.c
 create mode 100644 validation/preprocessor/hosted.c

diff --git a/lib.c b/lib.c
index 88bb31093deb..e56788260cb7 100644
--- a/lib.c
+++ b/lib.c
@@ -311,6 +311,7 @@ int dbg_ir = 0;
 int dbg_postorder = 0;
 
 unsigned long fdump_ir;
+int fhosted = 1;
 int fmem_report = 0;
 unsigned long long fmemcpy_max_count = 100000;
 unsigned long fpasses = ~0UL;
@@ -994,6 +995,8 @@ static int handle_fmax_warnings(const char *arg, const char *opt, const struct f
 static struct flag fflags[] = {
 	{ "diagnostic-prefix",	NULL,	handle_fdiagnostic_prefix },
 	{ "dump-ir",		NULL,	handle_fdump_ir },
+	{ "freestanding",	&fhosted, NULL, OPT_INVERSE },
+	{ "hosted",		&fhosted },
 	{ "linearize",		NULL,	handle_fpasses,	PASS_LINEARIZE },
 	{ "max-warnings=",	NULL,	handle_fmax_warnings },
 	{ "mem-report",		&fmem_report },
@@ -1300,6 +1303,7 @@ static void predefined_macros(void)
 	predefine("__GNUC_PATCHLEVEL__", 1, "%d", gcc_patchlevel);
 
 	predefine("__STDC__", 1, "1");
+	predefine("__STDC_HOSTED__", 0, fhosted ? "1" : "0");
 	switch (standard) {
 	default:
 		break;
diff --git a/lib.h b/lib.h
index e767840c1038..4f67958efdb9 100644
--- a/lib.h
+++ b/lib.h
@@ -202,6 +202,7 @@ extern int dbg_postorder;
 extern unsigned int fmax_warnings;
 extern int fmem_report;
 extern unsigned long fdump_ir;
+extern int fhosted;
 extern unsigned long long fmemcpy_max_count;
 extern unsigned long fpasses;
 extern int fpic;
diff --git a/validation/preprocessor/freestanding.c b/validation/preprocessor/freestanding.c
new file mode 100644
index 000000000000..7ee35354f711
--- /dev/null
+++ b/validation/preprocessor/freestanding.c
@@ -0,0 +1,11 @@
+__STDC_HOSTED__
+
+/*
+ * check-name: freestanding
+ * check-command: sparse -E -ffreestanding $file
+ *
+ * check-output-start
+
+0
+ * check-output-end
+ */
diff --git a/validation/preprocessor/hosted.c b/validation/preprocessor/hosted.c
new file mode 100644
index 000000000000..e6b3d3c1d6b7
--- /dev/null
+++ b/validation/preprocessor/hosted.c
@@ -0,0 +1,11 @@
+__STDC_HOSTED__
+
+/*
+ * check-name: hosted
+ * check-command: sparse -E -fhosted $file
+ *
+ * check-output-start
+
+1
+ * check-output-end
+ */
-- 
2.27.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22 23:12 [PATCH] teach sparse about __STDC_HOSTED__ Luc Van Oostenryck

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git