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 assertion failure for temporar...



details:   https://anonhg.NetBSD.org/src/rev/ca162a360e14
branches:  trunk
changeset: 1020619:ca162a360e14
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 17 21:20:08 2021 +0000

description:
lint: fix assertion failure for temporary objects in initialization

diffstat:

 tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c   |  16 ++++++++------
 tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp |   3 +-
 usr.bin/xlint/lint1/init.c                              |  18 +++++++++++++++-
 3 files changed, 27 insertions(+), 10 deletions(-)

diffs (101 lines):

diff -r 9d359d31e9e7 -r ca162a360e14 tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c
--- a/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c     Sat Apr 17 20:57:18 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c     Sat Apr 17 21:20:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gcc_init_compound_literal.c,v 1.2 2021/04/17 20:57:18 rillig Exp $     */
+/*     $NetBSD: gcc_init_compound_literal.c,v 1.3 2021/04/17 21:20:08 rillig Exp $     */
 # 3 "gcc_init_compound_literal.c"
 
 /*
@@ -12,6 +12,10 @@
  * Using these address constants, it is possible to reference an unnamed
  * object created by a compound literal (C99 6.5.2.5), using either an
  * explicit '&' or the implicit array-to-pointer conversion from C99 6.3.2.1.
+ *
+ * Before init.c 1.195 from 2021-04-17, lint failed with an assertion failure
+ * in check_global_variable, called by check_global_symbols since these
+ * temporary objects have neither storage class EXTERN nor STATIC.
  */
 
 // Seen in sys/crypto/aes/aes_ccm.c.
@@ -20,10 +24,9 @@
 } T = {
        (void *)0,
        (void *)0,      /* expect: too many struct/union initializers */
-// FIXME: lint: assertion "sym->s_scl == EXTERN || sym->s_scl == STATIC" failed
-//     .ctxt = (const unsigned char[4]){
-//         1, 2, 3, 4
-//     },
+       .ctxt = (const unsigned char[4]){
+           1, 2, 3, 4
+       },
 };
 
 struct node {
@@ -36,7 +39,7 @@
  * Initial tree for representing the decisions in the classic number guessing
  * game often used in teaching the basics of programming.
  */
-/* TODO: activate after fixing the assertion failure
+/* expect+1: static variable guess unused */
 static const struct node guess = {
        50,
        &(struct node){
@@ -54,4 +57,3 @@
        },
        (void *)0
 };
-*/
diff -r 9d359d31e9e7 -r ca162a360e14 tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp
--- a/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp   Sat Apr 17 20:57:18 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp   Sat Apr 17 21:20:08 2021 +0000
@@ -1,1 +1,2 @@
-gcc_init_compound_literal.c(22): error: too many struct/union initializers [172]
+gcc_init_compound_literal.c(26): error: too many struct/union initializers [172]
+gcc_init_compound_literal.c(43): warning: static variable guess unused [226]
diff -r 9d359d31e9e7 -r ca162a360e14 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sat Apr 17 20:57:18 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sat Apr 17 21:20:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.194 2021/04/09 23:03:26 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.195 2021/04/17 21:20:08 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.194 2021/04/09 23:03:26 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.195 2021/04/17 21:20:08 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -994,6 +994,17 @@
 static struct initialization *init;
 
 
+static void
+discard_temporary_objects(void)
+{
+       sym_t   *sym;
+
+       for (sym = dcs->d_dlsyms; sym != NULL; sym = sym->s_dlnxt)
+               if (ch_isdigit(sym->s_name[0])) /* see mktempsym */
+                       rmsym(sym);
+}
+
+
 static struct initialization *
 current_init(void)
 {
@@ -1037,6 +1048,9 @@
        debug_indentation--;
 #endif
        debug_step0("end initialization");
+
+       if (init == NULL)
+               discard_temporary_objects();
 }
 
 void



Home | Main Index | Thread Index | Old Index