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: treat incomplete union in the same...



details:   https://anonhg.NetBSD.org/src/rev/602b7594fe1a
branches:  trunk
changeset: 1029111:602b7594fe1a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Dec 21 21:42:21 2021 +0000

description:
lint: treat incomplete union in the same way as incomplete struct

The newly added tests triggered the assertion in begin_designation since
for incomplete types the initialization is stopped before handling the
first brace.

diffstat:

 tests/usr.bin/xlint/lint1/init.c   |  24 +++++++++++++++++++++---
 tests/usr.bin/xlint/lint1/init.exp |  12 ++++++++----
 usr.bin/xlint/lint1/init.c         |  13 +++++++++----
 3 files changed, 38 insertions(+), 11 deletions(-)

diffs (104 lines):

diff -r 71b309eaf21c -r 602b7594fe1a tests/usr.bin/xlint/lint1/init.c
--- a/tests/usr.bin/xlint/lint1/init.c  Tue Dec 21 21:30:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/init.c  Tue Dec 21 21:42:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.8 2021/12/21 21:16:08 rillig Exp $  */
+/*     $NetBSD: init.c,v 1.9 2021/12/21 21:42:21 rillig Exp $  */
 # 3 "init.c"
 
 /*
@@ -73,14 +73,32 @@
        do_nothing,
 };
 
+
+/* expect+1: error: initialization of incomplete type 'incomplete struct incomplete_struct' [175] */
+struct incomplete_struct s1 = {
+       1,
+/* expect+1: error: 's1' has incomplete type 'incomplete struct incomplete_struct' [31] */
+};
+
+/* expect+1: error: initialization of incomplete type 'incomplete struct incomplete_struct' [175] */
+struct incomplete_struct s2 = {
+       .member = 1,
+/* expect+1: error: 's2' has incomplete type 'incomplete struct incomplete_struct' [31] */
+};
+
+struct incomplete_struct {
+       int num;
+};
+
+
+/* expect+1: error: initialization of incomplete type 'incomplete union incomplete_union' [175] */
 union incomplete_union u1 = {
-       /* expect+1: error: too many struct/union initializers [172] */
        1,
 /* expect+1: error: 'u1' has incomplete type 'incomplete union incomplete_union' [31] */
 };
 
+/* expect+1: error: initialization of incomplete type 'incomplete union incomplete_union' [175] */
 union incomplete_union u2 = {
-       /* expect+1: error: type 'incomplete union incomplete_union' does not have member 'member' [101] */
        .member = 1,
 /* expect+1: error: 'u2' has incomplete type 'incomplete union incomplete_union' [31] */
 };
diff -r 71b309eaf21c -r 602b7594fe1a tests/usr.bin/xlint/lint1/init.exp
--- a/tests/usr.bin/xlint/lint1/init.exp        Tue Dec 21 21:30:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/init.exp        Tue Dec 21 21:42:21 2021 +0000
@@ -1,5 +1,9 @@
 init.c(16): error: empty array declaration: empty_array_with_initializer [190]
-init.c(78): error: too many struct/union initializers [172]
-init.c(80): error: 'u1' has incomplete type 'incomplete union incomplete_union' [31]
-init.c(84): error: type 'incomplete union incomplete_union' does not have member 'member' [101]
-init.c(86): error: 'u2' has incomplete type 'incomplete union incomplete_union' [31]
+init.c(78): error: initialization of incomplete type 'incomplete struct incomplete_struct' [175]
+init.c(81): error: 's1' has incomplete type 'incomplete struct incomplete_struct' [31]
+init.c(84): error: initialization of incomplete type 'incomplete struct incomplete_struct' [175]
+init.c(87): error: 's2' has incomplete type 'incomplete struct incomplete_struct' [31]
+init.c(95): error: initialization of incomplete type 'incomplete union incomplete_union' [175]
+init.c(98): error: 'u1' has incomplete type 'incomplete union incomplete_union' [31]
+init.c(101): error: initialization of incomplete type 'incomplete union incomplete_union' [175]
+init.c(104): error: 'u2' has incomplete type 'incomplete union incomplete_union' [31]
diff -r 71b309eaf21c -r 602b7594fe1a usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Tue Dec 21 21:30:49 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Tue Dec 21 21:42:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.226 2021/12/21 21:04:08 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.227 2021/12/21 21:42:21 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.226 2021/12/21 21:04:08 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.227 2021/12/21 21:42:21 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -731,7 +731,7 @@
                warning(238);
        }
 
-       if (tp->t_tspec == STRUCT && tp->t_str->sou_incomplete) {
+       if (is_struct_or_union(tp->t_tspec) && tp->t_str->sou_incomplete) {
                /* initialization of incomplete type '%s' */
                error(175, type_name(tp));
                in->in_err = true;
@@ -990,9 +990,14 @@
 void
 begin_designation(void)
 {
+       initialization *in;
        brace_level *bl;
 
-       bl = current_init()->in_brace_level;
+       in = current_init();
+       if (in->in_err)
+               return;
+
+       bl = in->in_brace_level;
        lint_assert(bl != NULL);
        designation_reset(&bl->bl_designation);
 }



Home | Main Index | Thread Index | Old Index