Module Name: src Committed By: rillig Date: Sun Feb 28 01:06:57 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_153.c msg_153.exp msg_229.c msg_229.exp src/usr.bin/xlint/lint1: err.c tree.c Log Message: lint: make messages for incompatible pointers more specific Message 153 didn't state obviously which of the pointer types was the one before conversion (or cast) and which was the resulting type. Message 229 didn't have any type information at all. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_153.c \ src/tests/usr.bin/xlint/lint1/msg_229.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_153.exp \ src/tests/usr.bin/xlint/lint1/msg_229.exp cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.222 -r1.223 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_153.c diff -u src/tests/usr.bin/xlint/lint1/msg_153.c:1.3 src/tests/usr.bin/xlint/lint1/msg_153.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_153.c:1.3 Sun Feb 28 00:52:16 2021 +++ src/tests/usr.bin/xlint/lint1/msg_153.c Sun Feb 28 01:06:57 2021 @@ -1,15 +1,22 @@ -/* $NetBSD: msg_153.c,v 1.3 2021/02/28 00:52:16 rillig Exp $ */ +/* $NetBSD: msg_153.c,v 1.4 2021/02/28 01:06:57 rillig Exp $ */ # 3 "msg_153.c" -// Test for message: argument has incompatible pointer type, arg #%d (%s != %s) [153] +// Test for message: converting '%s' to incompatible '%s' for argument %d [153] typedef double (*unary_operator)(double); -void sink_unary_operator(unary_operator); +void sink_function_pointer(unary_operator); +void sink_int_pointer(int *); void -example(int x) +to_function_pointer(int *x) { - sink_unary_operator(&x); + sink_function_pointer(x); +} + +void +to_int_pointer(unary_operator op) +{ + sink_int_pointer(op); } Index: src/tests/usr.bin/xlint/lint1/msg_229.c diff -u src/tests/usr.bin/xlint/lint1/msg_229.c:1.3 src/tests/usr.bin/xlint/lint1/msg_229.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_229.c:1.3 Sun Feb 28 00:52:16 2021 +++ src/tests/usr.bin/xlint/lint1/msg_229.c Sun Feb 28 01:06:57 2021 @@ -1,12 +1,18 @@ -/* $NetBSD: msg_229.c,v 1.3 2021/02/28 00:52:16 rillig Exp $ */ +/* $NetBSD: msg_229.c,v 1.4 2021/02/28 01:06:57 rillig Exp $ */ # 3 "msg_229.c" -// Test for message: questionable conversion of function pointer [229] +// Test for message: converting '%s' to '%s' is questionable [229] typedef double (*unary_operator)(double); int * -example(unary_operator op) +to_int_pointer(unary_operator op) { return (int *)op; } + +unary_operator +to_function_pointer(int *p) +{ + return (unary_operator)p; +} Index: src/tests/usr.bin/xlint/lint1/msg_153.exp diff -u src/tests/usr.bin/xlint/lint1/msg_153.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_153.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_153.exp:1.2 Sun Feb 28 00:52:16 2021 +++ src/tests/usr.bin/xlint/lint1/msg_153.exp Sun Feb 28 01:06:57 2021 @@ -1 +1,2 @@ -msg_153.c(14): warning: argument has incompatible pointer type, arg #1 (pointer to function(double) returning double != pointer to int) [153] +msg_153.c(15): warning: converting 'pointer to int' to incompatible 'pointer to function(double) returning double' for argument 1 [153] +msg_153.c(21): warning: converting 'pointer to function(double) returning double' to incompatible 'pointer to int' for argument 1 [153] Index: src/tests/usr.bin/xlint/lint1/msg_229.exp diff -u src/tests/usr.bin/xlint/lint1/msg_229.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_229.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_229.exp:1.2 Sun Feb 28 00:52:16 2021 +++ src/tests/usr.bin/xlint/lint1/msg_229.exp Sun Feb 28 01:06:57 2021 @@ -1 +1,2 @@ -msg_229.c(11): warning: questionable conversion of function pointer [229] +msg_229.c(11): warning: converting 'pointer to function(double) returning double' to 'pointer to int' is questionable [229] +msg_229.c(17): warning: converting 'pointer to int' to 'pointer to function(double) returning double' is questionable [229] Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.82 src/usr.bin/xlint/lint1/err.c:1.83 --- src/usr.bin/xlint/lint1/err.c:1.82 Sun Feb 28 00:40:22 2021 +++ src/usr.bin/xlint/lint1/err.c Sun Feb 28 01:06:57 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.82 2021/02/28 00:40:22 rillig Exp $ */ +/* $NetBSD: err.c,v 1.83 2021/02/28 01:06:57 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: err.c,v 1.82 2021/02/28 00:40:22 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.83 2021/02/28 01:06:57 rillig Exp $"); #endif #include <sys/types.h> @@ -212,7 +212,7 @@ const char *msgs[] = { "argument mismatch: %d arg%s passed, %d expected", /* 150 */ "void expressions may not be arguments, arg #%d", /* 151 */ "argument cannot have unknown size, arg #%d", /* 152 */ - "argument has incompatible pointer type, arg #%d (%s != %s)", /* 153 */ + "converting '%s' to incompatible '%s' for argument %d", /* 153 */ "illegal combination of %s (%s) and %s (%s), arg #%d", /* 154 */ "argument is incompatible with prototype, arg #%d", /* 155 */ "enum type mismatch, arg #%d (%s != %s)", /* 156 */ @@ -288,7 +288,7 @@ const char *msgs[] = { "static variable %s unused", /* 226 */ "const object %s should have initializer", /* 227 */ "function cannot return const or volatile object", /* 228 */ - "questionable conversion of function pointer", /* 229 */ + "converting '%s' to '%s' is questionable", /* 229 */ "nonportable character comparison, op %s", /* 230 */ "argument %s unused in function %s", /* 231 */ "label %s unused in function %s", /* 232 */ Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.222 src/usr.bin/xlint/lint1/tree.c:1.223 --- src/usr.bin/xlint/lint1/tree.c:1.222 Sun Feb 28 00:40:22 2021 +++ src/usr.bin/xlint/lint1/tree.c Sun Feb 28 01:06:57 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.222 2021/02/28 00:40:22 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.223 2021/02/28 01:06:57 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: tree.c,v 1.222 2021/02/28 00:40:22 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.223 2021/02/28 01:06:57 rillig Exp $"); #endif #include <float.h> @@ -1597,9 +1597,9 @@ check_assign_types_compatible(op_t op, i warning(182, type_name(lstp), type_name(rstp)); break; case FARG: - /* argument has incompatible pointer type... */ + /* converting '%s' to incompatible '%s' ... */ warning(153, - arg, type_name(lstp), type_name(rstp)); + type_name(rtp), type_name(ltp), arg); break; default: /* operands have incompatible pointer type... */ @@ -1642,8 +1642,8 @@ check_assign_types_compatible(op_t op, i warn_incompatible_pointers(NULL, ltp, rtp); break; case FARG: - /* arg. has incomp. pointer type, arg #%d (%s != %s) */ - warning(153, arg, type_name(ltp), type_name(rtp)); + /* converting '%s' to incompatible '%s' for ... */ + warning(153, type_name(rtp), type_name(ltp), arg); break; default: warn_incompatible_pointers(mp, ltp, rtp); @@ -2238,8 +2238,8 @@ check_pointer_conversion(op_t op, tnode_ } else if (nt == FUNC && ot == FUNC) { return; } else if (nt == FUNC || ot == FUNC) { - /* questionable conversion of function pointer */ - warning(229); + /* converting '%s' to '%s' is questionable */ + warning(229, type_name(tn->tn_type), type_name(tp)); return; }