tccgen.c: fix two scope problems

... see tests

Also:
- tccgen.c: cleanup _Generic a little
- libtcc.c: cleanup mem-debug a little
- arm-link.c: read/write only once
- tcc.h: another fix for clang offsetof
- tccdbg.c:
  * stabs: handle forward struct/enum decls
  * stabs: fix anonymous struct members (must not have a .L123 name)
  * avoid strncpy()
This commit is contained in:
grischka
2025-08-18 22:55:38 +02:00
parent 4e6c4db340
commit acb2a909dd
8 changed files with 166 additions and 60 deletions

View File

@@ -1,7 +1,11 @@
#include <stdio.h>
int printf(const char*, ...);
#define myassert(x) \
printf("%s:%d: %s : \"%s\"\n", __FILE__,__LINE__,(x)?"ok":"error",#x)
enum{ in = 0};
#define myassert(X) do{ if(!X) printf("%d: assertion failed\n", __LINE__); }while(0)
int main(){
int main_1(){
{
myassert(!in);
if(sizeof(enum{in=1})) myassert(in);
@@ -38,6 +42,45 @@ int main(){
for(;sizeof(enum{in=1});){ myassert(in); break; }
myassert(!in); //OK
}
return 0;
}
/* --------------------------------------------- */
int main_2()
{
char c = 'a';
void func1(char c); /* param 'c' must not shadow local 'c' */
func1(c);
return 0;
}
void func1(char c)
{
myassert(c == 'a');
}
struct st { int a; };
/* --------------------------------------------- */
int main_3()
{
struct st func(void);
struct st st = func(); /* not an 'incompatible redefinition' */
myassert(st.a == 10);
return 0;
}
struct st func(void)
{
struct st st = { 10 };
return st;
}
/* --------------------------------------------- */
int main()
{
main_1();
main_2();
main_3();
return 0;
}

View File

@@ -0,0 +1,23 @@
129_scopes.c:10: ok : "!in"
129_scopes.c:11: ok : "in"
129_scopes.c:12: ok : "!in"
129_scopes.c:15: ok : "!in"
129_scopes.c:16: ok : "in"
129_scopes.c:17: ok : "!in"
129_scopes.c:20: ok : "!in"
129_scopes.c:21: ok : "in"
129_scopes.c:22: ok : "!in"
129_scopes.c:25: ok : "!in"
129_scopes.c:26: ok : "!in"
129_scopes.c:27: ok : "!in"
129_scopes.c:31: ok : "!in"
129_scopes.c:32: ok : "in"
129_scopes.c:33: ok : "!in"
129_scopes.c:36: ok : "!in"
129_scopes.c:37: ok : "in"
129_scopes.c:38: ok : "!in"
129_scopes.c:41: ok : "!in"
129_scopes.c:42: ok : "in"
129_scopes.c:43: ok : "!in"
129_scopes.c:59: ok : "c == 'a'"
129_scopes.c:69: ok : "st.a == 10"