Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: add more details to message about ...
details: https://anonhg.NetBSD.org/src/rev/84fcb3be5a8b
branches: trunk
changeset: 368509:84fcb3be5a8b
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jul 16 22:36:06 2022 +0000
description:
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.
diffstat:
tests/usr.bin/xlint/lint1/msg_135.c | 6 +++---
usr.bin/xlint/lint1/err.c | 6 +++---
usr.bin/xlint/lint1/tree.c | 10 ++++++----
3 files changed, 12 insertions(+), 10 deletions(-)
diffs (80 lines):
diff -r a3cea49a65c7 -r 84fcb3be5a8b tests/usr.bin/xlint/lint1/msg_135.c
--- a/tests/usr.bin/xlint/lint1/msg_135.c Sat Jul 16 22:23:38 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_135.c Sat Jul 16 22:36:06 2022 +0000
@@ -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 @@
{
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;
diff -r a3cea49a65c7 -r 84fcb3be5a8b usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Jul 16 22:23:38 2022 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Jul 16 22:36:06 2022 +0000
@@ -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 @@
"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 */
diff -r a3cea49a65c7 -r 84fcb3be5a8b usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sat Jul 16 22:23:38 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sat Jul 16 22:36:06 2022 +0000
@@ -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 @@
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)) {
Home |
Main Index |
Thread Index |
Old Index