From patchwork Fri Mar 31 01:44:39 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: 9655373 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 D6EB060113 for ; Fri, 31 Mar 2017 01:46:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C91FA28617 for ; Fri, 31 Mar 2017 01:46:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDC9428688; Fri, 31 Mar 2017 01:46:35 +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 5D4E428696 for ; Fri, 31 Mar 2017 01:46:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934742AbdCaBqf (ORCPT ); Thu, 30 Mar 2017 21:46:35 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35127 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934847AbdCaBqe (ORCPT ); Thu, 30 Mar 2017 21:46:34 -0400 Received: by mail-wr0-f196.google.com with SMTP id p52so16621170wrc.2 for ; Thu, 30 Mar 2017 18:46:33 -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=2hHGY1xXFWJ2ZybNhjaN6bOL8fOUQIqi9P4fS51vodM=; b=Ofx2fm3EbVXllWFiDUAt/zhuRJgkQ/Cu+52QCpulA2sQdM4E+qLBRS1tn2nhf3kuO+ 81QrxbLGV6LvK6VLO759bL4s09O3pUkp8yxZYVQdE5ibpbDqnN0EoLNiUrrGYcwY+gk5 XMA+MrenBAB5UbvA4jhP9AGqLU4MYvKFfgj/h9dAdJJqk55ceHX6Cy+iHKKA/dM1YAaF Fo9uetP8RaqOhAZQzkz0MVfyB8iWWIGF6LozS6+Rk311wbvcG0Hm9LDV1bT9RQiLIzZZ dfTVmt750aBGrO2erzW00ZU2pIMfWbt/MqgjHz/dgnWxYVcagFG/6r3w8FgKYVBgdtls 8PBQ== 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=2hHGY1xXFWJ2ZybNhjaN6bOL8fOUQIqi9P4fS51vodM=; b=tA8bHpQIOjIOKHCTY/p/Fwt/WYj3E6px2v5Guy5rc36YuKU+CpdnQGSLokFvfakEQ9 fj6fOSWBRr5cGE0Q6o1F1qdqGNP8AFt5xp1d5wFPBCLoN7CWvDmcMRLX/NXsV1X/cc8h zSzkweGTlTWg1iNG9DT3y2r7UN8gvS2kx0XTSOF1bM699PV10JDberpFP0HHiFChK3U9 7FrLZKHOHa53Or3Gjk9IIMBInuEhvIwe5YChzjiJUBhOXay+IyrYCzw3NZmgmfUDo9RD XAHYZm7XGv7ij7D6shYq2Enbnetunle0MWAtAne+IcJvou1fI2GErihcTAAbd6mXSw3I phzA== X-Gm-Message-State: AFeK/H0EIG0j6yLlXYGT3TrJ3m3vbUxuo6T7mUefQV/jHmY8nPqBpnQP3B38cJNMJX+AYw== X-Received: by 10.223.143.53 with SMTP id p50mr344985wrb.2.1490924792362; Thu, 30 Mar 2017 18:46:32 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 18:46:31 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Nicolai Stange , Luc Van Oostenryck Subject: [PATCH v4 05/25] constexpr: examine constness of preops at evaluation only Date: Fri, 31 Mar 2017 03:44:39 +0200 Message-Id: <20170331014459.9351-6-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 prefix expressions' constness flags to the evaluation phase such that expressions like -__builtin_choose_expr(0, 0, 0) ~__builtin_choose_expr(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 | 3 --- validation/constexpr-preop.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 validation/constexpr-preop.c diff --git a/evaluate.c b/evaluate.c index 48530f28c..07788eacc 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1805,8 +1805,8 @@ static struct symbol *evaluate_sign(struct expression *expr) { struct symbol *ctype = expr->unop->ctype; int class = classify_type(ctype, &ctype); - if (expr->flags && !(expr->unop->flags & CEF_ICE)) - expr->flags = CEF_NONE; + unsigned char flags = expr->unop->flags & ~CEF_CONST_MASK; + /* should be an arithmetic type */ if (!(class & TYPE_NUM)) return bad_expr_type(expr); @@ -1823,6 +1823,7 @@ Normal: } if (expr->op == '+') *expr = *expr->unop; + expr->flags = flags; expr->ctype = ctype; return ctype; Restr: @@ -1860,8 +1861,7 @@ static struct symbol *evaluate_preop(struct expression *expr) return evaluate_postop(expr); case '!': - if (expr->flags && !(expr->unop->flags & CEF_ICE)) - expr->flags = CEF_NONE; + expr->flags = expr->unop->flags & ~CEF_CONST_MASK; if (is_safe_type(ctype)) warning(expr->pos, "testing a 'safe expression'"); if (is_float_type(ctype)) { diff --git a/expression.c b/expression.c index b59af8886..0332c4406 100644 --- a/expression.c +++ b/expression.c @@ -450,8 +450,6 @@ struct token *primary_expression(struct token *token, struct expression **tree) expr = alloc_expression(token->pos, EXPR_PREOP); expr->op = '('; token = parens_expression(token, &expr->unop, "in expression"); - if (expr->unop) - expr->flags = expr->unop->flags; break; } if (token->special == '[' && lookup_type(token->next)) { @@ -663,7 +661,6 @@ static struct token *unary_expression(struct token *token, struct expression **t unary = alloc_expression(token->pos, EXPR_PREOP); unary->op = token->special; unary->unop = unop; - unary->flags = unop->flags & ~CEF_CONST_MASK; *tree = unary; return next; } diff --git a/validation/constexpr-preop.c b/validation/constexpr-preop.c new file mode 100644 index 000000000..5d869da4f --- /dev/null +++ b/validation/constexpr-preop.c @@ -0,0 +1,29 @@ +static int a[] = { + [+0] = 0, // OK + [+__builtin_choose_expr(0, 0, 0)] = 0, // OK + [+0.] = 0, // KO + [+__builtin_choose_expr(0, 0, 0.)] = 0, // KO + [-0] = 0, // OK + [-__builtin_choose_expr(0, 0, 0)] = 0, // OK + [-0.] = 0, // KO + [-__builtin_choose_expr(0, 0, 0.)] = 0, // KO + [~0] = 0, // OK + [~__builtin_choose_expr(0, 0, 0)] = 0, // OK + [!0] = 0, // OK + [!__builtin_choose_expr(0, 0, 0)] = 0, // OK + [!0.] = 0, // KO + [!__builtin_choose_expr(0, 0, 0.)] = 0, // KO +}; + +/* + * check-name: Expression constness propagation in preops + * + * check-error-start +constexpr-preop.c:4:5: error: bad constant expression +constexpr-preop.c:5:33: error: bad constant expression +constexpr-preop.c:8:4: error: bad constant expression +constexpr-preop.c:9:4: error: bad constant expression +constexpr-preop.c:14:4: error: bad integer constant expression +constexpr-preop.c:15:4: error: bad integer constant expression + * check-error-end + */