From patchwork Fri Mar 31 01:44:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9655407 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 4410C60352 for ; Fri, 31 Mar 2017 01:46:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3623328688 for ; Fri, 31 Mar 2017 01:46:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B36F28693; Fri, 31 Mar 2017 01:46:53 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 C2CAD28696 for ; Fri, 31 Mar 2017 01:46:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934889AbdCaBqw (ORCPT ); Thu, 30 Mar 2017 21:46:52 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33376 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935019AbdCaBqv (ORCPT ); Thu, 30 Mar 2017 21:46:51 -0400 Received: by mail-wr0-f195.google.com with SMTP id u18so16611859wrc.0 for ; Thu, 30 Mar 2017 18:46:49 -0700 (PDT) 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=PgMHpspfI3zldj3L9TdL/BPcgrfVc8s3h1hYq6XaQ5M=; b=I31dxyB7nrhgndbzQlkchdNBpg15gH9zBYv0C+bll5pc47SKHfbUHbIWRXMTgtjBm6 S4QI2e+NXxZ3mMYExVTVbyoYSACY9NjNc6U/LEVQt3D4gKuXErTsTtWoXXiyOBjQxA6K 5dwEAJKlqNwsnb+aPoimF8rcv5xnjuqmcOskQY7K4ipT0siJk5Nux32weE02xi/P2GAF PP/qBDib3KIlDTT5PXfSCM5KHNTuxaWBZLOK95nyC5RmjV0MENCqgAflx26oBa2r0x/L bK/dbRES7Yn1BWbZ7rQ2gPHnMBnIh7GIT/dziKzND1Jq75SrRMfhdYD/JTcjpCy9hrgw mdwg== 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=PgMHpspfI3zldj3L9TdL/BPcgrfVc8s3h1hYq6XaQ5M=; b=YyYKTCe2uTauCZ33PN77A9DOqmVzorMnAEC0stN0mZcUu+RLfQcuCeee47lGZJAu4j bt20rKQkl8gSDwyApXVL9ewZyS8kiFhisy645mZprqWra+YqVAiMKL09duxlr3Ike1QI o3j5JDVzuBC9Imz9hs9HPVswAYLUjnH4P5MXOIh/re79NBt/LDMBVRlV8dCskfKbqUf9 TCQYoin+vubyekb0RyxAxBglVMHgwNEZwDqeGaSC7yp+uHicB44mY5bZOpqjAy9zKiMe +SJ+0vDUWH8zweWyjUmzE9FTE8ukKRb3eEVlH6Pq51IvL6+n/suvx5gr+twlOy+0lpzW Op0A== X-Gm-Message-State: AFeK/H2VH0lTvK5Qt87ukVSuxqRJK+R+4P+xrBVjTL3kpv6WQ5jr75cZba7Z3zNf8/S5SQ== X-Received: by 10.28.26.69 with SMTP id a66mr772036wma.88.1490924808958; Thu, 30 Mar 2017 18:46:48 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:88d:1900:cdad:92b8:5279:ae19]) by smtp.gmail.com with ESMTPSA id 189sm917023wmm.31.2017.03.30.18.46.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 18:46:48 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Nicolai Stange , Luc Van Oostenryck Subject: [PATCH v4 22/25] constexpr: treat comparisons between types as integer constexpr Date: Fri, 31 Mar 2017 03:44:56 +0200 Message-Id: <20170331014459.9351-23-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170331014459.9351-1-luc.vanoostenryck@gmail.com> References: <20170331014459.9351-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 From: Nicolai Stange The expression parsing code builds an EXPR_COMPARE expression around two EXPR_TYPE expressions for __builtin_types_compatible_p(). The EXPR_TYPE expressions are tagged as being integer constant expressions in order to trick the generic comparison evaluation code into flagging the result as an integer constant expression again. Avoid this trickery by making evaluate_compare() unconditionally tag a comparison between types as an integer constant expression. Signed-off-by: Nicolai Stange Signed-off-by: Luc Van Oostenryck --- evaluate.c | 13 +++++++++---- expression.c | 3 --- validation/constexpr-types-compatible-p.c | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 validation/constexpr-types-compatible-p.c diff --git a/evaluate.c b/evaluate.c index 1ae370c7b..46ea10ed8 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1016,16 +1016,21 @@ static struct symbol *evaluate_compare(struct expression *expr) struct symbol *ctype; const char *typediff; - expr->flags = left->flags & right->flags & ~CEF_CONST_MASK; - expr->flags &= ~CEF_ADDR; - /* Type types? */ - if (is_type_type(ltype) && is_type_type(rtype)) + if (is_type_type(ltype) && is_type_type(rtype)) { + /* + * __builtin_types_compatible_p() yields an integer + * constant expression + */ + expr->flags = CEF_SET_ICE; goto OK; + } if (is_safe_type(left->ctype) || is_safe_type(right->ctype)) warning(expr->pos, "testing a 'safe expression'"); + expr->flags = left->flags & right->flags & ~CEF_CONST_MASK & ~CEF_ADDR; + /* number on number */ if (lclass & rclass & TYPE_NUM) { ctype = usual_conversions(expr->op, expr->left, expr->right, diff --git a/expression.c b/expression.c index e4b770fc0..e5ebad65b 100644 --- a/expression.c +++ b/expression.c @@ -131,7 +131,6 @@ static struct token *parse_type(struct token *token, struct expression **tree) { struct symbol *sym; *tree = alloc_expression(token->pos, EXPR_TYPE); - (*tree)->flags = CEF_SET_ICE; /* sic */ token = typename(token, &sym, NULL); if (sym->ident) sparse_error(token->pos, @@ -459,8 +458,6 @@ struct token *primary_expression(struct token *token, struct expression **tree) } if (token->special == '[' && lookup_type(token->next)) { expr = alloc_expression(token->pos, EXPR_TYPE); - /* sic */ - expr->flags = CEF_SET_ICE; token = typename(token->next, &expr->symbol, NULL); token = expect(token, ']', "in type expression"); break; diff --git a/validation/constexpr-types-compatible-p.c b/validation/constexpr-types-compatible-p.c new file mode 100644 index 000000000..1969bf3bd --- /dev/null +++ b/validation/constexpr-types-compatible-p.c @@ -0,0 +1,8 @@ +static int a[] = {[__builtin_types_compatible_p(int, int)] = 0}; + +/* + * check-name: __builtin_types_compatible_p() constness verification. + * + * check-error-start + * check-error-end + */