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: in C99 mode, do not warn about non...



details:   https://anonhg.NetBSD.org/src/rev/e7b7e823c8a5
branches:  trunk
changeset: 365234:e7b7e823c8a5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Apr 15 21:50:07 2022 +0000

description:
lint: in C99 mode, do not warn about non-prototype conversions

Message 259 is "argument #%d is converted from '%s' to '%s' due to
prototype", and it is intended to warn about compatibility between
traditional C where functions had no prototypes and standard C where
functions have prototypes.

Running lint in C99 mode is further away from traditional C than running
lint in C90 mode, so that warning doesn't make sense for C99.  There are
still some inconsistencies in the 5 language version modes that lint
offers:

        -t              for traditional C
        (no option)     for migrating traditional C to C90
        -s              for C90 code
        -S              for C99 code
        -Ac11           for C11 code

By disabling warning 259 in C99 mode, a typical NetBSD build produces
14.500 fewer warnings than before, of about 100.000 total.

Message 259 overlaps with message 298 "conversion from '%s' to '%s' may
lose accuracy, arg #%d", and in some cases of potentially lossy
conversions, lint now produces none of these messages.  In some other
cases, these warnings were reported redundantly.  The cases where
message 298 makes sense will be added back later, as needed.

diffstat:

 tests/usr.bin/xlint/lint1/d_constant_conv2.c   |  11 ++-
 tests/usr.bin/xlint/lint1/d_constant_conv2.exp |   2 +-
 tests/usr.bin/xlint/lint1/d_type_conv1.c       |  11 ++-
 tests/usr.bin/xlint/lint1/d_type_conv1.exp     |   2 +-
 tests/usr.bin/xlint/lint1/d_type_conv2.c       |  11 ++-
 tests/usr.bin/xlint/lint1/d_type_conv2.exp     |   2 +-
 tests/usr.bin/xlint/lint1/d_type_conv3.c       |  11 ++-
 tests/usr.bin/xlint/lint1/d_type_conv3.exp     |   4 +-
 tests/usr.bin/xlint/lint1/expr_fold.c          |  27 +-------
 tests/usr.bin/xlint/lint1/expr_fold.exp        |  85 ++++++++++---------------
 tests/usr.bin/xlint/lint1/msg_259.c            |   4 +-
 tests/usr.bin/xlint/lint1/msg_259_ilp32.c      |   4 +-
 usr.bin/xlint/lint1/tree.c                     |   7 +-
 13 files changed, 85 insertions(+), 96 deletions(-)

diffs (truncated from 392 to 300 lines):

diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/d_constant_conv2.c
--- a/tests/usr.bin/xlint/lint1/d_constant_conv2.c      Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_constant_conv2.c      Fri Apr 15 21:50:07 2022 +0000
@@ -1,12 +1,19 @@
-/*     $NetBSD: d_constant_conv2.c,v 1.4 2022/01/15 14:22:03 rillig Exp $      */
+/*     $NetBSD: d_constant_conv2.c,v 1.5 2022/04/15 21:50:07 rillig Exp $      */
 # 3 "d_constant_conv2.c"
 
 /* Flag information-losing constant conversion in argument lists */
 
+/*
+ * Before tree.c 1.427 from 2022-04-15, lint warned about conversions due to
+ * prototype even in C99 mode, which is far away from traditional C to make
+ * non-prototype functions an issue.
+ */
+/* lint1-flags: -h -w */
+
 int f(unsigned int);
 
 void
-should_fail()
+should_fail(void)
 {
        /* expect+1: warning: argument #1 is converted from 'double' to 'unsigned int' due to prototype [259] */
        f(2.1);
diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/d_constant_conv2.exp
--- a/tests/usr.bin/xlint/lint1/d_constant_conv2.exp    Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_constant_conv2.exp    Fri Apr 15 21:50:07 2022 +0000
@@ -1,1 +1,1 @@
-d_constant_conv2.c(12): warning: argument #1 is converted from 'double' to 'unsigned int' due to prototype [259]
+d_constant_conv2.c(19): warning: argument #1 is converted from 'double' to 'unsigned int' due to prototype [259]
diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/d_type_conv1.c
--- a/tests/usr.bin/xlint/lint1/d_type_conv1.c  Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_type_conv1.c  Fri Apr 15 21:50:07 2022 +0000
@@ -1,12 +1,19 @@
-/*     $NetBSD: d_type_conv1.c,v 1.4 2022/01/15 14:22:03 rillig Exp $  */
+/*     $NetBSD: d_type_conv1.c,v 1.5 2022/04/15 21:50:07 rillig Exp $  */
 # 3 "d_type_conv1.c"
 
 /* Flag information-losing type conversion in argument lists */
 
+/*
+ * Before tree.c 1.427 from 2022-04-15, lint warned about conversions due to
+ * prototype even in C99 mode, which is far away from traditional C to make
+ * non-prototype functions an issue.
+ */
+/* lint1-flags: -g -h -w */
+
 int f(unsigned int);
 
 void
-should_fail()
+should_fail(void)
 {
        long long x = 20;
 
diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/d_type_conv1.exp
--- a/tests/usr.bin/xlint/lint1/d_type_conv1.exp        Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_type_conv1.exp        Fri Apr 15 21:50:07 2022 +0000
@@ -1,1 +1,1 @@
-d_type_conv1.c(14): warning: argument #1 is converted from 'long long' to 'unsigned int' due to prototype [259]
+d_type_conv1.c(21): warning: argument #1 is converted from 'long long' to 'unsigned int' due to prototype [259]
diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/d_type_conv2.c
--- a/tests/usr.bin/xlint/lint1/d_type_conv2.c  Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_type_conv2.c  Fri Apr 15 21:50:07 2022 +0000
@@ -1,12 +1,19 @@
-/*     $NetBSD: d_type_conv2.c,v 1.4 2022/01/15 14:22:03 rillig Exp $  */
+/*     $NetBSD: d_type_conv2.c,v 1.5 2022/04/15 21:50:07 rillig Exp $  */
 # 3 "d_type_conv2.c"
 
 /* Flag information-losing type conversion in argument lists */
 
+/*
+ * Before tree.c 1.427 from 2022-04-15, lint warned about conversions due to
+ * prototype even in C99 mode, which is far away from traditional C to make
+ * non-prototype functions an issue.
+ */
+/* lint1-flags: -h -w */
+
 int f(float);
 
 void
-should_fail()
+should_fail(void)
 {
        double x = 2.0;
 
diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/d_type_conv2.exp
--- a/tests/usr.bin/xlint/lint1/d_type_conv2.exp        Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_type_conv2.exp        Fri Apr 15 21:50:07 2022 +0000
@@ -1,1 +1,1 @@
-d_type_conv2.c(14): warning: argument #1 is converted from 'double' to 'float' due to prototype [259]
+d_type_conv2.c(21): warning: argument #1 is converted from 'double' to 'float' due to prototype [259]
diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/d_type_conv3.c
--- a/tests/usr.bin/xlint/lint1/d_type_conv3.c  Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_type_conv3.c  Fri Apr 15 21:50:07 2022 +0000
@@ -1,12 +1,19 @@
-/*     $NetBSD: d_type_conv3.c,v 1.5 2022/01/15 14:22:03 rillig Exp $  */
+/*     $NetBSD: d_type_conv3.c,v 1.6 2022/04/15 21:50:07 rillig Exp $  */
 # 3 "d_type_conv3.c"
 
 /* Flag information-losing type conversion in argument lists */
 
+/*
+ * Before tree.c 1.427 from 2022-04-15, lint warned about conversions due to
+ * prototype even in C99 mode, which is far away from traditional C to make
+ * non-prototype functions an issue.
+ */
+/* lint1-flags: -g -h -w */
+
 int f(unsigned int);
 
 void
-should_fail()
+should_fail(void)
 {
 
        /* expect+2: warning: argument #1 is converted from 'long long' to 'unsigned int' due to prototype [259] */
diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/d_type_conv3.exp
--- a/tests/usr.bin/xlint/lint1/d_type_conv3.exp        Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_type_conv3.exp        Fri Apr 15 21:50:07 2022 +0000
@@ -1,2 +1,2 @@
-d_type_conv3.c(14): warning: argument #1 is converted from 'long long' to 'unsigned int' due to prototype [259]
-d_type_conv3.c(14): warning: conversion of 'long long' to 'unsigned int' is out of range, arg #1 [295]
+d_type_conv3.c(21): warning: argument #1 is converted from 'long long' to 'unsigned int' due to prototype [259]
+d_type_conv3.c(21): warning: conversion of 'long long' to 'unsigned int' is out of range, arg #1 [295]
diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/expr_fold.c
--- a/tests/usr.bin/xlint/lint1/expr_fold.c     Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_fold.c     Fri Apr 15 21:50:07 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expr_fold.c,v 1.5 2021/08/23 06:50:01 rillig Exp $     */
+/*     $NetBSD: expr_fold.c,v 1.6 2022/04/15 21:50:07 rillig Exp $     */
 # 3 "expr_fold.c"
 
 /*
@@ -29,20 +29,14 @@
 {
        take_int(+(0));
        take_int(+(2147483647));
-       /* XXX: one of these two messages is redundant */
-       /* expect+2: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        /* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
        take_int(+(2147483648));
-       /* XXX: one of these two messages is redundant */
-       /* expect+2: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        /* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
        take_int(+(4294967295));
 
        take_uint(+(0));
        take_uint(+(2147483647));
-       /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */
        take_uint(+(2147483648));
-       /* expect+1: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */
        take_uint(+(4294967295));
 
        /*
@@ -60,11 +54,9 @@
        take_int(-(0));
        take_int(-(2147483647));
 
-       /* expect+1: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        take_int(-(2147483648));
 
        /* The '-' is an operator, it is not part of the integer constant. */
-       /* expect+1: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        take_int(-2147483648);
 
        /* expect+2: warning: integer overflow detected, op '+' [141] */
@@ -72,18 +64,14 @@
        take_int(-(2147483647 + 1));
        /* expect+1: warning: integer overflow detected, op '-' [141] */
        take_int(-(-2147483647 - 1));
-       /* expect+2: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        /* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
        take_int(-(4294967295));
 
        take_uint(-(0));
-       /* expect+2: warning: conversion of negative constant to unsigned type, arg #1 [296] */
-       /* expect+1: warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259] */
+       /* expect+1: warning: conversion of negative constant to unsigned type, arg #1 [296] */
        take_uint(-(2147483647));
-       /* expect+2: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */
        /* expect+1: warning: conversion of negative constant to unsigned type, arg #1 [296] */
        take_uint(-(2147483648));
-       /* expect+2: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */
        /* expect+1: warning: conversion of negative constant to unsigned type, arg #1 [296] */
        take_uint(-(4294967295));
 }
@@ -93,23 +81,17 @@
 {
        take_int(~(0));
        take_int(~(2147483647));
-       /* expect+2: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        /* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
        take_int(~(2147483648));
-       /* expect+2: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        /* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
        take_int(~(4294967295));
 
-       /* expect+2: warning: conversion of negative constant to unsigned type, arg #1 [296] */
-       /* expect+1: warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259] */
+       /* expect+1: warning: conversion of negative constant to unsigned type, arg #1 [296] */
        take_uint(~(0));
-       /* expect+2: warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259] */
        /* expect+1: warning: conversion of negative constant to unsigned type, arg #1 [296] */
        take_uint(~(2147483647));
-       /* expect+2: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */
        /* expect+1: warning: conversion of negative constant to unsigned type, arg #1 [296] */
        take_uint(~(2147483648));
-       /* expect+2: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */
        /* expect+1: warning: conversion of negative constant to unsigned type, arg #1 [296] */
        take_uint(~(4294967295));
 }
@@ -137,7 +119,6 @@
        /* expect+1: warning: integer overflow detected, op '/' [141] */
        take_int(0 / 0);
 
-       /* expect+2: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        /* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
        take_int(-2147483648 / -1);
 }
@@ -154,7 +135,6 @@
        /* expect+1: error: modulus by 0 [140] */
        take_int(0U % 0U);
 
-       /* expect+1: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        take_int(-2147483648 % -1);
 }
 
@@ -191,7 +171,6 @@
        /* expect+1: warning: integer overflow detected, op '-' [141] */
        take_int(-2147483647 - 2);
 
-       /* expect+1: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
        take_int(0 - 2147483648);
        /* expect+1: warning: integer overflow detected, op '-' [141] */
        take_uint(0 - 2147483648U);
diff -r 411750ab2b90 -r e7b7e823c8a5 tests/usr.bin/xlint/lint1/expr_fold.exp
--- a/tests/usr.bin/xlint/lint1/expr_fold.exp   Fri Apr 15 17:53:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_fold.exp   Fri Apr 15 21:50:07 2022 +0000
@@ -1,53 +1,34 @@
-expr_fold.c(35): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
+expr_fold.c(33): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
 expr_fold.c(35): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
-expr_fold.c(39): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-expr_fold.c(39): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
-expr_fold.c(44): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
-expr_fold.c(46): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
-expr_fold.c(64): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-expr_fold.c(68): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-expr_fold.c(72): warning: integer overflow detected, op '+' [141]
-expr_fold.c(72): warning: integer overflow detected, op '-' [141]
-expr_fold.c(74): warning: integer overflow detected, op '-' [141]
-expr_fold.c(77): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-expr_fold.c(77): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
-expr_fold.c(82): warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259]
-expr_fold.c(82): warning: conversion of negative constant to unsigned type, arg #1 [296]
-expr_fold.c(85): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
-expr_fold.c(85): warning: conversion of negative constant to unsigned type, arg #1 [296]
-expr_fold.c(88): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
-expr_fold.c(88): warning: conversion of negative constant to unsigned type, arg #1 [296]
-expr_fold.c(98): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-expr_fold.c(98): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
-expr_fold.c(101): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-expr_fold.c(101): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
-expr_fold.c(105): warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259]
-expr_fold.c(105): warning: conversion of negative constant to unsigned type, arg #1 [296]
-expr_fold.c(108): warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259]
-expr_fold.c(108): warning: conversion of negative constant to unsigned type, arg #1 [296]
-expr_fold.c(111): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
-expr_fold.c(111): warning: conversion of negative constant to unsigned type, arg #1 [296]
-expr_fold.c(114): warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259]
-expr_fold.c(114): warning: conversion of negative constant to unsigned type, arg #1 [296]
-expr_fold.c(122): warning: integer overflow detected, op '*' [141]
-expr_fold.c(124): warning: integer overflow detected, op '*' [141]
-expr_fold.c(129): warning: integer overflow detected, op '*' [141]
-expr_fold.c(138): error: division by 0 [139]
-expr_fold.c(138): warning: integer overflow detected, op '/' [141]
-expr_fold.c(142): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-expr_fold.c(142): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
-expr_fold.c(149): error: modulus by 0 [140]
-expr_fold.c(151): error: modulus by 0 [140]
-expr_fold.c(153): error: modulus by 0 [140]
-expr_fold.c(155): error: modulus by 0 [140]
-expr_fold.c(158): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-expr_fold.c(165): warning: integer overflow detected, op '+' [141]
-expr_fold.c(171): warning: integer overflow detected, op '+' [141]
-expr_fold.c(188): warning: integer overflow detected, op '-' [141]
-expr_fold.c(192): warning: integer overflow detected, op '-' [141]
-expr_fold.c(195): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-expr_fold.c(197): warning: integer overflow detected, op '-' [141]
-expr_fold.c(204): warning: integer overflow detected, op '<<' [141]
-expr_fold.c(207): warning: integer overflow detected, op '<<' [141]
-expr_fold.c(211): warning: shift amount 104 is greater than bit-size 32 of 'unsigned int' [122]
-expr_fold.c(223): warning: shift amount 104 is greater than bit-size 32 of 'int' [122]
+expr_fold.c(64): warning: integer overflow detected, op '+' [141]
+expr_fold.c(64): warning: integer overflow detected, op '-' [141]
+expr_fold.c(66): warning: integer overflow detected, op '-' [141]
+expr_fold.c(68): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
+expr_fold.c(72): warning: conversion of negative constant to unsigned type, arg #1 [296]



Home | Main Index | Thread Index | Old Index