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 the C11 type quali...



details:   https://anonhg.NetBSD.org/src/rev/9c1104eee610
branches:  trunk
changeset: 373150:9c1104eee610
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 21 13:07:21 2023 +0000

description:
lint: add support for the C11 type qualifier '_Atomic'

That keyword can be used as a type specifier as well, support for that
will be added later.

diffstat:

 distrib/sets/lists/tests/mi            |   3 ++-
 tests/usr.bin/xlint/lint1/Makefile     |   4 ++--
 tests/usr.bin/xlint/lint1/c11_atomic.c |   7 +------
 tests/usr.bin/xlint/lint1/c99_atomic.c |   9 +++------
 tests/usr.bin/xlint/lint1/msg_350.c    |  12 ++++++++++++
 usr.bin/xlint/lint1/cgram.y            |  14 ++++++++++----
 usr.bin/xlint/lint1/debug.c            |   5 +++--
 usr.bin/xlint/lint1/decl.c             |   6 +++---
 usr.bin/xlint/lint1/err.c              |   5 +++--
 usr.bin/xlint/lint1/lex.c              |   6 ++++--
 usr.bin/xlint/lint1/lint1.h            |   8 ++++++--
 11 files changed, 49 insertions(+), 30 deletions(-)

diffs (275 lines):

diff -r 5dded4c50bd7 -r 9c1104eee610 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Jan 21 12:50:52 2023 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Jan 21 13:07:21 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1245 2023/01/21 11:57:03 rillig Exp $
+# $NetBSD: mi,v 1.1246 2023/01/21 13:07:21 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -7336,6 +7336,7 @@
 ./usr/tests/usr.bin/xlint/lint1/msg_348.exp                    tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_349.c                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_349.exp                    tests-obsolete          obsolete,atf
+./usr/tests/usr.bin/xlint/lint1/msg_350.c                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.c                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.exp                   tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.c                  tests-usr.bin-tests     compattestfile,atf
diff -r 5dded4c50bd7 -r 9c1104eee610 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sat Jan 21 12:50:52 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sat Jan 21 13:07:21 2023 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.132 2023/01/21 11:57:03 rillig Exp $
+# $NetBSD: Makefile,v 1.133 2023/01/21 13:07:22 rillig Exp $
 
 NOMAN=         # defined
-MAX_MESSAGE=   349             # see lint1/err.c
+MAX_MESSAGE=   350             # see lint1/err.c
 
 .include <bsd.own.mk>
 
diff -r 5dded4c50bd7 -r 9c1104eee610 tests/usr.bin/xlint/lint1/c11_atomic.c
--- a/tests/usr.bin/xlint/lint1/c11_atomic.c    Sat Jan 21 12:50:52 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_atomic.c    Sat Jan 21 13:07:21 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: c11_atomic.c,v 1.1 2023/01/21 11:57:03 rillig Exp $    */
+/*     $NetBSD: c11_atomic.c,v 1.2 2023/01/21 13:07:22 rillig Exp $    */
 # 3 "c11_atomic.c"
 
 /*
@@ -12,16 +12,11 @@
 
 /* lint1-extra-flags: -Ac11 */
 
-/* FIXME: The error messages are misleading. */
-
 /* C11 6.7.3 "Type qualifiers" */
-/* expect+2: error: old-style declaration; add 'int' [1] */
-/* expect+1: error: syntax error 'int' [249] */
 typedef _Atomic int atomic_int;
 
 typedef _Atomic struct {
        int field;
 } atomic_struct;
-/* expect-1: error: illegal type combination [4] */
 
 /* TODO: C11 6.7.2.4 "Atomic type specifiers" */
diff -r 5dded4c50bd7 -r 9c1104eee610 tests/usr.bin/xlint/lint1/c99_atomic.c
--- a/tests/usr.bin/xlint/lint1/c99_atomic.c    Sat Jan 21 12:50:52 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/c99_atomic.c    Sat Jan 21 13:07:21 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: c99_atomic.c,v 1.1 2023/01/21 11:57:03 rillig Exp $    */
+/*     $NetBSD: c99_atomic.c,v 1.2 2023/01/21 13:07:22 rillig Exp $    */
 # 3 "c99_atomic.c"
 
 /*
@@ -6,13 +6,10 @@
  * mode, the parser recognizes the keyword but flags it.
  */
 
-/* FIXME: The error messages are misleading. */
-
-/* expect+2: error: old-style declaration; add 'int' [1] */
-/* expect+1: error: syntax error 'int' [249] */
+/* expect+1: error: '_Atomic' requires C11 or later [350] */
 typedef _Atomic int atomic_int;
 
+/* expect+1: error: '_Atomic' requires C11 or later [350] */
 typedef _Atomic struct {
        int field;
 } atomic_struct;
-/* expect-1: error: illegal type combination [4] */
diff -r 5dded4c50bd7 -r 9c1104eee610 tests/usr.bin/xlint/lint1/msg_350.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_350.c       Sat Jan 21 13:07:21 2023 +0000
@@ -0,0 +1,12 @@
+/*     $NetBSD: msg_350.c,v 1.1 2023/01/21 13:07:22 rillig Exp $       */
+# 3 "msg_350.c"
+
+// Test for message 350: '_Atomic' requires C11 or later [350]
+
+/* expect+1: error: '_Atomic' requires C11 or later [350] */
+typedef _Atomic int atomic_int;
+
+/* expect+1: error: '_Atomic' requires C11 or later [350] */
+typedef _Atomic struct {
+       int field;
+} atomic_struct;
diff -r 5dded4c50bd7 -r 9c1104eee610 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Jan 21 12:50:52 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Jan 21 13:07:21 2023 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.429 2023/01/21 12:50:52 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.430 2023/01/21 13:07:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.429 2023/01/21 12:50:52 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.430 2023/01/21 13:07:22 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -206,7 +206,7 @@
  */
 %token <y_tspec>       T_TYPE
 
-/* qualifiers (const, volatile, restrict, _Thread_local) */
+/* qualifiers (const, volatile, restrict, _Thread_local, _Atomic) */
 %token <y_tqual>       T_QUAL
 
 /* struct or union */
@@ -1099,7 +1099,13 @@
        ;
 
 type_qualifier:                        /* C99 6.7.3 */
-         T_QUAL
+         T_QUAL {
+               /* TODO: First fix c11ism, then use it here. */
+               if ($1 == ATOMIC && !allow_c11)
+                       /* '_Atomic' requires C11 or later */
+                       error(350);
+               $$ = $1;
+         }
        ;
 
 pointer:                       /* C99 6.7.5 */
diff -r 5dded4c50bd7 -r 9c1104eee610 usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Sat Jan 21 12:50:52 2023 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sat Jan 21 13:07:21 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.24 2023/01/08 14:05:02 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.25 2023/01/21 13:07:22 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.24 2023/01/08 14:05:02 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.25 2023/01/21 13:07:22 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -284,6 +284,7 @@
                "volatile",
                "restrict",
                "_Thread_local",
+               "_Atomic",
        };
 
        return name[qual];
diff -r 5dded4c50bd7 -r 9c1104eee610 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Jan 21 12:50:52 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Jan 21 13:07:21 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.303 2023/01/14 10:33:34 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.304 2023/01/21 13:07:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.303 2023/01/14 10:33:34 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.304 2023/01/21 13:07:22 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -560,7 +560,7 @@
                }
                dcs->d_volatile = true;
        } else {
-               lint_assert(q == RESTRICT || q == THREAD);
+               lint_assert(q == RESTRICT || q == THREAD || q == ATOMIC);
                /* Silently ignore these qualifiers. */
        }
 }
diff -r 5dded4c50bd7 -r 9c1104eee610 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Jan 21 12:50:52 2023 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Jan 21 13:07:21 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.185 2023/01/08 17:54:03 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.186 2023/01/21 13:07:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.185 2023/01/08 17:54:03 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.186 2023/01/21 13:07:22 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -405,6 +405,7 @@
        "redeclaration of '%s' with type '%s', expected '%s'",        /* 347 */
        "maximum value %d of '%s' does not match maximum array index %d", /* 348 */
        "non type argument to alignof is a GCC extension",            /* 349 */
+       "'_Atomic' requires C11 or later",                            /* 350 */
 };
 
 static bool    is_suppressed[sizeof(msgs) / sizeof(msgs[0])];
diff -r 5dded4c50bd7 -r 9c1104eee610 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Jan 21 12:50:52 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Jan 21 13:07:21 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.140 2023/01/21 10:18:15 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.141 2023/01/21 13:07:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.140 2023/01/21 10:18:15 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.141 2023/01/21 13:07:22 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -112,6 +112,7 @@
        kwdef_keyword(  "_Alignas",     T_ALIGNAS),
        kwdef_keyword(  "_Alignof",     T_ALIGNOF),
        kwdef_token(    "alignof",      T_ALIGNOF,              78,0,6),
+       kwdef_tqual(    "_Atomic",      ATOMIC,                 11,0,1),
        kwdef_token(    "asm",          T_ASM,                  78,1,7),
        kwdef_token(    "attribute",    T_ATTRIBUTE,            78,1,6),
        kwdef_sclass(   "auto",         AUTO,                   78,0,1),
@@ -157,6 +158,7 @@
        kwdef_keyword(  "switch",       T_SWITCH),
        kwdef_token(    "__symbolrename",       T_SYMBOLRENAME, 78,0,1),
        kwdef_tqual(    "__thread",     THREAD,                 78,1,1),
+       /* XXX: _Thread_local is a storage-class-specifier, not tqual. */
        kwdef_tqual(    "_Thread_local", THREAD,                11,0,1),
        kwdef_sclass(   "typedef",      TYPEDEF,                78,0,1),
        kwdef_token(    "typeof",       T_TYPEOF,               78,1,7),
diff -r 5dded4c50bd7 -r 9c1104eee610 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sat Jan 21 12:50:52 2023 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sat Jan 21 13:07:21 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.160 2023/01/14 10:33:34 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.161 2023/01/21 13:07:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -92,7 +92,11 @@
  * qualifiers (only for lex/yacc interface)
  */
 typedef enum {
-       CONST, VOLATILE, RESTRICT, THREAD
+       CONST,
+       VOLATILE,
+       RESTRICT,
+       THREAD,                 /* XXX: storage-class-qualifier */
+       ATOMIC,
 } tqual_t;
 
 /* An integer or floating-point value. */



Home | Main Index | Thread Index | Old Index