Module Name:    src
Committed By:   rillig
Date:           Fri Jun 24 21:22:11 UTC 2022

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

Log Message:
lint: do not warn about pointer casts to array types

If the (recursive) element type of the array is compatible, that's good
enough.  Even after the previous commits, this warning is the one that
occurs most in a standard NetBSD build, and it is generally ignored.
For now, focus on reducing the number of false positives to an
acceptable level.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/tests/usr.bin/xlint/lint1/msg_247.c
cvs rdiff -u -r1.462 -r1.463 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_247.c
diff -u src/tests/usr.bin/xlint/lint1/msg_247.c:1.25 src/tests/usr.bin/xlint/lint1/msg_247.c:1.26
--- src/tests/usr.bin/xlint/lint1/msg_247.c:1.25	Fri Jun 24 21:02:10 2022
+++ src/tests/usr.bin/xlint/lint1/msg_247.c	Fri Jun 24 21:22:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_247.c,v 1.25 2022/06/24 21:02:10 rillig Exp $	*/
+/*	$NetBSD: msg_247.c,v 1.26 2022/06/24 21:22:11 rillig Exp $	*/
 # 3 "msg_247.c"
 
 // Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
@@ -322,6 +322,13 @@ unnecessary_cast_from_array_to_pointer(i
 		/* expect+1: warning: illegal combination of 'pointer to double' and 'pointer to array[5] of double' [184] */
 		return storage_2d;
 
-	/* expect+1: warning: pointer cast from 'pointer to array[5] of double' to 'pointer to double' may be troublesome [247] */
+	/*
+	 * C11 6.3.2.1p3 says that an array is converted to a pointer to its
+	 * first element.  That paragraph doesn't say 'recursively', that
+	 * word is only used two paragraphs above, in 6.3.2.1p1.
+	 */
+	if (dim == -2)
+		return storage_2d[0];
+
 	return (double *)storage_2d;
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.462 src/usr.bin/xlint/lint1/tree.c:1.463
--- src/usr.bin/xlint/lint1/tree.c:1.462	Fri Jun 24 20:44:53 2022
+++ src/usr.bin/xlint/lint1/tree.c	Fri Jun 24 21:22:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.462 2022/06/24 20:44:53 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.463 2022/06/24 21:22:11 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.462 2022/06/24 20:44:53 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.463 2022/06/24 21:22:11 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2512,6 +2512,11 @@ should_warn_about_pointer_cast(const typ
 			       const type_t *ostp, tspec_t ost)
 {
 
+	while (nst == ARRAY)
+		nstp = nstp->t_subt, nst = nstp->t_tspec;
+	while (ost == ARRAY)
+		ostp = ostp->t_subt, ost = ostp->t_tspec;
+
 	if (nst == STRUCT && ost == STRUCT &&
 	    (struct_starts_with(nstp, ostp) ||
 	     struct_starts_with(ostp, nstp)))

Reply via email to