From 72ade848da159c4bb230b1a3f47e96dc76d55342 Mon Sep 17 00:00:00 2001 From: christos Date: Mon, 12 Apr 2021 15:55:26 +0000 Subject: [PATCH] Add attribute fallthrough --- usr.bin/xlint/lint1/cgram.y | 12 +++++++++--- usr.bin/xlint/lint1/lex.c | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y index 154b1832417a..53511e0aca3f 100644 --- a/usr.bin/xlint/lint1/cgram.y +++ b/usr.bin/xlint/lint1/cgram.y @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.211 2021/04/02 12:16:50 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.212 2021/04/12 15:55:26 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.y,v 1.211 2021/04/02 12:16:50 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.212 2021/04/12 15:55:26 christos Exp $"); #endif #include @@ -218,6 +218,7 @@ anonymize(sym_t *s) %token T_AT_CONSTRUCTOR %token T_AT_DEPRECATED %token T_AT_DESTRUCTOR +%token T_AT_FALLTHROUGH %token T_AT_FORMAT %token T_AT_FORMAT_ARG %token T_AT_FORMAT_GNU_PRINTF @@ -595,6 +596,9 @@ type_attribute_spec: | T_AT_WARN_UNUSED_RESULT | T_AT_WEAK | T_AT_VISIBILITY T_LPAREN constant_expr T_RPAREN + | T_AT_FALLTHROUGH { + fallthru(1); + } | T_QUAL { if ($1 != CONST) yyerror("Bad attribute"); @@ -1490,7 +1494,8 @@ direct_abstract_decl: ; non_expr_statement: - labeled_statement + type_attribute T_SEMI + | labeled_statement | compound_statement | selection_statement | iteration_statement @@ -1498,6 +1503,7 @@ non_expr_statement: seen_fallthrough = false; } | asm_statement + ; statement: /* C99 6.8 */ expr_statement diff --git a/usr.bin/xlint/lint1/lex.c b/usr.bin/xlint/lint1/lex.c index 350ef4796b39..d4345ffa1c0f 100644 --- a/usr.bin/xlint/lint1/lex.c +++ b/usr.bin/xlint/lint1/lex.c @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.26 2021/04/09 15:58:43 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.27 2021/04/12 15:55:26 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: lex.c,v 1.26 2021/04/09 15:58:43 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.27 2021/04/12 15:55:26 christos Exp $"); #endif #include @@ -169,6 +169,7 @@ static struct kwtab { kwdef_token( "enum", T_ENUM, 0,0,0,0,1), kwdef_token( "extension", T_EXTENSION, 0,0,1,0,4), kwdef_sclass( "extern", EXTERN, 0,0,0,0,1), + kwdef_token( "fallthrough", T_AT_FALLTHROUGH, 0,0,1,1,5), kwdef_type( "float", FLOAT, 0,0,0,0,1), kwdef_token( "for", T_FOR, 0,0,0,0,1), kwdef_token( "format", T_AT_FORMAT, 0,0,1,1,5),