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 '_Atomic' as a...
details: https://anonhg.NetBSD.org/src/rev/9eb91595acfc
branches: trunk
changeset: 373151:9eb91595acfc
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jan 21 13:48:40 2023 +0000
description:
lint: add support for C11 '_Atomic' as atomic-type-specifier
Following the C11 grammar, the keyword '_Atomic' needs to be a separate
syntactic category, to avoid further conflicts in the grammar.
The two newly added conflicts in the grammar would come into play when
mixing traditional C with C11, in a type name without an implicit 'int'.
If the type '_Atomic(int)*' were parsed as '_Atomic int(int)*', the
trailing '*' would be a syntax error.
diffstat:
tests/usr.bin/xlint/lint1/c11_atomic.c | 11 +++++++++--
tests/usr.bin/xlint/lint1/c99_atomic.c | 12 +++++++++++-
usr.bin/xlint/lint1/cgram.y | 30 +++++++++++++++++++++++-------
usr.bin/xlint/lint1/lex.c | 6 +++---
4 files changed, 46 insertions(+), 13 deletions(-)
diffs (163 lines):
diff -r 9c1104eee610 -r 9eb91595acfc tests/usr.bin/xlint/lint1/c11_atomic.c
--- a/tests/usr.bin/xlint/lint1/c11_atomic.c Sat Jan 21 13:07:21 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_atomic.c Sat Jan 21 13:48:40 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: c11_atomic.c,v 1.2 2023/01/21 13:07:22 rillig Exp $ */
+/* $NetBSD: c11_atomic.c,v 1.3 2023/01/21 13:48:40 rillig Exp $ */
# 3 "c11_atomic.c"
/*
@@ -19,4 +19,11 @@
int field;
} atomic_struct;
-/* TODO: C11 6.7.2.4 "Atomic type specifiers" */
+/* C11 6.7.2.4 "Atomic type specifiers" */
+double *
+atomic_ptr_cmpexch(_Atomic(double *)*ptr_var, _Atomic(double *) new_value)
+{
+ double *old = *ptr_var;
+ *ptr_var = new_value;
+ return old;
+}
diff -r 9c1104eee610 -r 9eb91595acfc tests/usr.bin/xlint/lint1/c99_atomic.c
--- a/tests/usr.bin/xlint/lint1/c99_atomic.c Sat Jan 21 13:07:21 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/c99_atomic.c Sat Jan 21 13:48:40 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: c99_atomic.c,v 1.2 2023/01/21 13:07:22 rillig Exp $ */
+/* $NetBSD: c99_atomic.c,v 1.3 2023/01/21 13:48:40 rillig Exp $ */
# 3 "c99_atomic.c"
/*
@@ -13,3 +13,13 @@
typedef _Atomic struct {
int field;
} atomic_struct;
+
+/* expect+3: error: '_Atomic' requires C11 or later [350] */
+/* expect+2: error: '_Atomic' requires C11 or later [350] */
+double *
+atomic_ptr_cmpexch(_Atomic(double *)*ptr_var, _Atomic(double *) new_value)
+{
+ double *old = *ptr_var;
+ *ptr_var = new_value;
+ return old;
+}
diff -r 9c1104eee610 -r 9eb91595acfc usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Sat Jan 21 13:07:21 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Sat Jan 21 13:48:40 2023 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.430 2023/01/21 13:07:22 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.431 2023/01/21 13:48:40 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.430 2023/01/21 13:07:22 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.431 2023/01/21 13:48:40 rillig Exp $");
#endif
#include <limits.h>
@@ -143,7 +143,7 @@
%}
-%expect 129
+%expect 131
%union {
val_t *y_val;
@@ -206,8 +206,9 @@
*/
%token <y_tspec> T_TYPE
-/* qualifiers (const, volatile, restrict, _Thread_local, _Atomic) */
+/* qualifiers (const, volatile, restrict, _Thread_local) */
%token <y_tqual> T_QUAL
+%token <y_tqual> T_ATOMIC
/* struct or union */
%token <y_tspec> T_STRUCT_OR_UNION
@@ -276,6 +277,7 @@
%type <y_type> begin_type_typespec
%type <y_type> type_specifier
%type <y_type> notype_type_specifier
+%type <y_type> atomic_type_specifier
%type <y_type> struct_or_union_specifier
%type <y_tspec> struct_or_union
%type <y_sym> braced_struct_declaration_list
@@ -854,6 +856,7 @@
$$ = $3 != NULL ? block_dup_type($3->tn_type) : gettyp(INT);
$$->t_typeof = true;
}
+ | atomic_type_specifier
| struct_or_union_specifier {
end_declaration_level();
$$ = $1;
@@ -864,6 +867,13 @@
}
;
+/* K&R ---, C90 ---, C99 ---, C11 6.7.2.4 */
+atomic_type_specifier:
+ atomic T_LPAREN type_name T_RPAREN {
+ $$ = $3;
+ }
+ ;
+
struct_or_union_specifier: /* C99 6.7.2.1 */
struct_or_union identifier_sym {
/*
@@ -1099,12 +1109,18 @@
;
type_qualifier: /* C99 6.7.3 */
- T_QUAL {
+ T_QUAL
+ | atomic {
+ $$ = ATOMIC;
+ }
+ ;
+
+atomic: /* helper */
+ T_ATOMIC {
/* TODO: First fix c11ism, then use it here. */
- if ($1 == ATOMIC && !allow_c11)
+ if (!allow_c11)
/* '_Atomic' requires C11 or later */
error(350);
- $$ = $1;
}
;
diff -r 9c1104eee610 -r 9eb91595acfc usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Jan 21 13:07:21 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Jan 21 13:48:40 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.141 2023/01/21 13:07:22 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.142 2023/01/21 13:48:40 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.141 2023/01/21 13:07:22 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.142 2023/01/21 13:48:40 rillig Exp $");
#endif
#include <ctype.h>
@@ -112,7 +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( "_Atomic", T_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),
Home |
Main Index |
Thread Index |
Old Index