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: add query for comma operator



details:   https://anonhg.NetBSD.org/src/rev/6e36c96ea5d4
branches:  trunk
changeset: 376576:6e36c96ea5d4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jun 22 13:57:44 2023 +0000

description:
lint: add query for comma operator

diffstat:

 tests/usr.bin/xlint/lint1/queries.c  |  26 ++++++++++++++++++++++----
 tests/usr.bin/xlint/lint1/t_usage.sh |   8 ++++----
 usr.bin/xlint/lint1/err.c            |   5 +++--
 usr.bin/xlint/lint1/tree.c           |  10 ++++++++--
 4 files changed, 37 insertions(+), 12 deletions(-)

diffs (151 lines):

diff -r 5475a7154e40 -r 6e36c96ea5d4 tests/usr.bin/xlint/lint1/queries.c
--- a/tests/usr.bin/xlint/lint1/queries.c       Thu Jun 22 13:02:42 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/queries.c       Thu Jun 22 13:57:44 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: queries.c,v 1.14 2023/06/03 21:08:06 rillig Exp $      */
+/*     $NetBSD: queries.c,v 1.15 2023/06/22 13:57:44 rillig Exp $      */
 # 3 "queries.c"
 
 /*
@@ -15,7 +15,7 @@
  *     such as casts between arithmetic types.
  */
 
-/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11 -X 351 */
+/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12 -X 351 */
 
 typedef unsigned char u8_t;
 typedef unsigned short u16_t;
@@ -324,12 +324,15 @@ Q9(int x)
        case 3:
                return -(13);
        case 4:
+               /* expect+2: comma operator with types 'int' and 'int' [Q12] */
                /* expect+1: parenthesized return value [Q9] */
                return (0), (1);
        case 5:
+               /* expect+2: comma operator with types 'int' and 'int' [Q12] */
                /* expect+1: parenthesized return value [Q9] */
                return (0, 1);
        case 6:
+               /* expect+1: comma operator with types 'int' and 'int' [Q12] */
                return 0, 1;
        case 7:
                /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */
@@ -340,9 +343,9 @@ Q9(int x)
                return (0.0);
        case 9:
                return
-# 344 "queries.c" 3 4
+# 347 "queries.c" 3 4
                ((void *)0)
-# 346 "queries.c"
+# 349 "queries.c"
                /* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */
                ;
        case 10:
@@ -379,6 +382,21 @@ Q11(void)
        static_var_init++;
 }
 
+void
+Q12(void)
+{
+       /* expect+1: comma operator with types 'void' and '_Bool' [Q12] */
+       if (Q11(), cond)
+               return;
+
+       /* expect+5: implicit conversion changes sign from 'unsigned char' to 'int' [Q3] */
+       /* expect+4: implicit conversion changes sign from 'int' to 'unsigned short' [Q3] */
+       /* expect+3: implicit conversion changes sign from 'unsigned short' to 'int' [Q3] */
+       /* expect+2: implicit conversion changes sign from 'int' to 'unsigned int' [Q3] */
+       /* expect+1: comma operator with types 'unsigned short' and 'unsigned int' [Q12] */
+       u16 += u8, u32 += u16;
+}
+
 /*
  * Since queries do not affect the exit status, force a warning to make this
  * test conform to the general expectation that a test that produces output
diff -r 5475a7154e40 -r 6e36c96ea5d4 tests/usr.bin/xlint/lint1/t_usage.sh
--- a/tests/usr.bin/xlint/lint1/t_usage.sh      Thu Jun 22 13:02:42 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/t_usage.sh      Thu Jun 22 13:57:44 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_usage.sh,v 1.4 2023/06/03 21:08:06 rillig Exp $
+# $NetBSD: t_usage.sh,v 1.5 2023/06/22 13:57:44 rillig Exp $
 #
 # Copyright (c) 2023 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -97,13 +97,13 @@ enable_queries_body()
 
        # The largest known query.
        atf_check \
-           "$lint1" -q 11 code.c /dev/null
+           "$lint1" -q 12 code.c /dev/null
 
        # Larger than the largest known query.
        atf_check \
            -s 'exit:1' \
-           -e "inline:lint1: invalid query ID '12'\n" \
-           "$lint1" -q 12 code.c /dev/null
+           -e "inline:lint1: invalid query ID '13'\n" \
+           "$lint1" -q 13 code.c /dev/null
 
        # Whitespace is not allowed before a query ID.
        atf_check \
diff -r 5475a7154e40 -r 6e36c96ea5d4 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Thu Jun 22 13:02:42 2023 +0000
+++ b/usr.bin/xlint/lint1/err.c Thu Jun 22 13:57:44 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.199 2023/06/09 15:36:31 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.200 2023/06/22 13:57:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.199 2023/06/09 15:36:31 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.200 2023/06/22 13:57:44 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -707,6 +707,7 @@ static const char *queries[] = {
        "parenthesized return value",                                 /* Q9 */
        "chained assignment with '%s' and '%s'",                      /* Q10 */
        "static variable '%s' in function",                           /* Q11 */
+       "comma operator with types '%s' and '%s'",                    /* Q12 */
 };
 
 bool any_query_enabled;                /* for optimizing non-query scenarios */
diff -r 5475a7154e40 -r 6e36c96ea5d4 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Thu Jun 22 13:02:42 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Thu Jun 22 13:57:44 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.527 2023/06/09 15:36:31 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.528 2023/06/22 13:57:44 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.527 2023/06/09 15:36:31 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.528 2023/06/22 13:57:44 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1783,6 +1783,12 @@ build_binary(tnode_t *ln, op_t op, bool 
                ntn = build_assignment(op, sys, ln, rn);
                break;
        case COMMA:
+               if (any_query_enabled) {
+                       /* comma operator with types '%s' and '%s' */
+                       query_message(12,
+                           type_name(ln->tn_type), type_name(rn->tn_type));
+               }
+               /* FALLTHROUGH */
        case QUEST:
                ntn = new_tnode(op, sys, rn->tn_type, ln, rn);
                break;



Home | Main Index | Thread Index | Old Index