Module Name:    src
Committed By:   rillig
Date:           Mon May 22 17:53:27 UTC 2023

Modified Files:
        src/tests/usr.bin/xlint/lint1: emit.c emit.exp-ln
        src/usr.bin/xlint/lint1: decl.c init.c

Log Message:
lint: fix emitted type for arrays of unknown size


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/emit.c
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/emit.exp-ln
cvs rdiff -u -r1.312 -r1.313 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.241 -r1.242 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/emit.c
diff -u src/tests/usr.bin/xlint/lint1/emit.c:1.16 src/tests/usr.bin/xlint/lint1/emit.c:1.17
--- src/tests/usr.bin/xlint/lint1/emit.c:1.16	Mon May 22 11:51:46 2023
+++ src/tests/usr.bin/xlint/lint1/emit.c	Mon May 22 17:53:27 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: emit.c,v 1.16 2023/05/22 11:51:46 rillig Exp $	*/
+/*	$NetBSD: emit.c,v 1.17 2023/05/22 17:53:27 rillig Exp $	*/
 # 3 "emit.c"
 
 /*
@@ -309,10 +309,9 @@ struct compound_expression_in_initialize
 };
 
 /*
- * FIXME: The type that ends up in the .ln file is 'A0cC', which is wrong as it
- * has array size 0 instead of the correct 8.
- *
- * This is caused by cgram_declare being called before processing the
+ * Before decl.c 1.312 and init.c 1.242 from 2023-05-22, the type that ended up
+ * in the .ln file was 'A0cC', which was wrong as it had array size 0 instead
+ * of the correct 8.  That type had been taken too early, before looking at the
  * initializer.
  */
 const char array_of_unknown_size[] = "unknown";

Index: src/tests/usr.bin/xlint/lint1/emit.exp-ln
diff -u src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.11 src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.12
--- src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.11	Mon May 22 11:51:46 2023
+++ src/tests/usr.bin/xlint/lint1/emit.exp-ln	Mon May 22 17:53:27 2023
@@ -82,4 +82,4 @@ Semit.c
 289u0.289x16defined_used_var
 286d0.286d8use_varsF0V
 305d0.305d8compoundsT134compound_expression_in_initializer
-318d0.318d21array_of_unknown_sizeA0cC
+317d0.317d21array_of_unknown_sizeA8cC

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.312 src/usr.bin/xlint/lint1/decl.c:1.313
--- src/usr.bin/xlint/lint1/decl.c:1.312	Mon May 22 17:47:27 2023
+++ src/usr.bin/xlint/lint1/decl.c	Mon May 22 17:53:27 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.312 2023/05/22 17:47:27 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.313 2023/05/22 17:53:27 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.312 2023/05/22 17:47:27 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.313 2023/05/22 17:53:27 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1992,7 +1992,8 @@ declare_extern(sym_t *dsym, bool has_ini
 		 */
 		bool rval = dsym->s_type->t_subt->t_tspec != VOID;
 		outfdef(dsym, &dsym->s_def_pos, rval, false, NULL);
-	} else if (!is_compiler_builtin(dsym->s_name)) {
+	} else if (!is_compiler_builtin(dsym->s_name)
+	    && !(has_initializer && dsym->s_type->t_incomplete_array)) {
 		outsym(dsym, dsym->s_scl, dsym->s_def);
 	}
 

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.241 src/usr.bin/xlint/lint1/init.c:1.242
--- src/usr.bin/xlint/lint1/init.c:1.241	Sat Apr 22 17:49:15 2023
+++ src/usr.bin/xlint/lint1/init.c	Mon May 22 17:53:27 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.241 2023/04/22 17:49:15 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.242 2023/05/22 17:53:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.241 2023/04/22 17:49:15 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.242 2023/05/22 17:53:27 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -252,6 +252,7 @@ update_type_of_array_of_unknown_size(sym
 	tp->t_incomplete_array = false;
 	sym->s_type = tp;
 	debug_step("completed array type is '%s'", type_name(sym->s_type));
+	outsym(sym, sym->s_scl, sym->s_def);
 }
 
 

Reply via email to