On 19.08.2025 11:35, Herman ten Brugge via Tinycc-devel wrote:
This program stopped working after commit "local scope for types of function 
parameters"

#include <stdio.h>

int main(void)
{
   char c = 'a';
   void func1(char c);

   func1(c);
   return 0;
}

void func1(char c)
{
     printf("%c\n", c);
}

Oops, tricky.  Thing is that if an 'extern' symbol or a function is
declared locally and is not yet known, then it is pushed on global_stack
via external_sym() and global_identifier_push().

But the 'ref' symbols (parameters) would be still on local_stack.
So these must be copied to global stack too otherwise it would crash
later when local stack was popped.  This is done by copy_sym_ref().

It's just that these symbol must not be made lexically visible which
is what happened with this bug.  Would just need to add in copy_sym():

    if ((s->v & ~SYM_STRUCT) < SYM_FIRST_ANOM
+       && ps == &local_stack)
        sym_link(s, 1);

As to the debug problem:

I tested stabs and did 'p *s' in tcc.exe:main() to see TCCState,
nothing.  So it turned out that because TCCState is typedef'd in
libtcc.h first, it is in stabs with no members and a size of -1
and won't be added later because it already was.

Dwarf seems to have another problem though that in a case with some
mutually linked structures, it would quickly eat up 2GB -> memory full.
Which is why I added -g1dwarf switch so I can compile that project.

Seems that stabs works because the tcc_debug_remove(s1, e); doesn't
work ('e' was never added). Whereas with dwarf 't' is removed but
the code never stops.

Why should it output the same structure more than once anyway ?

-- grischka


     Herman

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to