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: fix type comparison in _Generic se...



details:   https://anonhg.NetBSD.org/src/rev/1baeb5a6c4b5
branches:  trunk
changeset: 379930:1baeb5a6c4b5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 27 21:16:40 2021 +0000

description:
lint: fix type comparison in _Generic selection expressions

In the newly added test comma_expression, there were two distinct type
objects for the tspec DOUBLE.

diffstat:

 tests/usr.bin/xlint/lint1/c11_generic_expression.c   |  18 +++++++++++++++++-
 tests/usr.bin/xlint/lint1/c11_generic_expression.exp |   1 +
 usr.bin/xlint/lint1/tree.c                           |   7 ++++---
 3 files changed, 22 insertions(+), 4 deletions(-)

diffs (65 lines):

diff -r f9807de36d86 -r 1baeb5a6c4b5 tests/usr.bin/xlint/lint1/c11_generic_expression.c
--- a/tests/usr.bin/xlint/lint1/c11_generic_expression.c        Sun Jun 27 20:47:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_generic_expression.c        Sun Jun 27 21:16:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: c11_generic_expression.c,v 1.3 2021/06/27 20:47:13 rillig Exp $        */
+/*     $NetBSD: c11_generic_expression.c,v 1.4 2021/06/27 21:16:40 rillig Exp $        */
 # 3 "c11_generic_expression.c"
 
 /*
@@ -59,3 +59,19 @@ classify_char(char c)
            default: 0.0
        );
 }
+
+/*
+ * Before cgram.y 1.238 from 2021-06-27, lint accepted a comma-expression,
+ * which looked as if _Generic would accept multiple arguments before the
+ * selection.
+ */
+/* ARGSUSED */
+const int *
+comma_expression(char first, double second)
+{
+       return _Generic(first, second,  /* FIXME */
+           char: "first",
+           double: 2.0
+       );
+       /* expect-1: mismatch (pointer to const int) and (double) [211] */
+}
diff -r f9807de36d86 -r 1baeb5a6c4b5 tests/usr.bin/xlint/lint1/c11_generic_expression.exp
--- a/tests/usr.bin/xlint/lint1/c11_generic_expression.exp      Sun Jun 27 20:47:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_generic_expression.exp      Sun Jun 27 21:16:40 2021 +0000
@@ -2,3 +2,4 @@ c11_generic_expression.c(29): warning: f
 c11_generic_expression.c(21): warning: argument 'var' unused in function 'classify_type_without_default' [231]
 c11_generic_expression.c(37): warning: argument 'var' unused in function 'classify_type_with_default' [231]
 c11_generic_expression.c(53): warning: argument 'c' unused in function 'classify_char' [231]
+c11_generic_expression.c(75): error: return value type mismatch (pointer to const int) and (double) [211]
diff -r f9807de36d86 -r 1baeb5a6c4b5 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Jun 27 20:47:13 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Jun 27 21:16:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.291 2021/06/27 20:47:13 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.292 2021/06/27 21:16:40 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.291 2021/06/27 20:47:13 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.292 2021/06/27 21:16:40 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -475,7 +475,8 @@ build_generic_selection(const tnode_t *e
        tnode_t *default_result = NULL;
 
        for (; sel != NULL; sel = sel->gat_prev)
-               if (expr != NULL && sel->gat_arg == expr->tn_type)
+               if (expr != NULL &&
+                   eqtype(sel->gat_arg, expr->tn_type, false, false, NULL))
                        return sel->gat_result;
                else if (sel->gat_arg == NULL)
                        default_result = sel->gat_result;



Home | Main Index | Thread Index | Old Index