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 debug logging for C99-style in...



details:   https://anonhg.NetBSD.org/src/rev/dbe3369e4a87
branches:  trunk
changeset: 953706:dbe3369e4a87
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Mar 17 15:45:30 2021 +0000

description:
lint: add debug logging for C99-style initialization of arrays

No functional change outside debug mode.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |   7 ++++---
 usr.bin/xlint/lint1/externs1.h |   3 ++-
 usr.bin/xlint/lint1/init.c     |  20 ++++++++++++++++++--
 3 files changed, 24 insertions(+), 6 deletions(-)

diffs (94 lines):

diff -r fcbfea964afc -r dbe3369e4a87 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Wed Mar 17 15:37:42 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Wed Mar 17 15:45:30 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.175 2021/03/17 01:53:21 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.176 2021/03/17 15:45:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.175 2021/03/17 01:53:21 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.176 2021/03/17 15:45:30 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -107,7 +107,7 @@
 #define SAVE_WARN_FLAGS(f, l)  olwarn = lwarn
 #define RESTORE_WARN_FLAGS(f, l) \
        (void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn))
-#define cgram_debug(fmt, args...) (void)0
+#define cgram_debug(fmt, args...) do { } while (false)
 #endif
 
 /* unbind the anonymous struct members from the struct */
@@ -1359,6 +1359,7 @@
 
 designator:                    /* C99 6.7.8 "Initialization" */
          T_LBRACK range T_RBRACK {
+               designator_push_subscript($2);
                if (!Sflag)
                        /* array initializer with des.s is a C9X feature */
                        warning(321);
diff -r fcbfea964afc -r dbe3369e4a87 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Wed Mar 17 15:37:42 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Wed Mar 17 15:45:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.75 2021/03/17 01:53:21 rillig Exp $     */
+/*     $NetBSD: externs1.h,v 1.76 2021/03/17 15:45:30 rillig Exp $     */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -300,6 +300,7 @@
 extern void    init_lbrace(void);
 extern void    init_using_expr(tnode_t *);
 extern void    push_member(sbuf_t *);
+extern void    designator_push_subscript(range_t);
 
 /*
  * emit.c
diff -r fcbfea964afc -r dbe3369e4a87 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Wed Mar 17 15:37:42 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Wed Mar 17 15:45:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.90 2021/03/17 15:37:42 rillig Exp $ */
+/*     $NetBSD: init.c,v 1.91 2021/03/17 15:45:30 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.90 2021/03/17 15:37:42 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.91 2021/03/17 15:45:30 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -287,6 +287,22 @@
        }
 }
 
+/*
+ * A struct member that has array type is initialized using a designator.
+ *
+ * C99 example: struct { int member[4]; } var = { [2] = 12345 };
+ *
+ * GNU example: struct { int member[4]; } var = { [1 ... 3] = 12345 };
+ */
+void
+designator_push_subscript(range_t range)
+{
+       debug_enter();
+       debug_step("subscript range is %zu ... %zu", range.lo, range.hi);
+       debug_initstack();
+       debug_leave();
+}
+
 static void
 pop_member(void)
 {



Home | Main Index | Thread Index | Old Index