Module Name:    src
Committed By:   rillig
Date:           Fri Mar 21 20:37:31 UTC 2025

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_135.c
        src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: don't warn when a cast increases the alignment from 1 to n


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/msg_135.c
cvs rdiff -u -r1.676 -r1.677 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.16 src/tests/usr.bin/xlint/lint1/msg_135.c:1.17
--- src/tests/usr.bin/xlint/lint1/msg_135.c:1.16	Fri Mar 21 20:33:47 2025
+++ src/tests/usr.bin/xlint/lint1/msg_135.c	Fri Mar 21 20:37:31 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_135.c,v 1.16 2025/03/21 20:33:47 rillig Exp $	*/
+/*	$NetBSD: msg_135.c,v 1.17 2025/03/21 20:37:31 rillig Exp $	*/
 # 3 "msg_135.c"
 
 // Test for message: converting '%s' to '%s' increases alignment from %u to %u [135]
@@ -108,6 +108,11 @@ cast_to_union(void)
 	return both->p_align_8;
 }
 
+/*
+ * Structures with alignment 1 typically contain padding arrays only, so don't
+ * warn when they are converted to their structured counterparts.  An example
+ * of such a conversion is from 'struct sockaddr' to 'struct sockaddr_in6'.
+ */
 void
 from_alignment_1_to_8(void)
 {
@@ -122,8 +127,6 @@ from_alignment_1_to_8(void)
 	static struct alignment_1 *pointer_1;
 	static struct alignment_8 *pointer_8;
 
-	// FIXME: Don't warn when the old alignment is 1.
-	/* expect+1: warning: converting 'pointer to struct alignment_1' to 'pointer to struct alignment_8' increases alignment from 1 to 8 [135] */
 	pointer_8 = (struct alignment_8 *)pointer_1;
 	pointer_1 = (struct alignment_1 *)pointer_8;
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.676 src/usr.bin/xlint/lint1/tree.c:1.677
--- src/usr.bin/xlint/lint1/tree.c:1.676	Tue Mar 11 22:12:35 2025
+++ src/usr.bin/xlint/lint1/tree.c	Fri Mar 21 20:37:31 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.676 2025/03/11 22:12:35 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.677 2025/03/21 20:37:31 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.676 2025/03/11 22:12:35 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.677 2025/03/21 20:37:31 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3868,8 +3868,7 @@ convert_pointer_from_pointer(type_t *ntp
 	}
 
 	if (hflag && alignment(nstp) > alignment(ostp) &&
-	    ost != CHAR && ost != UCHAR &&
-	    !is_incomplete(ostp) &&
+	    !is_incomplete(ostp) && alignment(ostp) > 1 &&
 	    !(nst == UNION && union_contains(nstp, ostp))) {
 		/* converting '%s' to '%s' increases alignment ... */
 		warning(135, type_name(otp), type_name(ntp),

Reply via email to