Module Name: src Committed By: rillig Date: Mon Feb 24 19:56:27 UTC 2025
Modified Files: src/tests/usr.bin/xlint/lint1: c11.c msg_127.c msg_153.c src/usr.bin/xlint/lint1: err.c tree.c Log Message: lint: remove no-op variant of the unary '&' operator Neither K&R 1978 nor any of the C standards mentions that &function or &array would be a no-op. This no-op behavior produced wrong warnings in sbin/gpt. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/c11.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_127.c cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_153.c cvs rdiff -u -r1.264 -r1.265 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.672 -r1.673 src/usr.bin/xlint/lint1/tree.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/c11.c diff -u src/tests/usr.bin/xlint/lint1/c11.c:1.8 src/tests/usr.bin/xlint/lint1/c11.c:1.9 --- src/tests/usr.bin/xlint/lint1/c11.c:1.8 Sat Nov 30 11:27:20 2024 +++ src/tests/usr.bin/xlint/lint1/c11.c Mon Feb 24 19:56:27 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: c11.c,v 1.8 2024/11/30 11:27:20 rillig Exp $ */ +/* $NetBSD: c11.c,v 1.9 2025/02/24 19:56:27 rillig Exp $ */ # 3 "c11.c" /* @@ -122,7 +122,7 @@ void fvla(int m, int C[m][m]) int (*s)[m]; /* expect+1: warning: nested 'extern' declaration of 'r' [352] */ extern int (*r)[m]; - /* expect+1: warning: illegal combination of 'pointer to array[1] of int' and 'pointer to int', op 'init' [124] */ + /* expect+1: warning: illegal combination of 'pointer to array[1] of int' and 'pointer to array[100] of int', op 'init' [124] */ static int (*q)[m] = &B; } Index: src/tests/usr.bin/xlint/lint1/msg_127.c diff -u src/tests/usr.bin/xlint/lint1/msg_127.c:1.4 src/tests/usr.bin/xlint/lint1/msg_127.c:1.5 --- src/tests/usr.bin/xlint/lint1/msg_127.c:1.4 Thu Jun 16 16:58:36 2022 +++ src/tests/usr.bin/xlint/lint1/msg_127.c Mon Feb 24 19:56:27 2025 @@ -1,14 +1,17 @@ -/* $NetBSD: msg_127.c,v 1.4 2022/06/16 16:58:36 rillig Exp $ */ +/* $NetBSD: msg_127.c,v 1.5 2025/02/24 19:56:27 rillig Exp $ */ # 3 "msg_127.c" /* Test for message: '&' before array or function: ignored [127] */ +/* + * This message is no longer used, as it contradicts all C standards and is + * not mentioned in K&R 1978 either. + */ /* lint1-extra-flags: -t */ void example() { - /* expect+1: warning: '&' before array or function: ignored [127] */ if (&example != (void *)0) return; } Index: src/tests/usr.bin/xlint/lint1/msg_153.c diff -u src/tests/usr.bin/xlint/lint1/msg_153.c:1.10 src/tests/usr.bin/xlint/lint1/msg_153.c:1.11 --- src/tests/usr.bin/xlint/lint1/msg_153.c:1.10 Mon Feb 24 19:49:00 2025 +++ src/tests/usr.bin/xlint/lint1/msg_153.c Mon Feb 24 19:56:27 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_153.c,v 1.10 2025/02/24 19:49:00 rillig Exp $ */ +/* $NetBSD: msg_153.c,v 1.11 2025/02/24 19:56:27 rillig Exp $ */ # 3 "msg_153.c" // Test for message: converting '%s' to incompatible '%s' for argument %d [153] @@ -44,7 +44,5 @@ qualifiers(char *ptr, const volatile cha void pass_pointer_to_array(void) { - // FIXME: Must be a pointer to 16 bytes, not to 1 byte. - /* expect+1: warning: converting 'pointer to unsigned char' to incompatible 'pointer to array[16] of unsigned char' for argument 1 [153] */ take_pointer_to_sixteen_bytes(&bytes); } Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.264 src/usr.bin/xlint/lint1/err.c:1.265 --- src/usr.bin/xlint/lint1/err.c:1.264 Thu Feb 20 21:53:28 2025 +++ src/usr.bin/xlint/lint1/err.c Mon Feb 24 19:56:27 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.264 2025/02/20 21:53:28 rillig Exp $ */ +/* $NetBSD: err.c,v 1.265 2025/02/24 19:56:27 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: err.c,v 1.264 2025/02/20 21:53:28 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.265 2025/02/24 19:56:27 rillig Exp $"); #endif #include <limits.h> @@ -182,7 +182,7 @@ static const char *const msgs[] = { "illegal combination of '%s' and '%s', op '%s'", // 124 "pointers to functions can only be compared for equality", // 125 "incompatible types '%s' and '%s' in conditional", // 126 - "'&' before array or function: ignored", // 127 + "", /* no longer used */ // 127 "operator '%s' discards '%s' from '%s'", // 128 "expression has null effect", // 129 "enum type mismatch: '%s' '%s' '%s'", // 130 Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.672 src/usr.bin/xlint/lint1/tree.c:1.673 --- src/usr.bin/xlint/lint1/tree.c:1.672 Thu Feb 20 21:53:28 2025 +++ src/usr.bin/xlint/lint1/tree.c Mon Feb 24 19:56:27 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.672 2025/02/20 21:53:28 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.673 2025/02/24 19:56:27 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.672 2025/02/20 21:53:28 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.673 2025/02/24 19:56:27 rillig Exp $"); #endif #include <float.h> @@ -1034,17 +1034,8 @@ balance(op_t op, tnode_t **lnp, tnode_t } static tnode_t * -build_address(bool sys, tnode_t *tn, bool force) +build_address(bool sys, tnode_t *tn) { - tspec_t t; - - if (!force && ((t = tn->tn_type->t_tspec) == ARRAY || t == FUNC)) { - if (!allow_c90) - /* '&' before array or function: ignored */ - warning(127); - return tn; - } - /* eliminate '&*' */ if (tn->tn_op == INDIR && tn->u.ops.left->tn_type->t_tspec == PTR && @@ -1295,7 +1286,7 @@ build_struct_access(op_t op, bool sys, t bool lvalue = op == ARROW || ln->tn_lvalue; if (op == POINT) - ln = build_address(sys, ln, true); + ln = build_address(sys, ln); else if (ln->tn_type->t_tspec != PTR) { lint_assert(!allow_c90); lint_assert(is_integer(ln->tn_type->t_tspec)); @@ -2057,7 +2048,7 @@ build_binary(tnode_t *ln, op_t op, bool ntn = build_prepost_incdec(op, sys, ln); break; case ADDR: - ntn = build_address(sys, ln, false); + ntn = build_address(sys, ln); break; case INDIR: ntn = build_op(INDIR, sys, ln->tn_type->t_subt, ln, NULL); @@ -2357,7 +2348,7 @@ cconv(tnode_t *tn) } if (tn->tn_type->t_tspec == FUNC) - tn = build_address(tn->tn_sys, tn, true); + tn = build_address(tn->tn_sys, tn); if (tn->tn_lvalue) { type_t *tp = expr_dup_type(tn->tn_type);