Re: sparse v0.6.4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 06, 2021 at 07:53:19PM +0100, Ramsay Jones wrote:
> 
> 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).

Nice. Thank you.
 
> [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. :( ]

Yes, it was posted on the ML (archived as
https://lore.kernel.org/linux-sparse/20210906042111.lhoq7egtpmw3jcv6@mail/ )
I used to be unsubscribed from various kernel.org mailing list relatively
often (but I think I haven't been the last 2 years or so, at least from the
sparse ML).

> 
> 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.

I vaguely remember there was some complications for switch labels but I can't
remember the details.

> 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 tend more and more to use errors only for the cases where Sparse can't
handle the following correctly anymore.

> 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.

Yes, I'm aware of this but IIRC the motivation was related to the mixing
of statements and declarations. The next standard is planned for 2023,
meanwhile I don't have a strong opinion about this error/warning (but
I'm very fine making things coherent between switch and regular labels).

Best regards,
-- Luc



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux