[PATCH 3/8] add predefine_nostd()

[email protected]
Newsgroups org.kernel.vger.smatch
Message-ID <[email protected]>
From: Luc Van Oostenryck <[email protected]>

GCC adds predefines for some symbols lying in the user's namespace,
like "linux" or "sparc", but only if the selected dialect is not one
of the standard ones.

Add an helper, predefine_nostd(), for these.

Signed-off-by: Luc Van Oostenryck <[email protected]>
Signed-off-by: John Levon <[email protected]>
---
 lib.h         | 1 +
 pre-process.c | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/lib.h b/lib.h
index 44e2b5c5..70b2ba39 100644
--- a/lib.h
+++ b/lib.h
@@ -134,6 +134,7 @@ enum phase {
 
 extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1);
 extern void predefine(const char *name, int weak, const char *fmt, ...) FORMAT_ATTR(3);
+extern void predefine_nostd(const char *name);
 
 extern int preprocess_only;
 
diff --git a/pre-process.c b/pre-process.c
index c35cbcfb..5a9313a3 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -1568,6 +1568,14 @@ void predefine(const char *name, int weak, const char *fmt, ...)
 	do_define(value->pos, NULL, ident, NULL, value, attr);
 }
 
+///
+// like predefine() but only if one of the non-standard dialect is chosen
+void predefine_nostd(const char *name)
+{
+	if ((standard & STANDARD_GNU) || (standard == STANDARD_NONE))
+		predefine(name, 1, "1");
+}
+
 static int do_handle_define(struct stream *stream, struct token **line, struct token *token, int attr)
 {
 	struct token *arglist, *expansion;
-- 
2.23.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.