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: remove wrong warning about wrong i...



details:   https://anonhg.NetBSD.org/src/rev/97b852802c4e
branches:  trunk
changeset: 954056:97b852802c4e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 28 14:01:49 2021 +0000

description:
lint: remove wrong warning about wrong initializer type

The following code is valid:

        int valid = {{{ 3 }}};

C90 3.5.7 and C99 6.7.8 both say that the "initializer for a scalar
shall be a single expression, optionally enclosed in braces".  They
don't put any upper bound on the amount of braces, not even in the
"Translation limits" section.

diffstat:

 distrib/sets/lists/tests/mi                |   4 ++--
 tests/usr.bin/xlint/lint1/Makefile         |   4 ++--
 tests/usr.bin/xlint/lint1/d_c99_init.c     |  10 +++++-----
 tests/usr.bin/xlint/lint1/d_c99_init.exp   |   2 --
 tests/usr.bin/xlint/lint1/msg_176.c        |  13 ++++++++++---
 tests/usr.bin/xlint/lint1/msg_176.exp      |   1 -
 tests/usr.bin/xlint/lint1/t_integration.sh |  21 +++++++++------------
 usr.bin/xlint/lint1/err.c                  |   6 +++---
 usr.bin/xlint/lint1/init.c                 |  23 ++++++++---------------
 9 files changed, 39 insertions(+), 45 deletions(-)

diffs (235 lines):

diff -r 27d09c29e7a5 -r 97b852802c4e distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Mar 28 13:39:39 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Mar 28 14:01:49 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1033 2021/03/23 21:19:08 rillig Exp $
+# $NetBSD: mi,v 1.1034 2021/03/28 14:01:49 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6532,7 +6532,7 @@
 ./usr/tests/usr.bin/xlint/lint1/msg_175.c                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_175.exp                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_176.c                      tests-usr.bin-tests     compattestfile,atf
-./usr/tests/usr.bin/xlint/lint1/msg_176.exp                    tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_176.exp                    tests-obsolete          obsolete
 ./usr/tests/usr.bin/xlint/lint1/msg_177.c                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_177.exp                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_178.c                      tests-usr.bin-tests     compattestfile,atf
diff -r 27d09c29e7a5 -r 97b852802c4e tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sun Mar 28 13:39:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sun Mar 28 14:01:49 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.36 2021/03/23 21:19:08 rillig Exp $
+# $NetBSD: Makefile,v 1.37 2021/03/28 14:01:50 rillig Exp $
 
 NOMAN=         # defined
 
@@ -98,7 +98,7 @@
 FILES+=                d_typefun.c
 FILES+=                d_typename_as_var.c
 FILES+=                d_zero_sized_arrays.c
-FILES+=                ${:U0 ${:U:range=340}:C,^.$,0&,:C,^..$,0&,:@msg@msg_${msg}.c msg_${msg}.exp@}
+FILES+=                ${:U0 ${:U:range=340}:C,^.$,0&,:C,^..$,0&,:@msg@msg_${msg}.c msg_${msg}.exp@:Nmsg_176.exp}
 
 # Note: only works for adding tests.
 # To remove a test, the $$mi file must be edited manually.
diff -r 27d09c29e7a5 -r 97b852802c4e tests/usr.bin/xlint/lint1/d_c99_init.c
--- a/tests/usr.bin/xlint/lint1/d_c99_init.c    Sun Mar 28 13:39:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.c    Sun Mar 28 14:01:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_init.c,v 1.16 2021/03/27 23:13:48 rillig Exp $   */
+/*     $NetBSD: d_c99_init.c,v 1.17 2021/03/28 14:01:50 rillig Exp $   */
 # 3 "d_c99_init.c"
 
 /*
@@ -15,11 +15,11 @@
 } any;
 
 
-// C99 6.7.8p11 says "optionally enclosed in braces".  The intended
-// interpretation is "optionally enclosed in a single pair of braces".
+// C99 6.7.8p11 says "optionally enclosed in braces".  There is no limitation
+// on the number of brace pairs.
 int scalar_without_braces = 3;
 int scalar_with_optional_braces = { 3 };
-int scalar_with_too_many_braces = {{ 3 }};             /* expect: 176 */
+int scalar_with_too_many_braces = {{ 3 }};
 int scalar_with_too_many_initializers = { 3, 5 };      /* expect: 174 */
 
 
@@ -139,7 +139,7 @@
  * about this, so there is no extra work for lint to do.
  */
 struct point scalar_with_several_braces = {
-       {{{3}}},                /*FIXME*//* expect: invalid initializer type int */
+       {{{3}}},
        {{{{4}}}},
 };
 
diff -r 27d09c29e7a5 -r 97b852802c4e tests/usr.bin/xlint/lint1/d_c99_init.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_init.exp  Sun Mar 28 13:39:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.exp  Sun Mar 28 14:01:49 2021 +0000
@@ -1,7 +1,5 @@
-d_c99_init.c(22): error: invalid initializer type int [176]
 d_c99_init.c(23): error: too many initializers [174]
 d_c99_init.c(49): error: cannot initialize 'pointer to const void' from 'struct any' [185]
 d_c99_init.c(65): error: too many array initializers, expected 3 [173]
 d_c99_init.c(130): error: syntax error 'named member must only be used with struct/union' [249]
-d_c99_init.c(142): error: invalid initializer type int [176]
 d_c99_init.c(217): error: too many struct/union initializers [172]
diff -r 27d09c29e7a5 -r 97b852802c4e tests/usr.bin/xlint/lint1/msg_176.c
--- a/tests/usr.bin/xlint/lint1/msg_176.c       Sun Mar 28 13:39:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_176.c       Sun Mar 28 14:01:49 2021 +0000
@@ -1,7 +1,14 @@
-/*     $NetBSD: msg_176.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_176.c,v 1.3 2021/03/28 14:01:50 rillig Exp $       */
 # 3 "msg_176.c"
 
 // Test for message: invalid initializer type %s [176]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/*
+ * Before init.c 1.161 from 2021-03-28, lint wronly complained about
+ * initializers with redundant braces.
+ *
+ * C99 allows these, both GCC and Clang warn about them since they are unusual
+ * and confusing.
+ */
+
+int valid = {{{3}}};
diff -r 27d09c29e7a5 -r 97b852802c4e tests/usr.bin/xlint/lint1/msg_176.exp
--- a/tests/usr.bin/xlint/lint1/msg_176.exp     Sun Mar 28 13:39:39 2021 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-msg_176.c(6): error: syntax error ':' [249]
diff -r 27d09c29e7a5 -r 97b852802c4e tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Sun Mar 28 13:39:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Sun Mar 28 14:01:49 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.36 2021/03/27 13:59:18 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.37 2021/03/28 14:01:50 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -169,22 +169,19 @@
 test_case all_messages
 all_messages_body()
 {
-       local srcdir ok msg base flags
+       local failed msg
 
-       srcdir="$(atf_get_srcdir)"
-       ok="true"
+       failed=""
 
        for msg in $(seq 0 340); do
-               base="$(printf '%s/msg_%03d' "${srcdir}" "${msg}")"
-               flags="$(extract_flags "${base}.c")"
-
-               # shellcheck disable=SC2154 disable=SC2086
-               ${Atf_Check} -s not-exit:0 -o "file:${base}.exp" -e empty \
-                   ${LINT1} ${flags} "${base}.c" /dev/null \
-               || ok="false"
+               name="$(printf 'msg_%03d.c' "${msg}")"
+               check_lint1 "${name}" \
+               || failed="$failed${failed:+ }$name"
        done
 
-       atf_check "${ok}"
+       if [ "$failed" != "" ]; then
+               atf_check "false" "$failed"
+       fi
 }
 
 
diff -r 27d09c29e7a5 -r 97b852802c4e usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sun Mar 28 13:39:39 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Sun Mar 28 14:01:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.96 2021/03/27 12:42:22 rillig Exp $  */
+/*     $NetBSD: err.c,v 1.97 2021/03/28 14:01:49 rillig Exp $  */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.96 2021/03/27 12:42:22 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.97 2021/03/28 14:01:49 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -230,7 +230,7 @@
        "too many array initializers, expected %d",                   /* 173 */
        "too many initializers",                                      /* 174 */
        "initialization of an incomplete type",                       /* 175 */
-       "invalid initializer type %s",                                /* 176 */
+       "",                     /* no longer used */                  /* 176 */
        "non-constant initializer",                                   /* 177 */
        "initializer does not fit",                                   /* 178 */
        "cannot initialize struct/union with no named member",        /* 179 */
diff -r 27d09c29e7a5 -r 97b852802c4e usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sun Mar 28 13:39:39 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sun Mar 28 14:01:49 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.161 2021/03/28 13:09:43 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.162 2021/03/28 14:01:49 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.161 2021/03/28 13:09:43 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.162 2021/03/28 14:01:49 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -858,12 +858,13 @@
 
        level = in->brace_level;
        lint_assert(level->bl_remaining > 0);
-       lint_assert(level->bl_type == NULL ||
-                   !is_scalar(level->bl_type->t_tspec));
 
        in->brace_level = xcalloc(1, sizeof *in->brace_level);
        in->brace_level->bl_enclosing = level;
        in->brace_level->bl_type = level->bl_subtype;
+       if (in->brace_level->bl_type == NULL)
+               in->brace_level->bl_type = level->bl_type;
+       lint_assert(in->brace_level->bl_type != NULL);
        lint_assert(in->brace_level->bl_type->t_tspec != FUNC);
 
 again:
@@ -1012,13 +1013,6 @@
        debug_enter();
        initialization_debug(in);
 
-       if (in->brace_level->bl_type != NULL &&
-           is_scalar(in->brace_level->bl_type->t_tspec)) {
-               /* invalid initializer type %s */
-               error(176, type_name(in->brace_level->bl_type));
-               initialization_set_error(in);
-       }
-
        if (!in->initerr &&
            !brace_level_check_too_many_initializers(in->brace_level))
                initialization_set_error(in);
@@ -1029,10 +1023,9 @@
        if (!in->initerr) {
                in->brace_level->bl_brace = true;
                designation_debug(&in->designation);
-               debug_step("expecting type '%s'",
-                   type_name(in->brace_level->bl_type != NULL
-                       ? in->brace_level->bl_type
-                       : in->brace_level->bl_subtype));
+               if (in->brace_level->bl_type != NULL)
+                       debug_step("expecting type '%s'",
+                           type_name(in->brace_level->bl_type));
        }
 
        initialization_debug(in);



Home | Main Index | Thread Index | Old Index