From patchwork Fri Mar 31 01:44:49 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: 9655393 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 18A6F60113 for ; Fri, 31 Mar 2017 01:46:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B29128688 for ; Fri, 31 Mar 2017 01:46:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 000AE28696; Fri, 31 Mar 2017 01:46:44 +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 A7EC428688 for ; Fri, 31 Mar 2017 01:46:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935028AbdCaBqo (ORCPT ); Thu, 30 Mar 2017 21:46:44 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35202 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935019AbdCaBqo (ORCPT ); Thu, 30 Mar 2017 21:46:44 -0400 Received: by mail-wr0-f194.google.com with SMTP id p52so16621606wrc.2 for ; Thu, 30 Mar 2017 18:46:43 -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=KwrIzrrZrVODm/p4zeGwbpSPfYqTpFcnB6BhSshrxc4=; b=QPYpMFOC3AbbnID3dJgE/bGbjcLS8Ae8uAs16B6XhXDPy8OhNC5nNZHl6lNrT3TV1j RLPZvwZRs4XjwO3VF8+ufVEDD0whnHQ2T4Uk0rgSIc1uWSuoaDicyD2Pt/xR4wiooyG8 +E/hJcr/JJCr7VKhLTNPuhagBXSZSDPmCYzdtp1kjI1f9M+7GxJoYjX7BxOf27Sq34wf Tz/y/qKs+RCTnWzycjOCVxI7X0cf9pQCN0/bZNPiqO4BpT0W8mkSNxYQq6QkCsUAwx02 MKlnP+vzztUdOUFtNKxyihSeJjbR2o2F5ioHKfChEVAOpHEWsBury53npdreofE/P/mC RmQQ== 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=KwrIzrrZrVODm/p4zeGwbpSPfYqTpFcnB6BhSshrxc4=; b=kHFX9x53cDRnNQAKo6tA97GquWUAWOIbfHLqirOA92TyGgiRNwFlt2OJWPICYOGqdI gWts6xQs80a8M7L+A3YuGrKmJoI18Z3frX4Sy140XDpj3DD3kztTv1zAv48VApo+0pJa RvF38NLmgjXFf/qWUH+gyoCh4rpAv3tS5jnTKosK/Ceh2yRdI4tjoBwVFoRWh0QW8zI1 8xLtATV3Py+6DGmnhkWDLAuOy8q+sxH+0XEvGbyVipaPX4oVJ7eWaR2JtPJeQBU59GL6 sttyLpLgTrhnMv9FwvfpLfWwKE2JCEFbZ/QNSQVV3q9ghPC323SbgjGM2LcwBz5+xw2M 0xow== X-Gm-Message-State: AFeK/H37gKCcogBtVWUiQ/T8jf8xQM2gm2tEOY/VfnKcIaviYDPo2lod0yMorZCftn/afQ== X-Received: by 10.28.90.66 with SMTP id o63mr382850wmb.97.1490924802234; Thu, 30 Mar 2017 18:46:42 -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.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 18:46:41 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Nicolai Stange , Luc Van Oostenryck Subject: [PATCH v4 15/25] constexpr: recognize members of static compound objects as address constants Date: Fri, 31 Mar 2017 03:44:49 +0200 Message-Id: <20170331014459.9351-16-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 According to 6.6(9), the member access operators "." and "->" may be used in the creation of address constants. Uses of both operators amount to the creation of EXPR_DEREF expressions which are eventually fed into evaluate_offset() at evaluation. Make evaluate_offset() propagate any address constant flag of the object containing the referenced member to the newly created pointer addition expression. Signed-off-by: Nicolai Stange Signed-off-by: Luc Van Oostenryck --- evaluate.c | 6 ++++++ validation/constexpr-addr-of-static-member.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 validation/constexpr-addr-of-static-member.c diff --git a/evaluate.c b/evaluate.c index e58d9c373..9a7d432b8 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1962,6 +1962,12 @@ static struct expression *evaluate_offset(struct expression *expr, unsigned long * we ever take the address of this member dereference.. */ add->ctype = &lazy_ptr_ctype; + /* + * The resulting address of a member access through an address + * constant is an address constant again [6.6(9)]. + */ + add->flags = expr->flags; + return add; } diff --git a/validation/constexpr-addr-of-static-member.c b/validation/constexpr-addr-of-static-member.c new file mode 100644 index 000000000..f944f213e --- /dev/null +++ b/validation/constexpr-addr-of-static-member.c @@ -0,0 +1,26 @@ +struct A { + int a; + int b[2]; +}; + +struct B { + int c; + struct A d; +}; + +static struct B a= {1, {1, {1, 1}}}; + +static int *b = &a.d.a; // OK +static int *c = &(&a.d)->a; // OK +static int *d = a.d.b; // OK +static int *e = (&a.d)->b; // OK +static int *f = &a.d.b[1]; // OK +static int *g = &(&a.d)->b[1]; // OK + +/* + * check-name: address of static object's member constness verification. + * check-command: sparse -Wconstexpr-not-const $file + * + * check-error-start + * check-error-end + */