Op 24-08-2025 om 15:01 schreef Herman ten Brugge:
Another problem from the test suite:
int printf(const char *,...);
int a[3];
int f(void);
int main(void)
{
extern int a[3];
a[2]=10;
printf("%d\n", f());
}
int f(void)
{
return a[2]==10 ? 1 : 0;
}
results in:
15: error: invalid operand types for binary operation
It looks like the extern is introducing the problem.
I found a fix for this problem as well. See attachment.
Herman
diff --git a/tccgen.c b/tccgen.c
index 67cf6b9..4b06ecf 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -8788,6 +8788,7 @@ static int decl(int l)
if (sym && sym->sym_scope == local_scope) {
if (!is_compatible_types(&sym->type, &type)
|| !(sym->type.t & VT_TYPEDEF))
+ redef:
tcc_error("incompatible redefinition of '%s'",
get_tok_str(v, NULL));
sym->type = type;
@@ -8824,8 +8825,16 @@ static int decl(int l)
&& l == VT_CONST && type.ref->c < 0)
) {
/* external variable or function */
- type.t |= VT_EXTERN;
- external_sym(v, &type, r, &ad);
+ sym = sym_find(v);
+ if ((type.t & VT_EXTERN) &&
+ sym && local_scope && sym->sym_scope == 0) {
+ if (!is_compatible_types(&sym->type, &type))
+ goto redef;
+ }
+ else {
+ type.t |= VT_EXTERN;
+ external_sym(v, &type, r, &ad);
+ }
} else {
if (l == VT_CONST || (type.t & VT_STATIC))
r |= VT_CONST;
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel