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
diff --git a/tccgen.c b/tccgen.c
index d5e9bf5..24c46ed 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -7253,6 +7253,9 @@ again:
             if (debug_modes)
                 tcc_tcov_reset_ind(tcc_state);
             vla_restore(cur_scope->vla.loc);
+            /* c23 declaration after label */
+            if (tok != ';')
+                decl(VT_LOCAL);
             if (tok != '}')
                 goto again;
             /* we accept this, but it is a mistake */
@@ -7266,7 +7269,7 @@ again:
                 if (is_expr) {
                     vpop();
                     gexpr();
-                } else if (!decl(VT_JMP)) {
+                } else {
                     gexpr();
                     vpop();
                 }
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to