From patchwork Fri Mar 31 01:44:40 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: 9655375 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 69F3A60113 for ; Fri, 31 Mar 2017 01:46:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BFBB28617 for ; Fri, 31 Mar 2017 01:46:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50D8128693; Fri, 31 Mar 2017 01:46:37 +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 E782428617 for ; Fri, 31 Mar 2017 01:46:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934877AbdCaBqg (ORCPT ); Thu, 30 Mar 2017 21:46:36 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35985 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934785AbdCaBqf (ORCPT ); Thu, 30 Mar 2017 21:46:35 -0400 Received: by mail-wr0-f194.google.com with SMTP id k6so15309644wre.3 for ; Thu, 30 Mar 2017 18:46:34 -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=ELbIt2LpzpcajFSS8vNW/Zc9LoMRPOYFCWKmDH9Apj0=; b=XcculQD64eyxOTNLuxWoHWthdzeUz0qmLJ5O2+kBqc4wJEPfkmAzc/wnMXmwYsuBY2 bb/ETu5EJqRgvVRptihayQJ7fdOBnY1+U62SMOMe2RgF5XWFy4izr70fuAndvtGHLcDo GlfbOwOV7DjNHl6Qf9szYFEf8CY96td8I6tPgqL4uXGXiZFkPTBQbfVbJ4fChvBR8zCs SCIvFM2A+gbKwTYvR6SfgSxEDgY5HcgB4Df7xhfA+yrysAWSf0iAD+8olQSk9ZBEbUC2 nM7jiqn+kgsAQ41+2M9ZcoqIuEzK8xQDZ/puvRxcQmxTPyzMRKTCtesWDOVBXqB/WTr6 XRjA== 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=ELbIt2LpzpcajFSS8vNW/Zc9LoMRPOYFCWKmDH9Apj0=; b=juq2e+cnrLbrAtMl1/hhtR3tknwn0TpYTHAVT9jDCw5yXqWDcdOKjriVrmyL6phqPQ 3sJfiK5zdvxM3D0vG/OeQkdNF4TJLuWFocaSRaETIO2bP+ECTcB9q72THZ56018+BQc6 MvNC5MgVM0wkLHatE8OzKabYIyM1TGQz/QSz+YXpCkTWaQx9a4Jvpgle3fx/OJl+bD2H 1mZoUZQjHEPAHSHlXza/0vnIoeQcIKWcnVC9sL1Z4+vQLbMQx2OzqcweKEMPt0uv6YE4 P8Ma1o2w1GrBK+sDaHu9LlZH9G9LSp71ABrQZgLB1b3riVYHn3Zt/L31lKee7WSApZdQ L54w== X-Gm-Message-State: AFeK/H2Rvou/epp+dXMrGt7en+bv05TMdfV1NLsXNwkgc0jVLciBpI7nKTe476hOJ8YwsQ== X-Received: by 10.223.165.66 with SMTP id j2mr354646wrb.157.1490924793329; Thu, 30 Mar 2017 18:46:33 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 18:46:32 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Nicolai Stange , Luc Van Oostenryck Subject: [PATCH v4 06/25] constexpr: examine constness of conditionals at evaluation only Date: Fri, 31 Mar 2017 03:44:40 +0200 Message-Id: <20170331014459.9351-7-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 Move the whole calculation of conditional expressions' constness flags to the evaluation phase such that expressions like 0 ? __builtin_choose_expr(0, 0, 0) : 0 0 ? 0 : __builtin_choose_expr(0, 0, 0) can now be recognized as qualifying as integer constant expressions. Signed-off-by: Nicolai Stange Signed-off-by: Luc Van Oostenryck --- evaluate.c | 8 ++------ expression.c | 6 ------ validation/constexpr-conditional.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 validation/constexpr-conditional.c diff --git a/evaluate.c b/evaluate.c index 07788eacc..6d6e462cd 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1122,12 +1122,8 @@ static struct symbol *evaluate_conditional_expression(struct expression *expr) true = &expr->cond_true; } - if (expr->flags) { - int flags = expr->conditional->flags & CEF_ICE; - flags &= (*true)->flags & expr->cond_false->flags; - if (!flags) - expr->flags = CEF_NONE; - } + expr->flags = (expr->conditional->flags & (*true)->flags & + expr->cond_false->flags & ~CEF_CONST_MASK); lclass = classify_type(ltype, <ype); rclass = classify_type(rtype, &rtype); diff --git a/expression.c b/expression.c index 0332c4406..7f1eff306 100644 --- a/expression.c +++ b/expression.c @@ -856,12 +856,6 @@ struct token *conditional_expression(struct token *token, struct expression **tr token = parse_expression(token->next, &expr->cond_true); token = expect(token, ':', "in conditional expression"); token = conditional_expression(token, &expr->cond_false); - if (expr->left && expr->cond_false) { - expr->flags = expr->left->flags & expr->cond_false->flags; - if (expr->cond_true) - expr->flags &= expr->cond_true->flags; - expr->flags &= ~CEF_CONST_MASK; - } } return token; } diff --git a/validation/constexpr-conditional.c b/validation/constexpr-conditional.c new file mode 100644 index 000000000..a3331b3ef --- /dev/null +++ b/validation/constexpr-conditional.c @@ -0,0 +1,34 @@ +static int a[] = { + [0 ? : 0] = 0, // OK + [1 ? : 0] = 0, // OK + [0 ? 0 : 0] = 0, // OK + [1 ? 0 : 0] = 0, // OK + [0 ? 0 : __builtin_choose_expr(0, 0, 0)] = 0, // OK + [1 ? __builtin_choose_expr(0, 0, 0) : 0] = 0, // OK + [0 ? __builtin_choose_expr(0, 0, 0) : 0] = 0, // OK + [1 ? 1 : __builtin_choose_expr(0, 0, 0)] = 0, // OK + [__builtin_choose_expr(0, 0, 0) ? : 0] = 0, // OK + [__builtin_choose_expr(0, 0, 1) ? : 0] = 0, // OK + [0. ? : 0] = 0, // KO + [0 ? 0. : 0] = 0, // KO + [1 ? : 0.] = 0, // KO + [__builtin_choose_expr(0, 0., 0) ? : 0] = 0, // OK + [__builtin_choose_expr(0, 0, 0.) ? : 0] = 0, // KO + [0 ? __builtin_choose_expr(0, 0., 0) : 0] = 0, // OK + [0 ? __builtin_choose_expr(0, 0, 0.) : 0] = 0, // KO + [1 ? 0 : __builtin_choose_expr(0, 0., 0)] = 0, // OK + [1 ? 0 : __builtin_choose_expr(0, 0, 0.)] = 0, // KO +}; + +/* + * check-name: Expression constness propagation in conditional expressions + * + * check-error-start +constexpr-conditional.c:12:13: error: bad constant expression +constexpr-conditional.c:13:19: error: bad constant expression +constexpr-conditional.c:14:12: error: bad constant expression +constexpr-conditional.c:16:42: error: bad constant expression +constexpr-conditional.c:18:48: error: bad constant expression +constexpr-conditional.c:20:14: error: bad constant expression + * check-error-end + */