mirror of
https://github.com/TinyCC/tinycc.git
synced 2025-11-16 12:34:45 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user