From patchwork Wed Feb 21 22:39:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 10234229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89DE0602A7 for ; Wed, 21 Feb 2018 22:39:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79EA9285CC for ; Wed, 21 Feb 2018 22:39:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E938285D2; Wed, 21 Feb 2018 22:39:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FE7C285CC for ; Wed, 21 Feb 2018 22:39:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751578AbeBUWjV (ORCPT ); Wed, 21 Feb 2018 17:39:21 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33655 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751571AbeBUWjS (ORCPT ); Wed, 21 Feb 2018 17:39:18 -0500 Received: by mail-wr0-f193.google.com with SMTP id s5so8681038wra.0 for ; Wed, 21 Feb 2018 14:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fH8wfvt/DMptvP9ClnBjEmFbfmUt3BngS+IADPI+0bU=; b=X34ENA8gqCZZXigxfnLMVgryjvFaHHj4MTRLlux1X/zcBWF/kBiwb27f73px2kUPSu TgKfMzzpZD/eIZA8e0RMBhDuEKnXBNjkQ5aNNxZ4ht+Sdl6hY0oyiWf34qA82TmQDpuF WReg+/yjyL2g+nKnpIRif7C8qXpzY3aA7/nC86eKt8+rhC1+jrGRgZHFLmLg89lGMsAl h3vPJQNm0o7PumAVaTG2B3Xui8NCgXuyaLpbsGTHD17TChN5vNNyrrdkzVy65okWhRkN N7PonNBmUTHvLe4Gt8vVM/RMkDkq7qVBufTVs66sxSKVnzpW64G8/MNYIa/oh76Y7nsh MVug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fH8wfvt/DMptvP9ClnBjEmFbfmUt3BngS+IADPI+0bU=; b=WgpjEKehZUUgOO4No+uGEXklr/LczPzL3f+DzMffUlZR9ejKA8Z1PrVe0UZJdYWCR6 KwQKgf3CXOmFIJHQjz7oh9jSwmRJv5zyolwLBtxgR6AYZJVx37XwYzFyQs9xNClUWyVw +1X25AtQSL4HKyFoUBTc6EtHDryNq2tykTTj3ZDZXOauJwTjCGdmk4T/r9h5W/eV72zb kYcwl9ZPeNAN0MBcusdUAfqp2VtC/NCSz7xi2vY20BxT9OPd2DEdB1jiHAel+0tZyEVo 42gL9NoY37tmSQrzLSL/dJVH9hJJMUqOmcm2xpn5PErsvTULNSrW+utT8gfvKpVOOPGr ndTg== X-Gm-Message-State: APf1xPBnbysG37jDgYAJTGsJ0yX8Ge4fO70w85cUE6eCexfgwc6O4LhK Q3+yIzKk4pfSia84OhRLy9ROTc3s X-Google-Smtp-Source: AH8x226buAi/VUPQRCW2xt0M5UCWGNHfCCOGNYDQ/ipqbxqUwr+HtAp5Z3ShawVkcN3u3cUi3slEDg== X-Received: by 10.223.134.68 with SMTP id 4mr4358906wrw.218.1519252756758; Wed, 21 Feb 2018 14:39:16 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:4007:e500:2180:98d9:8767:4b14]) by smtp.gmail.com with ESMTPSA id v17sm489433wrd.5.2018.02.21.14.39.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 14:39:16 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds , Matthew Wilcox , Al Viro , Luc Van Oostenryck Subject: [PATCH 3/3] teach sparse about restricted enums Date: Wed, 21 Feb 2018 23:39:08 +0100 Message-Id: <20180221223908.38904-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180221223908.38904-1-luc.vanoostenryck@gmail.com> References: <20180221223908.38904-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Too ugly to describe. Signed-off-by: Luc Van Oostenryck --- parse.c | 20 +++++++++++++++++--- validation/enum-restricted.c | 1 - 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/parse.c b/parse.c index ce96289c5..b58ae0a3f 100644 --- a/parse.c +++ b/parse.c @@ -696,10 +696,11 @@ static struct token *struct_union_enum_specifier(enum type type, struct token *token, struct decl_state *ctx, struct token *(*parse)(struct token *, struct symbol *)) { + struct decl_state type_attr = { }; struct symbol *sym; struct position *repos; - token = handle_attributes(token, ctx, KW_ATTRIBUTE); + token = handle_attributes(token, &type_attr, KW_ATTRIBUTE); if (token_type(token) == TOKEN_IDENT) { sym = lookup_symbol(token->ident, NS_STRUCT); if (!sym || @@ -712,6 +713,12 @@ static struct token *struct_union_enum_specifier(enum type type, } if (sym->type != type) error_die(token->pos, "invalid tag applied to %s", show_typename (sym)); + + // FIXME: should apply all modifiers + type_attr.ctype.base_type = sym; + if (type == SYM_ENUM) // FIXME: see is_int_type() + sym->ctype.base_type = &int_ctype; + sym = apply_bitwise(token->pos, &type_attr.ctype); ctx->ctype.base_type = sym; repos = &token->pos; token = token->next; @@ -860,8 +867,11 @@ static struct token *parse_enum_declaration(struct token *token, struct symbol * struct symbol *ctype = NULL, *base_type = NULL; Num upper = {-1, 0}, lower = {1, 0}; - parent->examined = 1; - parent->ctype.base_type = &int_ctype; + if (parent->type == SYM_RESTRICT) + parent->ctype.base_type->ctype.base_type = &int_ctype; + else + parent->ctype.base_type = &int_ctype; + examine_symbol_type(parent); while (token_type(token) == TOKEN_IDENT) { struct expression *expr = NULL; struct token *next = token->next; @@ -886,6 +896,8 @@ static struct token *parse_enum_declaration(struct token *token, struct symbol * expr->value = lastval; expr->ctype = ctype; } + if (parent->type == SYM_RESTRICT) + expr->ctype = parent; sym = alloc_symbol(token->pos, SYM_NODE); bind_symbol(sym, token->ident, NS_SYMBOL); @@ -898,6 +910,8 @@ static struct token *parse_enum_declaration(struct token *token, struct symbol * if (base_type != &bad_ctype) { if (ctype->type == SYM_NODE) ctype = ctype->ctype.base_type; + if (ctype->type == SYM_RESTRICT) + ctype = ctype->ctype.base_type; if (ctype->type == SYM_ENUM) { if (ctype == parent) ctype = base_type; diff --git a/validation/enum-restricted.c b/validation/enum-restricted.c index b58964172..39fd90673 100644 --- a/validation/enum-restricted.c +++ b/validation/enum-restricted.c @@ -18,5 +18,4 @@ static void foo(void) /* * check-name: enum-restricted - * check-known-to-fail */