commit 0f64b0ae4296cc9919a9b9faa897007200ed6b2f
parent ff3de6ad52b27002a8ff2c3611f02b6b45978b00
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Mon, 13 Apr 2026 12:02:40 +0200
cc1: Prefer defined types over not defined
Extern declarations can use an incomplete type, and that incomplete
type was hiding the type of new declarations. To avoid this problem,
this patch uses the new declared type in redeclarations if the type
of the symbol is incomplete as we already checked at that point if
the types were compatible or not.
Diffstat:
3 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/src/cmd/scc-cc/cc1/decl.c b/src/cmd/scc-cc/cc1/decl.c
@@ -260,6 +260,9 @@ redcl(Symbol *sym, Type *tp, int sclass)
}
sym->flags = flags;
+ if (!(sym->type->prop & TDEFINED) && tp->prop & TDEFINED)
+ sym->type = tp;
+
return sym;
redeclaration:
diff --git a/tests/cc/execute/0269-extern.c b/tests/cc/execute/0269-extern.c
@@ -0,0 +1,17 @@
+extern unsigned char tbl[];
+
+unsigned char tbl[8] = {
+ 1, 0, 2, 0,
+};
+
+unsigned char c = 3;
+
+int
+main(void)
+{
+ if (tbl[0] != 1 || tbl[2] != 2)
+ return 1;
+ if (tbl[4] != 0)
+ return 2;
+ return 0;
+}
diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst
@@ -259,3 +259,4 @@
0266-wchar.c
0267-wchar.c
0268-string.c
+0269-extern.c