Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: add test case for inte...



details:   https://anonhg.NetBSD.org/src/rev/2887872126fe
branches:  trunk
changeset: 365711:2887872126fe
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Apr 19 22:40:13 2022 +0000

description:
tests/lint: add test case for integer non-constant expression

Seen in sqlite3.c.

diffstat:

 tests/usr.bin/xlint/lint1/msg_132.c   |  17 ++++++++++++++++-
 tests/usr.bin/xlint/lint1/msg_132.exp |   1 +
 2 files changed, 17 insertions(+), 1 deletions(-)

diffs (36 lines):

diff -r 390d4369385b -r 2887872126fe tests/usr.bin/xlint/lint1/msg_132.c
--- a/tests/usr.bin/xlint/lint1/msg_132.c       Tue Apr 19 22:26:57 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.c       Tue Apr 19 22:40:13 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_132.c,v 1.6 2021/08/25 22:04:52 rillig Exp $       */
+/*     $NetBSD: msg_132.c,v 1.7 2022/04/19 22:40:13 rillig Exp $       */
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -85,3 +85,18 @@
                return arr + idx;
        return arr + (unsigned int)idx;
 }
+
+int
+non_constant_expression(void)
+{
+       /*
+        * Even though this variable definition looks like a constant, it
+        * does not fall within C's definition of an integer constant
+        * expression.  Due to that, lint does not perform constant folding
+        * on the expression built from this variable and thus doesn't know
+        * that the conversion will always succeed.
+        */
+       const int not_a_constant = 8;
+       /* expect+1: warning: conversion from 'unsigned long' to 'int' may lose accuracy [132] */
+       return sizeof(double) + not_a_constant * sizeof(char *);
+}
diff -r 390d4369385b -r 2887872126fe tests/usr.bin/xlint/lint1/msg_132.exp
--- a/tests/usr.bin/xlint/lint1/msg_132.exp     Tue Apr 19 22:26:57 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.exp     Tue Apr 19 22:40:13 2022 +0000
@@ -12,3 +12,4 @@
 msg_132.c(59): warning: conversion from 'long long' to 'int' may lose accuracy [132]
 msg_132.c(85): error: operands of '+' have incompatible types (pointer != double) [107]
 msg_132.c(85): warning: function 'cover_build_plus_minus' expects to return value [214]
+msg_132.c(101): warning: conversion from 'unsigned long' to 'int' may lose accuracy [132]



Home | Main Index | Thread Index | Old Index