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 parenthesized return...



details:   https://anonhg.NetBSD.org/src/rev/646de478f770
branches:  trunk
changeset: 374257:646de478f770
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 15 11:34:45 2023 +0000

description:
lint: add query for parenthesized return value

diffstat:

 tests/usr.bin/xlint/lint1/queries.c |  47 +++++++++++++++++++++++++++++++++++-
 usr.bin/xlint/lint1/err.c           |   5 ++-
 usr.bin/xlint/lint1/func.c          |  19 +++++++++++++-
 3 files changed, 65 insertions(+), 6 deletions(-)

diffs (137 lines):

diff -r af1e9cd816ab -r 646de478f770 tests/usr.bin/xlint/lint1/queries.c
--- a/tests/usr.bin/xlint/lint1/queries.c       Sat Apr 15 10:53:59 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/queries.c       Sat Apr 15 11:34:45 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: queries.c,v 1.11 2023/03/31 13:03:05 rillig Exp $      */
+/*     $NetBSD: queries.c,v 1.12 2023/04/15 11:34:45 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 -X 351 */
+/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9 -X 351 */
 
 typedef unsigned char u8_t;
 typedef unsigned short u16_t;
@@ -310,6 +310,49 @@ Q8(void)
        u16 = 0000644;
 }
 
+int
+Q9(int x)
+{
+       switch (x) {
+       case 0:
+               return 0;
+       case 1:
+               /* expect+1: parenthesized return value [Q9] */
+               return (0);
+       case 2:
+               return +(0);
+       case 3:
+               return -(13);
+       case 4:
+               /* expect+1: parenthesized return value [Q9] */
+               return (0), (1);
+       case 5:
+               /* expect+1: parenthesized return value [Q9] */
+               return (0, 1);
+       case 6:
+               return 0, 1;
+       case 7:
+               /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */
+               return 0.0;
+       case 8:
+               /* expect+2: parenthesized return value [Q9] */
+               /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */
+               return (0.0);
+       case 9:
+               return
+# 344 "queries.c" 3 4
+               ((void *)0)
+# 346 "queries.c"
+               /* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */
+               ;
+       case 10:
+               /* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */
+               return (void *)(0);
+       default:
+               return 0;
+       }
+}
+
 /*
  * 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 af1e9cd816ab -r 646de478f770 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Apr 15 10:53:59 2023 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Apr 15 11:34:45 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.192 2023/03/31 13:03:05 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.193 2023/04/15 11:34:45 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.192 2023/03/31 13:03:05 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.193 2023/04/15 11:34:45 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -699,6 +699,7 @@ static const char *queries[] = {
        "no-op cast from '%s' to '%s'",                               /* Q6 */
        "redundant cast from '%s' to '%s' before assignment",         /* Q7 */
        "octal number '%.*s'",                                        /* Q8 */
+       "parenthesized return value",                                 /* Q9 */
 };
 
 bool any_query_enabled;                /* for optimizing non-query scenarios */
diff -r af1e9cd816ab -r 646de478f770 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sat Apr 15 10:53:59 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sat Apr 15 11:34:45 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.152 2023/04/15 10:32:46 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.153 2023/04/15 11:34:45 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.152 2023/04/15 10:32:46 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.153 2023/04/15 11:34:45 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -1047,9 +1047,24 @@ do_continue(void)
        set_reached(false);
 }
 
+static bool
+is_parenthesized(const tnode_t *tn)
+{
+
+       while (!tn->tn_parenthesized && tn->tn_op == COMMA)
+               tn = tn->tn_right;
+       return tn->tn_parenthesized && !tn->tn_sys;
+}
+
 static void
 check_return_value(bool sys, tnode_t *tn)
 {
+
+       if (any_query_enabled && is_parenthesized(tn)) {
+               /* parenthesized return value */
+               query_message(9);
+       }
+
        /* Create a temporary node for the left side */
        tnode_t *ln = expr_zero_alloc(sizeof(*ln));
        ln->tn_op = NAME;



Home | Main Index | Thread Index | Old Index