Module Name: src Committed By: rillig Date: Sat Jul 16 22:36:06 UTC 2022
Modified Files: src/tests/usr.bin/xlint/lint1: msg_135.c src/usr.bin/xlint/lint1: err.c tree.c Log Message: lint: add more details to message about pointer alignment The previous message 'may cause alignment problem' was not detailed enough to be actionable, it didn't give the necessary insight to why lint was complaining at all. The new message 'increases alignment from 1 to 4' or 'from 2 to 8' describes the potentially problematic conversion, and together with the involved type names, it allows an informed decision about whether lint's warning is warranted or not. In a typical NetBSD build, this warning is in the top 10. The number of these warnings depends on the architecture, it is typically between 800 and 1600. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_135.c cvs rdiff -u -r1.181 -r1.182 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.474 -r1.475 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/msg_135.c diff -u src/tests/usr.bin/xlint/lint1/msg_135.c:1.10 src/tests/usr.bin/xlint/lint1/msg_135.c:1.11 --- src/tests/usr.bin/xlint/lint1/msg_135.c:1.10 Sat Jun 11 11:52:13 2022 +++ src/tests/usr.bin/xlint/lint1/msg_135.c Sat Jul 16 22:36:06 2022 @@ -1,7 +1,7 @@ -/* $NetBSD: msg_135.c,v 1.10 2022/06/11 11:52:13 rillig Exp $ */ +/* $NetBSD: msg_135.c,v 1.11 2022/07/16 22:36:06 rillig Exp $ */ # 3 "msg_135.c" -// Test for message: converting '%s' to '%s' may cause alignment problem [135] +// Test for message: converting '%s' to '%s' increases alignment from %u to %u [135] /* lint1-extra-flags: -h */ @@ -12,7 +12,7 @@ read_uint(const unsigned short **pp) { unsigned val; - /* expect+1: warning: converting 'pointer to const unsigned short' to 'pointer to const unsigned int' may cause alignment problem [135] */ + /* expect+1: warning: converting 'pointer to const unsigned short' to 'pointer to const unsigned int' increases alignment from 2 to 4 [135] */ val = *(const unsigned *)(*pp); pp += sizeof(unsigned); return val; Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.181 src/usr.bin/xlint/lint1/err.c:1.182 --- src/usr.bin/xlint/lint1/err.c:1.181 Tue Jul 5 22:50:41 2022 +++ src/usr.bin/xlint/lint1/err.c Sat Jul 16 22:36:06 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.181 2022/07/05 22:50:41 rillig Exp $ */ +/* $NetBSD: err.c,v 1.182 2022/07/16 22:36:06 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.181 2022/07/05 22:50:41 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.182 2022/07/16 22:36:06 rillig Exp $"); #endif #include <limits.h> @@ -190,7 +190,7 @@ static const char *const msgs[] = { "conversion from '%s' to '%s' may lose accuracy", /* 132 */ "conversion of pointer to '%s' loses bits", /* 133 */ "conversion of pointer to '%s' may lose bits", /* 134 */ - "converting '%s' to '%s' may cause alignment problem", /* 135 */ + "converting '%s' to '%s' increases alignment from %u to %u", /* 135 */ "cannot do pointer arithmetic on operand of unknown size", /* 136 */ "", /* unused */ /* 137 */ "unknown operand size, op '%s'", /* 138 */ Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.474 src/usr.bin/xlint/lint1/tree.c:1.475 --- src/usr.bin/xlint/lint1/tree.c:1.474 Fri Jul 8 21:19:07 2022 +++ src/usr.bin/xlint/lint1/tree.c Sat Jul 16 22:36:06 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.474 2022/07/08 21:19:07 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.475 2022/07/16 22:36:06 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.474 2022/07/08 21:19:07 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.475 2022/07/16 22:36:06 rillig Exp $"); #endif #include <float.h> @@ -2656,8 +2656,10 @@ convert_pointer_from_pointer(type_t *ntp if (hflag && alignment_in_bits(nstp) > alignment_in_bits(ostp) && ost != CHAR && ost != UCHAR && !is_incomplete(ostp)) { - /* converting '%s' to '%s' may cause alignment problem */ - warning(135, type_name(otp), type_name(ntp)); + /* converting '%s' to '%s' increases alignment ... */ + warning(135, type_name(otp), type_name(ntp), + alignment_in_bits(ostp) / CHAR_SIZE, + alignment_in_bits(nstp) / CHAR_SIZE); } if (cflag && should_warn_about_pointer_cast(nstp, nst, ostp, ost)) {