linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: sparse v0.6.4
Date: Mon, 6 Sep 2021 19:53:19 +0100	[thread overview]
Message-ID: <e9edc9f5-9b88-4a6a-17f8-544270ec2450@ramsayjones.plus.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3075 bytes --]


Hi Luc,

I have tested the new release, without issue, in the normal way on the
usual platforms (32- & 64-bit Linux, 64-bit cygwin).

[Have you posted to the sparse mailing-list yet? I think my subscription
has lapsed or something! I recently had to re-subscribe to the git
mailing-list as well. :( ]

Sorry for being tardy, but about 3 months ago a sparse issue came up on
the git mailing-list (see [1]). Take a look at this:

  $ cat -n junk.c
       1	
       2	static void func(int x)
       3	{
       4		switch (x) {
       5			default:
       6		}
       7	}
  $ sparse junk.c
  junk.c:6:9: error: Expected ; at end of statement
  junk.c:6:9: error: got }
  junk.c:8:0: error: Expected } at end of compound statement
  junk.c:8:0: error: got end-of-input
  junk.c:8:0: error: Expected } at end of function
  junk.c:8:0: error: got end-of-input
  $ 

Note: a case label that doesn't label a statement is not valid C, so what
is the problem? Well, for me, the implication of the email exchange was
that gcc seems to accept it without problem, except (with gcc 9.3.0):

  $ gcc junk.c
  junk.c: In function ‘func’:
  junk.c:5:3: error: label at end of compound statement
      5 |   default:
        |   ^~~~~~~
  $ 

... it doesn't for me!

So, I decided just to improve the error message issued by sparse. However,
that caused a moment of deja vu for me - hadn't you already fixed this
same issue? Having found your commit 0d6bb7e1 ("handle more graciously
labels with no statement", 2020-10-26), I realized that your fix only applied
for regular labels. The attached patch was the result of extending your
solution to case labels, like so:

  $ ./sparse junk.c
  junk.c:6:9: warning: statement expected after case label
  $ 

Note, just like your earlier commit, this issues a warning, rather than an
error (which it should probably be). I wrote this patch back in June, and
then forgot about it. :( [well, it was only lightly tested (testsuite and
one run over git), no tests, no commit message and it should probably be
an error!]

About a month ago, I noticed that gcc 11.2 had been released and the
release notes mentioned "Labels may appear before declarations and at the
end of a compound statement."  This, in turn, caused me to check my
current draft C2x document (dated December 11, 2020), which includes the
following:'N2508 Free Positioning of Labels Inside Compound Statements'.

It just so happens that, last night, I updated my cygwin installation and
the version of gcc went from 10.2 to 11.2. I think you can probably guess
what comes next:

  $ gcc -c junk.c
  $

  $ gcc -c -pedantic junk.c
  junk.c: In function ‘func’:
  junk.c:5:17: warning: label at end of compound statement [-Wpedantic]
      5 |                 default:
        |                 ^~~~~~~
  $ 

[Note: I tried several -std=cxx, but none of them even warned without
-pedantic]

So, for now, the standard does not allow these constructs, but the next
standard (whenever that will be) will.

ATB,
Ramsay Jones

[1] https://lore.kernel.org/git/xmqqr1hlqd5v.fsf@gitster.g/

[-- Attachment #2: 0001-parse-warn-about-a-case-label-on-empty-statement.patch --]
[-- Type: text/x-patch, Size: 890 bytes --]

From 39f65942a4047a391ca8323ae109ae3c1fe14bd9 Mon Sep 17 00:00:00 2001
From: Ramsay Jones <ramsay@ramsayjones.plus.com>
Date: Mon, 6 Sep 2021 19:00:57 +0100
Subject: [PATCH] parse: warn about a 'case label' on empty statement

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
 parse.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/parse.c b/parse.c
index bc1c0602..9f2a3cdf 100644
--- a/parse.c
+++ b/parse.c
@@ -2329,6 +2329,11 @@ static inline struct token *case_statement(struct token *token, struct statement
 	stmt->type = STMT_CASE;
 	token = expect(token, ':', "after default/case");
 	add_case_statement(stmt);
+	if (match_op(token, '}')) {
+		warning(token->pos, "statement expected after case label");
+		stmt->case_statement = alloc_statement(token->pos, STMT_NONE);
+		return token;
+	}
 	return statement(token, &stmt->case_statement);
 }
 
-- 
2.33.0


             reply	other threads:[~2021-09-06 19:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06 18:53 Ramsay Jones [this message]
2021-09-07  6:14 ` sparse v0.6.4 Luc Van Oostenryck
2022-01-15  4:25 ` Randy Dunlap
2022-05-21 13:54   ` Luc Van Oostenryck
2022-05-21 15:51     ` Randy Dunlap
2022-06-14  0:17   ` [PATCH] predefine __ATOMIC_ACQUIRE & friends as weak Luc Van Oostenryck

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=e9edc9f5-9b88-4a6a-17f8-544270ec2450@ramsayjones.plus.com \
    --to=ramsay@ramsayjones.plus.com \
    --cc=gitster@pobox.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    /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).