From patchwork Fri Mar 31 01:44:42 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: 9655379 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 5424660113 for ; Fri, 31 Mar 2017 01:46:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 463F628617 for ; Fri, 31 Mar 2017 01:46:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B24828693; Fri, 31 Mar 2017 01:46:39 +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 D6F5128617 for ; Fri, 31 Mar 2017 01:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934792AbdCaBqj (ORCPT ); Thu, 30 Mar 2017 21:46:39 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:36001 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934785AbdCaBqh (ORCPT ); Thu, 30 Mar 2017 21:46:37 -0400 Received: by mail-wr0-f193.google.com with SMTP id k6so15309732wre.3 for ; Thu, 30 Mar 2017 18:46:36 -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=VYztkduvDAC8g01SuNftp7GuXQJ2xMo5WquWH3P1BBE=; b=YJC9KvDI4vT1FLzCQQYoVyoMSpSTdrmIdrO2x78c4Qk2mRS77UjRJP40cGILRGPFMH w3nCep9qj5KlHuhkX7M/MzevcwZW2Ra9Rba5WETidybn/rhczrbnVhLb8rMvS16ZBKQH qNGBmwG2evtChBqm7o0elSdlMTgSX+1B6uwrebYYE/4vEsRQBRZ+/J3vqkcSUaQL4MJ2 iuqIow3WCr77SPUyZqqzOl41myCGduhzv3BZsmIG/hVRE4YLrPMlrfCxEjux94l+lJHq k588JWxDOEbMW3z/oZVdMGaO/AQ7hzKTW2rn6r/r4ca+zbaHp//zq4G1mcL2EQr3Rq74 KMNQ== 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=VYztkduvDAC8g01SuNftp7GuXQJ2xMo5WquWH3P1BBE=; b=O2bzRv5Nl4vqE7bPZfN3xpp2PvRim/PFseq70gVs1OBimQscLtkEZ8zXZeGXQbHrTN /9PNUTjLE5O9Edu6dP7X5qMr5rW7+/U3RWVEM+MRMUZMDw1L0Voqv1FlKy2GpJNVtXe8 OC7MTKZXAqCcn8QyRiZQqnMH+z2XtEno3DsEIq3o3buP/+i89kVulcO6J8/n7FiMnR2U u6sdJL/ld7IHYLrVvZTniw7aCEB75+PqBwlB08ufnexNMYMFt7g4e6bCgw6soTS+2zZ6 jjR3hV+0vpJ4hbEZagwhhTtXlaOxpWZdpJr8g/W8Lwv7IDr2z/RVX6ig3BbTtfFUh1JK mJOw== X-Gm-Message-State: AFeK/H3i8J6IZKcpQU1tmeO9Df1lj4HxEYJM9r2MMjclYflYg3nv01JSn/rgk89IRO5dBA== X-Received: by 10.223.161.70 with SMTP id r6mr320454wrr.65.1490924795483; Thu, 30 Mar 2017 18:46:35 -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.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 18:46:34 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Nicolai Stange , Luc Van Oostenryck Subject: [PATCH v4 08/25] constexpr: add support for tagging address constants Date: Fri, 31 Mar 2017 03:44:42 +0200 Message-Id: <20170331014459.9351-9-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 Address constants [6.6(9)] constitute one of the types of constant expressions allowed in initializers [6.6(7)] for static storage duration objects [6.7.8(4)]. Introduce a new flag for tagging expressions which qualify as being an address constant. Make sure not to carry over the address constant attribute from subexpressions for operators that never yield address constants, i.e. most arithmetic ones, logical ones etc. Signed-off-by: Nicolai Stange Signed-off-by: Luc Van Oostenryck --- evaluate.c | 19 ++++++++++++++++++- expression.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/evaluate.c b/evaluate.c index 6d6e462cd..68a2d5ebf 100644 --- a/evaluate.c +++ b/evaluate.c @@ -890,7 +890,7 @@ static struct symbol *evaluate_logical(struct expression *expr) /* the result is int [6.5.13(3), 6.5.14(3)] */ expr->ctype = &int_ctype; expr->flags = expr->left->flags & expr->right->flags; - expr->flags &= ~CEF_CONST_MASK; + expr->flags &= ~(CEF_CONST_MASK | CEF_ADDR); return &int_ctype; } @@ -1007,6 +1007,7 @@ static struct symbol *evaluate_compare(struct expression *expr) 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)) @@ -1124,6 +1125,11 @@ static struct symbol *evaluate_conditional_expression(struct expression *expr) expr->flags = (expr->conditional->flags & (*true)->flags & expr->cond_false->flags & ~CEF_CONST_MASK); + /* + * A conditional operator never yields an address constant + * [6.6(9)]. + */ + expr->flags &= ~CEF_ADDR; lclass = classify_type(ltype, <ype); rclass = classify_type(rtype, &rtype); @@ -1858,6 +1864,12 @@ static struct symbol *evaluate_preop(struct expression *expr) case '!': expr->flags = expr->unop->flags & ~CEF_CONST_MASK; + /* + * A logical negation never yields an address constant + * [6.6(9)]. + */ + expr->flags &= ~CEF_ADDR; + if (is_safe_type(ctype)) warning(expr->pos, "testing a 'safe expression'"); if (is_float_type(ctype)) { @@ -2719,6 +2731,11 @@ static int cast_flags(struct expression *expr, struct expression *old) class = classify_type(expr->ctype, &t); if (class & TYPE_NUM) { flags = old->flags & ~CEF_CONST_MASK; + /* + * Casts to numeric types never result in address + * constants [6.6(9)]. + */ + flags &= ~CEF_ADDR; /* * Cast to float type -> not an integer constant * expression [6.6(6)]. diff --git a/expression.h b/expression.h index 67b6a83e3..960f16005 100644 --- a/expression.h +++ b/expression.h @@ -97,9 +97,11 @@ enum constexpr_flag { * A constant expression in the sense of [6.6]: * - integer constant expression [6.6(6)] * - arithmetic constant expression [6.6(8)] + * - address constant [6.6(9)] */ CEF_ICE = (1 << 4), CEF_ACE = (1 << 5), + CEF_ADDR = (1 << 6), /* integer constant expression => arithmetic constant expression */ CEF_SET_ICE = (CEF_ICE | CEF_ACE),