Module Name: src
Committed By: rillig
Date: Wed Aug 2 21:26:12 UTC 2023
Modified Files:
src/usr.bin/xlint/lint1: decl.c
Log Message:
lint: do not return bogus types for unnamed function parameters
Since decl.c 1.18 from 2000-07-05, lint has returned bogus type
information in cases where it couldn't interpret complicated
declarators.
In cases like these, rather fail than proceed with wrong data.
To generate a diff of this commit:
cvs rdiff -u -r1.375 -r1.376 src/usr.bin/xlint/lint1/decl.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.375 src/usr.bin/xlint/lint1/decl.c:1.376
--- src/usr.bin/xlint/lint1/decl.c:1.375 Wed Aug 2 21:11:35 2023
+++ src/usr.bin/xlint/lint1/decl.c Wed Aug 2 21:26:12 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.375 2023/08/02 21:11:35 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.376 2023/08/02 21:26:12 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.375 2023/08/02 21:11:35 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.376 2023/08/02 21:26:12 rillig Exp $");
#endif
#include <sys/param.h>
@@ -1203,12 +1203,10 @@ add_pointer(sym_t *decl, qual_ptr *p)
debug_dcs();
type_t **tpp = &decl->s_type;
- while (*tpp != NULL && *tpp != dcs->d_type)
+ lint_assert(*tpp != NULL);
+ while (*tpp != dcs->d_type) {
tpp = &(*tpp)->t_subt;
- if (*tpp == NULL) {
- debug_step("add_pointer: unchanged '%s'",
- type_name(decl->s_type));
- return decl;
+ lint_assert(*tpp != NULL);
}
while (p != NULL) {
@@ -1274,12 +1272,10 @@ add_array(sym_t *decl, bool dim, int n)
debug_dcs();
type_t **tpp = &decl->s_type;
- while (*tpp != NULL && *tpp != dcs->d_type)
+ lint_assert(*tpp != NULL);
+ while (*tpp != dcs->d_type) {
tpp = &(*tpp)->t_subt;
- if (*tpp == NULL) {
- debug_step("add_array: unchanged '%s'",
- type_name(decl->s_type));
- return decl;
+ lint_assert(*tpp != NULL);
}
*tpp = block_derive_array(dcs->d_type, dim, n);
@@ -1389,24 +1385,11 @@ add_function(sym_t *decl, struct paramet
debug_dcs_all();
}
- /*
- * XXX: What is this code doing on a semantic level, and why?
- * Returning decl leads to the wrong function types in msg_347.
- */
type_t **tpp = &decl->s_type;
- if (*tpp == NULL)
- decl->s_type = dcs->d_enclosing->d_type;
- while (*tpp != NULL && *tpp != dcs->d_enclosing->d_type)
- /*
- * XXX: accessing INT->t_subt feels strange, even though it
- * may even be guaranteed to be NULL.
- */
+ lint_assert(*tpp != NULL);
+ while (*tpp != dcs->d_enclosing->d_type) {
tpp = &(*tpp)->t_subt;
- if (*tpp == NULL) {
- debug_step("add_function: unchanged '%s'",
- type_name(decl->s_type));
- debug_leave();
- return decl; /* see msg_347 */
+ lint_assert(*tpp != NULL);
}
*tpp = block_derive_function(dcs->d_enclosing->d_type,