aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Johnstone <geoff.johnstone@googlemail.com>2008-04-05 02:50:40 -0700
committerJosh Triplett <josh@freedesktop.org>2008-04-05 02:50:40 -0700
commitebed4963196340cf740bbcac3c3ac448a5b03add (patch)
tree9e259b80116a3ff91f83b8125bb22655798d61a7
parent0a09c64fd78b874a4f3abda7f5cd844eb20b71f6 (diff)
downloadsparse-ebed4963196340cf740bbcac3c3ac448a5b03add.tar.gz
sparse-ebed4963196340cf740bbcac3c3ac448a5b03add.tar.xz
sparse-ebed4963196340cf740bbcac3c3ac448a5b03add.zip
Add support for GCC's -std=... and -ansi command line options.
This adds support for GCC's -std=... and -ansi command line options, i.e. defining __STDC_VERSION__ and __STRICT_ANSI__ appropriately. This means that code that invokes #error if __STDC_VERSION__ < 199901L will work. It will probably also affect the userland header files too. Signed-off-by: Geoff Johnstone <geoff.johnstone@googlemail.com>
-rw-r--r--lib.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 2099262..8a417eb 100644
--- a/lib.c
+++ b/lib.c
@@ -214,6 +214,12 @@ int dbg_dead = 0;
int preprocess_only;
+static enum { STANDARD_C89,
+ STANDARD_C94,
+ STANDARD_C99,
+ STANDARD_GNU89,
+ STANDARD_GNU99, } standard = STANDARD_GNU89;
+
#define CMDLINE_INCLUDE 20
int cmdline_include_nr = 0;
struct cmdline_include cmdline_include[CMDLINE_INCLUDE];
@@ -495,6 +501,46 @@ static char **handle_switch_G(char *arg, char **next)
return next; // "-G0" or (bogus) terminal "-G"
}
+static char **handle_switch_a(char *arg, char **next)
+{
+ if (!strcmp (arg, "ansi"))
+ standard = STANDARD_C89;
+
+ return next;
+}
+
+static char **handle_switch_s(char *arg, char **next)
+{
+ if (!strncmp (arg, "std=", 4))
+ {
+ arg += 4;
+
+ if (!strcmp (arg, "c89") ||
+ !strcmp (arg, "iso9899:1990"))
+ standard = STANDARD_C89;
+
+ else if (!strcmp (arg, "iso9899:199409"))
+ standard = STANDARD_C94;
+
+ else if (!strcmp (arg, "c99") ||
+ !strcmp (arg, "c9x") ||
+ !strcmp (arg, "iso9899:1999") ||
+ !strcmp (arg, "iso9899:199x"))
+ standard = STANDARD_C99;
+
+ else if (!strcmp (arg, "gnu89"))
+ standard = STANDARD_GNU89;
+
+ else if (!strcmp (arg, "gnu99") || !strcmp (arg, "gnu9x"))
+ standard = STANDARD_GNU99;
+
+ else
+ die ("Unsupported C dialect");
+ }
+
+ return next;
+}
+
static char **handle_nostdinc(char *arg, char **next)
{
add_pre_buffer("#nostdinc\n");
@@ -538,6 +584,8 @@ char **handle_switch(char *arg, char **next)
case 'O': return handle_switch_O(arg, next);
case 'f': return handle_switch_f(arg, next);
case 'G': return handle_switch_G(arg, next);
+ case 'a': return handle_switch_a(arg, next);
+ case 's': return handle_switch_s(arg, next);
default:
break;
}
@@ -613,6 +661,33 @@ void create_builtin_stream(void)
add_pre_buffer("#weak_define __SIZE_TYPE__ unsigned int\n");
add_pre_buffer("#weak_define __STDC__ 1\n");
+ switch (standard)
+ {
+ case STANDARD_C89:
+ add_pre_buffer("#weak_define __STRICT_ANSI__\n");
+ break;
+
+ case STANDARD_C94:
+ add_pre_buffer("#weak_define __STDC_VERSION__ 199409L\n");
+ add_pre_buffer("#weak_define __STRICT_ANSI__\n");
+ break;
+
+ case STANDARD_C99:
+ add_pre_buffer("#weak_define __STDC_VERSION__ 199901L\n");
+ add_pre_buffer("#weak_define __STRICT_ANSI__\n");
+ break;
+
+ case STANDARD_GNU89:
+ break;
+
+ case STANDARD_GNU99:
+ add_pre_buffer("#weak_define __STDC_VERSION__ 199901L\n");
+ break;
+
+ default:
+ assert (0);
+ }
+
add_pre_buffer("#define __builtin_stdarg_start(a,b) ((a) = (__builtin_va_list)(&(b)))\n");
add_pre_buffer("#define __builtin_va_start(a,b) ((a) = (__builtin_va_list)(&(b)))\n");
add_pre_buffer("#define __builtin_va_arg(arg,type) ({ type __va_arg_ret = *(type *)(arg); arg += sizeof(type); __va_arg_ret; })\n");