linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add -gcc-version option
@ 2017-07-18 21:59 Pavel Roskin
  2017-07-18 23:35 ` Christopher Li
  0 siblings, 1 reply; 6+ messages in thread
From: Pavel Roskin @ 2017-07-18 21:59 UTC (permalink / raw)
  To: linux-sparse

The option argument is parsed into major, minor and patchlevel versions,
which are defined as __GNUC__, __GNUC_MINOR__, and __GNUC_PATCHLEVEL__ in
the preprocessor.

One possible use is running sparse compiled with the lastest gcc compiler
on a Linux kernel that doesn't support that compiler.

Signed-off-by: Pavel Roskin <pavel.roskin@virginorbit.com>
---
 lib.c    | 45 +++++++++++++++++++++++++++++++++++++++++++++
 sparse.1 |  7 +++++++
 2 files changed, 52 insertions(+)

diff --git a/lib.c b/lib.c
index ce66a81..aff6862 100644
--- a/lib.c
+++ b/lib.c
@@ -24,6 +24,7 @@
  */
 #include <ctype.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -831,10 +832,54 @@ static char **handle_base_dir(char *arg, char **next)
     return next;
 }

+static char **handle_gcc_version(char *arg, char **next)
+{
+    unsigned long gcc_major_ul, gcc_minor_ul = 0, gcc_patchlevel_ul = 0;
+    char *gcc_version, *p;
+
+    gcc_version = *++next;
+    if (!gcc_version)
+        die("missing argument for -gcc-version option");
+
+    gcc_major_ul = strtoul(gcc_version, &p, 10);
+    if (gcc_major_ul > INT_MAX)
+        die("bad gcc major version");
+
+    if (*p == '\0')
+        goto good;
+    else if (*p != '.')
+        die("bad character after gcc major version");
+
+    gcc_minor_ul = strtoul(p + 1, &p, 10);
+    if (gcc_minor_ul > INT_MAX)
+        die("bad gcc minor version");
+
+    if (*p == '\0')
+        goto good;
+    else if (*p != '.')
+        die("bad character after gcc minor version");
+
+    gcc_patchlevel_ul = strtoul(p + 1, &p, 10);
+    if (gcc_patchlevel_ul > INT_MAX)
+        die("bad gcc patchlevel version");
+
+    if (*p != '\0')
+        die("bad character after gcc patchlevel version");
+
+good:
+    gcc_major = gcc_major_ul;
+    gcc_minor = gcc_minor_ul;
+    gcc_patchlevel = gcc_patchlevel_ul;
+
+    return next;
+}
+
 static char **handle_switch_g(char *arg, char **next)
 {
     if (!strcmp (arg, "gcc-base-dir"))
         return handle_base_dir(arg, next);
+    else if (!strcmp (arg, "gcc-version"))
+        return handle_gcc_version(arg, next);

     return next;
 }
diff --git a/sparse.1 b/sparse.1
index b79c587..9f2c52d 100644
--- a/sparse.1
+++ b/sparse.1
@@ -355,6 +355,13 @@ Look for system headers in the multiarch
subdirectory \fIdir\fR.
 The \fIdir\fR name would normally take the form of the target's
 normalized GNU triplet. (e.g. i386-linux-gnu).
 .
+.TP
+.B \-gcc-version \fIversion\fR
+Simulate behavior of gcc of the specified version. At this time, this
+switch only affects macros \fI__GNUC__\fR, \fI__GNUC_MINOR__\fR, and
+\fI__GNUC_PATCHLEVEL__\fR. The default value is the version of gcc that
+compiled sparse, or \fI2.95.0\fR if that information is missing.
+.
 .SH DEBUG OPTIONS
 .TP
 .B \-fdump-linearize[=only]
-- 
2.13.3


-- 
Regards,
Pavel Roskin

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-07-19 19:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-18 21:59 [PATCH] Add -gcc-version option Pavel Roskin
2017-07-18 23:35 ` Christopher Li
2017-07-18 23:46   ` Pavel Roskin
2017-07-19 13:07     ` Christopher Li
2017-07-19 17:27       ` Pavel Roskin
2017-07-19 19:16         ` Christopher Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).