shithub: scc

Download patch

ref: 46ff41bc9e13600e602de27f04695e17bacac390
parent: efda45c11a438f0a83f57f55b34abb812f32cd53
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Nov 5 02:38:46 EDT 2021

cc2/qbe: Use common symbols for tentative declarations

Common symbols allow multiple tentative definitions in
different symbols, which is a common extension of the C
language, specially in UNIX where C was born.

--- a/src/cmd/cc/cc2/target/qbe/code.c
+++ b/src/cmd/cc/cc2/target/qbe/code.c
@@ -287,10 +287,13 @@
 		return;
 	if (sym->kind == SGLOB)
 		fputs("export ", stdout);
-	printf("data %s = align %d {\n", symname(sym), tp->align);
-	if (sym->type.flags & INITF)
-		return;
-	printf("\tz\t%lu\n}\n", tp->size);
+
+	printf("data %s = %s align %d {\n",
+	       symname(sym),
+	       (tp->flags & INITF) ? "" : "common",
+	       tp->align);
+	if ((tp->flags & INITF) == 0)
+		printf("\tz\t%lu\n}\n", tp->size);
 }
 
 void