linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 5/5] C11: teach sparse about '--std={c11,gnu11}'
Date: Thu,  5 Jan 2017 04:22:20 +0100	[thread overview]
Message-ID: <20170105032220.7339-6-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170105032220.7339-1-luc.vanoostenryck@gmail.com>

Now that support have been added for C11 new syntax we can accept
'--std={c11,gnu11}' no more dying with "Unsupported C dialect" message.
Also adjust __STDC_VERSION__ accordingly and define the few
associated feature macros (__STD_NO_ATOMICS__, ...).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c                         | 21 +++++++++++++++++++++
 validation/c11-stdc-version.c | 11 +++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 validation/c11-stdc-version.c

diff --git a/lib.c b/lib.c
index e5b0bb63..49ff6906 100644
--- a/lib.c
+++ b/lib.c
@@ -250,6 +250,8 @@ int preprocess_only;
 static enum { STANDARD_C89,
               STANDARD_C94,
               STANDARD_C99,
+              STANDARD_C11,
+              STANDARD_GNU11,
               STANDARD_GNU89,
               STANDARD_GNU99, } standard = STANDARD_GNU89;
 
@@ -574,6 +576,8 @@ static void handle_switch_W_finalize(void)
 			case STANDARD_C99:
 			case STANDARD_GNU89:
 			case STANDARD_GNU99:
+			case STANDARD_C11:
+			case STANDARD_GNU11:
 				Wdeclarationafterstatement = 0;
 				break;
 
@@ -679,6 +683,14 @@ static char **handle_switch_s(char *arg, char **next)
 		else if (!strcmp (arg, "gnu99") || !strcmp (arg, "gnu9x"))
 			standard = STANDARD_GNU99;
 
+		else if (!strcmp(arg, "c11") ||
+			 !strcmp(arg, "c1x") ||
+			 !strcmp(arg, "iso9899:2011"))
+			standard = STANDARD_C11;
+
+		else if (!strcmp(arg, "gnu11"))
+			standard = STANDARD_GNU11;
+
 		else
 			die ("Unsupported C dialect");
 	}
@@ -971,6 +983,15 @@ void create_builtin_stream(void)
 			add_pre_buffer("#weak_define __STDC_VERSION__ 199901L\n");
 			break;
 
+		case STANDARD_C11:
+			add_pre_buffer("#weak_define __STRICT_ANSI__ 1\n");
+		case STANDARD_GNU11:
+			add_pre_buffer("#weak_define __STDC_NO_ATOMICS__ 1\n");
+			add_pre_buffer("#weak_define __STDC_NO_COMPLEX__ 1\n");
+			add_pre_buffer("#weak_define __STDC_NO_THREADS__ 1\n");
+			add_pre_buffer("#weak_define __STDC_VERSION__ 201112L\n");
+			break;
+
 		default:
 			assert (0);
 	}
diff --git a/validation/c11-stdc-version.c b/validation/c11-stdc-version.c
new file mode 100644
index 00000000..3acedd19
--- /dev/null
+++ b/validation/c11-stdc-version.c
@@ -0,0 +1,11 @@
+__STDC_VERSION__
+
+/*
+ * check-name: c11-stdc-version
+ * check-command: sparse -E -std=c11 $file
+ *
+ * check-output-start
+
+201112L
+ * check-output-end
+ */
-- 
2.11.0


      parent reply	other threads:[~2017-01-05  3:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-05  3:22 [PATCH 0/5] add basic support for C11 Luc Van Oostenryck
2017-01-05  3:22 ` [PATCH 1/5] C11: teach sparse about '_Thread_local' Luc Van Oostenryck
2017-01-05  3:22 ` [PATCH 2/5] C11: teach sparse about '_Noreturn' Luc Van Oostenryck
2017-01-05  3:22 ` [PATCH 3/5] C11: teach sparse about '_Alignof()' Luc Van Oostenryck
2017-01-05  3:22 ` [PATCH 4/5] C11: teach sparse about '_Alignas()' Luc Van Oostenryck
2017-01-05  3:22 ` Luc Van Oostenryck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170105032220.7339-6-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).