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 support for C11-isms such as i...



details:   https://anonhg.NetBSD.org/src/rev/ccaba311dbab
branches:  trunk
changeset: 378487:ccaba311dbab
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Apr 14 18:35:40 2021 +0000

description:
lint: add support for C11-isms such as int[static 3]

diffstat:

 tests/usr.bin/xlint/lint1/msg_343.c   |   4 ++--
 tests/usr.bin/xlint/lint1/msg_343.exp |   4 ++--
 usr.bin/xlint/lint1/cgram.y           |  10 +++++-----
 usr.bin/xlint/lint1/check-msgs.lua    |   5 +++--
 usr.bin/xlint/lint1/err.c             |  22 +++++++++++++++++++---
 usr.bin/xlint/lint1/externs1.h        |   3 ++-
 usr.bin/xlint/lint1/lint1.h           |   3 ++-
 7 files changed, 35 insertions(+), 16 deletions(-)

diffs (163 lines):

diff -r bd560eb41757 -r ccaba311dbab tests/usr.bin/xlint/lint1/msg_343.c
--- a/tests/usr.bin/xlint/lint1/msg_343.c       Wed Apr 14 18:27:11 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_343.c       Wed Apr 14 18:35:40 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_343.c,v 1.1 2021/04/14 18:27:11 rillig Exp $       */
+/*     $NetBSD: msg_343.c,v 1.2 2021/04/14 18:35:40 rillig Exp $       */
 # 3 "msg_343.c"
 
-/* Test for message: static array size is a C99 extension [343] */
+/* Test for message: static array size is a C11 extension [343] */
 
 /* lint1-flags: -sw */
 
diff -r bd560eb41757 -r ccaba311dbab tests/usr.bin/xlint/lint1/msg_343.exp
--- a/tests/usr.bin/xlint/lint1/msg_343.exp     Wed Apr 14 18:27:11 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_343.exp     Wed Apr 14 18:35:40 2021 +0000
@@ -1,6 +1,6 @@
-msg_343.c(10): error: static array size is a C99 extension [343]
+msg_343.c(10): error: static array size is a C11 extension [343]
 msg_343.c(12): error: syntax error 'volatile' [249]
-msg_343.c(27): error: static array size is a C99 extension [343]
+msg_343.c(27): error: static array size is a C11 extension [343]
 msg_343.c(34): error: syntax error 'volatile' [249]
 msg_343.c(38): error: cannot dereference non-pointer type [96]
 msg_343.c(38): warning: function returns_volatile_int_array expects to return value [214]
diff -r bd560eb41757 -r ccaba311dbab usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Wed Apr 14 18:27:11 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Wed Apr 14 18:35:40 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.215 2021/04/14 18:27:11 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.216 2021/04/14 18:35:40 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.215 2021/04/14 18:27:11 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.216 2021/04/14 18:35:40 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -1134,11 +1134,11 @@ param_decl:
 
 array_size:
          T_SCLASS constant_expr {
-               /* C99 6.7.6.3 */
+               /* C11 6.7.6.3p7 */
                if ($1 != STATIC)
                        yyerror("Bad attribute");
-               /* static array size is a C99 extension */
-               c99ism(343);
+               /* static array size is a C11 extension */
+               c11ism(343);
                $$ = $2;
          }
        | constant_expr {
diff -r bd560eb41757 -r ccaba311dbab usr.bin/xlint/lint1/check-msgs.lua
--- a/usr.bin/xlint/lint1/check-msgs.lua        Wed Apr 14 18:27:11 2021 +0000
+++ b/usr.bin/xlint/lint1/check-msgs.lua        Wed Apr 14 18:35:40 2021 +0000
@@ -1,5 +1,5 @@
 #! /usr/bin/lua
--- $NetBSD: check-msgs.lua,v 1.9 2021/02/28 12:45:47 rillig Exp $
+-- $NetBSD: check-msgs.lua,v 1.10 2021/04/14 18:35:40 rillig Exp $
 
 --[[
 
@@ -83,7 +83,8 @@ local function collect_errors(fname, msg
 
     local func, id = line:match("^%s+(%w+)%((%d+)[),]")
     id = tonumber(id)
-    if func == "error" or func == "warning" or func == "c99ism" or
+    if func == "error" or func == "warning" or
+       func == "c99ism" or func == "c11ism" or
        func == "gnuism" or func == "message" then
       local comment = prev:match("^%s+/%* (.+) %*/$")
       if comment ~= nil then
diff -r bd560eb41757 -r ccaba311dbab usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Wed Apr 14 18:27:11 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Wed Apr 14 18:35:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.107 2021/04/14 13:34:08 christos Exp $       */
+/*     $NetBSD: err.c,v 1.108 2021/04/14 18:35:40 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.107 2021/04/14 13:34:08 christos Exp $");
+__RCSID("$NetBSD: err.c,v 1.108 2021/04/14 18:35:40 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -397,7 +397,7 @@ const       char *msgs[] = {
        "initialization with '[a...b]' is a GNU extension",           /* 340 */
        "argument to '%s' must be 'unsigned char' or EOF, not '%s'",  /* 341 */
        "argument to '%s' must be cast to 'unsigned char', not to '%s'", /* 342 */
-       "static array size is a C99 extension",                       /* 343 */
+       "static array size is a C11 extension",                       /* 343 */
 };
 
 static struct include_level {
@@ -612,6 +612,22 @@ void
        va_end(ap);
 }
 
+/* TODO: add a command line option for allowing C99 but not C11. */
+void
+(c11ism)(int n, ...)
+{
+       va_list ap;
+       bool extensions_ok = Sflag || gflag;
+
+       va_start(ap, n);
+       if (sflag && !extensions_ok) {
+               verror(n, ap);
+       } else if (sflag || !extensions_ok) {
+               vwarning(n, ap);
+       }
+       va_end(ap);
+}
+
 void
 (gnuism)(int n, ...)
 {
diff -r bd560eb41757 -r ccaba311dbab usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Wed Apr 14 18:27:11 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Wed Apr 14 18:35:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.103 2021/04/09 15:58:43 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.104 2021/04/14 18:35:40 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -124,6 +124,7 @@ extern      void    warning(int, ...);
 extern void    message(int, ...);
 extern void    gnuism(int, ...);
 extern void    c99ism(int, ...);
+extern void    c11ism(int, ...);
 extern void    internal_error(const char *, int, const char *, ...)
      __attribute__((__noreturn__,__format__(__printf__, 3, 4)));
 extern void    assert_failed(const char *, int, const char *, const char *)
diff -r bd560eb41757 -r ccaba311dbab usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Wed Apr 14 18:27:11 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Wed Apr 14 18:35:40 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.94 2021/04/10 18:36:27 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.95 2021/04/14 18:35:40 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -482,6 +482,7 @@ check_printf(const char *fmt, ...)
 #  define message(id, args...) wrap_check_printf(message, id, ##args)
 #  define gnuism(id, args...) wrap_check_printf(gnuism, id, ##args)
 #  define c99ism(id, args...) wrap_check_printf(c99ism, id, ##args)
+#  define c11ism(id, args...) wrap_check_printf(c11ism, id, ##args)
 #endif
 
 static inline bool



Home | Main Index | Thread Index | Old Index