History

tccgen: more of scope hacks

* case 1: local scope of 'ff' int main() { int ff = 123; { int ff(int): ff(456) }} * case 2: linkage of a static extern symbol (older gcc did allow that) static int ff(int); int main() { int ff(int): ff(456) } Also: - cleanup enum, let sym_push() handle redefinition - just mark incomplete array base types, unshare only when needed (in decl_initializer_alloc()) - fix sizeof empty array (= 0) : int ii[] = {}; - rename 'Sym' members used by __attribute__((cleanup(f)))

grischka committed 1 year ago

Commit 38ab5f61 parent ce4de9610 files · +288 −144Browse files

Showing the changes to tests (7 of 10 files). Show all

Unified · Split

7 files
  1. tests/tests2/129_scopes.c +77 −14
  2. tests/tests2/129_scopes.expect +8 −2
  3. tests/tests2/35_sizeof.c +24 −8
  4. tests/tests2/35_sizeof.expect +7 −2
  5. tests/tests2/39_typedef.c +9 −0
  6. tests/tests2/39_typedef.expect +2 −0
  7. tests/tests2/60_errors_and_warnings.expect +1 −1
tests/tests2/129_scopes.c+77−14
@@ -77,40 +77,101 @@ struct st func(void) · 76 unmodified lines
7777 }
7878
7979 /* --------------------------------------------- */
80−static void func2(char *(*md)(char *md))
80+/* func* 'md' must not be shadowed by param 'md' */
81+static void f4(char *(*md)(char *md))
8182 {
8283 (*md)("test");
8384 }
84−
85−static char *a(char *a)
85+static char *a4(char *a)
8686 {
87− printf("%s\n", a);
87+ int strcmp();
88+ myassert(!strcmp(a, "test"));
8889 return a;
8990 }
9091
91−int main_4(void)
92+int main_4()
9293 {
93− func2(a);
94+ f4(a4);
9495 return 0;
9596 }
9697
9798 /* --------------------------------------------- */
98−int b[3];
99−int f(void);
99+int a5[3], b5[];
100+int f5(void);
101+int main_5()
102+{
103+ extern int a5[3], b5[3];
104+ a5[2]=10, b5[2]=4;
105+ myassert(f5() == 10 + 4);
106+ return 0;
107+}
108+int f5(void)
109+{
110+ return a5[2]+b5[2];
111+}
112+int b5[3];
100113
101−int main_5(void)
114+/* --------------------------------------------- */
115+static int f6(int);
116+int i6 = 11;
117+
118+int main_6()
102119 {
103− extern int b[3];
104− b[2]=10;
105− printf("%d\n", f());
120+ {
121+ int i6 = 33, f6 = 44;
122+ myassert(i6 == 33 && f6 == 44);
123+ {
124+ int f6(int);
125+ extern int i6;
126+ myassert(i6 == 11 && f6(22) == 22);
127+ }
128+ myassert(i6 == 33 && f6 == 44);
129+ }
130+ myassert(i6 == 11 && f6(22) == 22);
106131 return 0;
107132 }
108133
109−int f(void)
134+int f6(int x)
110135 {
111− return b[2]==10 ? 1 : 0;
136+ return x;
112137 }
113138
139+/* --------------------------------------------- */
140+
141+#if defined __TINYC__ \
142+ ? !defined __leading_underscore \
143+ : !(defined __APPLE__ || defined _WIN32)
144+# define _
145+#else
146+# define _ "_"
147+#endif
148+
149+struct xx7 { int a, b; };
150+
151+void f7()
152+{
153+ struct xx7 { int c; } x;
154+ {
155+ extern struct xx7 { int a, b; } x __asm__(_"z7");
156+ x.a = 12;
157+ struct xx7 y = { 0,0 };
158+ }
159+ struct xx7 y = { 90 };
160+ x.c = 78;
161+ printf("xx7 (1) : %d %d\n", x.c, y.c);
162+}
163+
164+int main_7()
165+{
166+ f7();
167+ extern struct xx7 y __asm__(_"z7");
168+ printf("xx7 (2) : %d %d\n", y.a, y.b);
169+ return 0;
170+}
171+
172+
173+struct xx7 z7 = { 0, 34 };
174+
114175 /* --------------------------------------------- */
115176 int main()
116177 {
@@ -119,5 +180,7 @@ int main() · 2 unmodified lines
119180 main_3();
120181 main_4();
121182 main_5();
183+ main_6();
184+ main_7();
122185 return 0;
123186 }
tests/tests2/129_scopes.expect+8−2
@@ -21,5 +21,11 @@ · 20 unmodified lines
2121 129_scopes.c:43: ok : "!in"
2222 129_scopes.c:59: ok : "c == 'a'"
2323 129_scopes.c:69: ok : "st.a == 10"
24−test
25−1
24+129_scopes.c:88: ok : "!strcmp(a, "test")"
25+129_scopes.c:105: ok : "f5() == 10 + 4"
26+129_scopes.c:122: ok : "i6 == 33 && f6 == 44"
27+129_scopes.c:126: ok : "i6 == 11 && f6(22) == 22"
28+129_scopes.c:128: ok : "i6 == 33 && f6 == 44"
29+129_scopes.c:130: ok : "i6 == 11 && f6(22) == 22"
30+xx7 (1) : 78 90
31+xx7 (2) : 12 34
tests/tests2/35_sizeof.c+24−8
@@ -1,14 +1,30 @@
1−#include <stdio.h>
1+int printf(const char*, ...);
22
33 int main()
44 {
5− char a;
6− short b;
5+ char a;
6+ short b;
77
8− printf("%d %d\n", sizeof(char), sizeof(a));
9− printf("%d %d\n", sizeof(short), sizeof(b));
8+ printf("sizeof a : %d %d\n", sizeof(char), sizeof(a));
9+ printf("sizeof b : %d %d\n", sizeof(short), sizeof(b));
1010
11− return 0;
12−}
11+ int ii[] = {}; /* gnu extension, size = 0 */
12+ printf("sizeof ii : %d\n", sizeof ii);
13+
14+ int kk[] = { 1 };
15+ printf("sizeof kk : %d\n", sizeof kk);
16+
17+ char cc[] = "12";
18+ printf("sizeof cc : %d\n", sizeof cc);
1319
14−/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
20+ __WCHAR_TYPE__ ll[] = L"12345";
21+ printf("len-of ll : %d\n", sizeof ll / sizeof ll[0]);
22+
23+ static struct {
24+ int a,b,c;
25+ int d[];
26+ } ss[] = {{ 1, 2, 3, {} }};
27+ printf("sizeof ss : %d\n", sizeof ss);
28+
29+ return 0;
30+}
tests/tests2/35_sizeof.expect+7−2
@@ -1,2 +1,7 @@
1−1 1
2−2 2
1+sizeof a : 1 1
2+sizeof b : 2 2
3+sizeof ii : 0
4+sizeof kk : 4
5+sizeof cc : 3
6+len-of ll : 6
7+sizeof ss : 12
tests/tests2/39_typedef.c+9−0
@@ -13,6 +13,7 @@ typedef struct FunStruct MyFunStruct; · 12 unmodified lines
1313 typedef MyFunStruct *MoreFunThanEver;
1414
1515 typedef int t[];
16+int tints[];
1617
1718 int main()
1819 {
@@ -36,6 +37,14 @@ int main() · 17 unmodified lines
3637 printf("%d\n", (int)sizeof((t){1,2,3}));
3738 printf("%d\n", (int)sizeof((t){1,2,3,4}));
3839
40+ /* two arrays derived from same base type */
41+ t t3 = { 1,2,3 }, t4 = { 4,5,6,7 };
42+ for (p = t3, i = 0; i < 3 ; i++) printf("%d ", *p++);
43+ for (p = t4, i = 0; i < 4 ; i++) printf("%d ", *p++); printf("\n");
44+ typeof(tints) t5 = { 1,2,3 }, t6 = { 4,5,6,7 };
45+ for (p = t5, i = 0; i < 3 ; i++) printf("%d ", *p++);
46+ for (p = t6, i = 0; i < 4 ; i++) printf("%d ", *p++); printf("\n");
47+
3948 return 0;
4049 }
4150
tests/tests2/39_typedef.expect+2−0
@@ -5,3 +5,5 @@ · 4 unmodified lines
55 1 2 3 4
66 12
77 16
8+1 2 3 4 5 6 7
9+1 2 3 4 5 6 7
tests/tests2/60_errors_and_warnings.expect+1−1
@@ -17,7 +17,7 @@ · 16 unmodified lines
1717 60_errors_and_warnings.c:21: error: struct/union/enum already defined
1818
1919 [test_62_enumerator_redefinition]
20−60_errors_and_warnings.c:26: error: redefinition of enumerator 'RED'
20+60_errors_and_warnings.c:26: error: redeclaration of 'RED'
2121
2222 [test_63_local_enumerator_redefinition]
2323 [returns 1]

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t