tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Variable declaration as first statement in a 'case' b


From: Herman ten Brugge
Subject: Re: [Tinycc-devel] Variable declaration as first statement in a 'case' block gives error.
Date: Fri, 19 Jan 2024 07:18:41 +0100
User-agent: Mozilla Thunderbird

On 1/18/24 22:08, grischka wrote:
On 18.01.2024 17:38, Herman ten Brugge via Tinycc-devel wrote:
That depends on the version of gcc / clang.
Gcc 13.2.1 prints no error.
Clang 17.0.6 prints "error: expected expression"
Clang 18.0.0(not released yet) prints "warning: label followed by a declaration is a C23 extension [-Wc23-extensions]"

I probably should have mentioned it when committing the fix.

Maybe yes.

Plus mention that it's not a fix, but an experiment
with undocumented non-standard syntax.

Plus mention the benefit and the price too, please.

Plus while at it, spend some thoughts first:

-                } else {
+                } else if (!decl(VT_JMP)) {
                     gexpr();
                     vpop();


Hm... just one line changed.  But wait, does not tcc look
for decl before expression already?  Sure it does because
it supports C99.  Why now look twice ?  And why skip parsing
the expression if where was a declaration?  What's the point?
Who wrote that?

Let's maybe try to use the tcov for tcc (which as we know was
you who wrote it and is really not bad btw):

$ tcc -ftest-coverage ../tcc.c -o tcc1.exe && tcc1.exe ../tcc.c -o tcc2.exe

tcc1.exe.tcov:
       -: 0:Function:decl 68.67%
Before:
  10701: 8417: int v, has_init, r, oldint;
After:
  18408: 8417: int v, has_init, r, oldint;

We note 7707 additional (+72%) calls for decl(),

      183: 7247:    block_after_label:
     1006: 7248:              {

and that however only 1006 labels/cases/defaults were seen
at all.

Also we note no "label: decl" in tcc anywhere and also in
noone elses code we've seen so far (the OP's doesn't count
because it's generated C IIUC)

Now back to the "benefit vs. price" question ...

I wanted to avoid an extra check for ';' because I found code like:

    case xxx: ; }

Instead of writing 'break;' they used ';'.
Without checking for ';' a warning was printed:
deprecated use of label at end of compound statement

So how about the next patch:
C23: Implement declaration after label (see attached patch)

    Herman

Attachment: patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]