From patchwork Mon May 15 15:52:16 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: 9727523 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 E526860386 for ; Mon, 15 May 2017 15:54:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE90826E51 for ; Mon, 15 May 2017 15:54:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1D0E2896B; Mon, 15 May 2017 15:54:23 +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 70E6326E51 for ; Mon, 15 May 2017 15:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756020AbdEOPyX (ORCPT ); Mon, 15 May 2017 11:54:23 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:36033 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755171AbdEOPyW (ORCPT ); Mon, 15 May 2017 11:54:22 -0400 Received: by mail-qk0-f196.google.com with SMTP id y128so17926877qka.3 for ; Mon, 15 May 2017 08:54:22 -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; bh=/6tQN3/C37H3jHORKPjhXcW6Ia71KshlzM5KS24N+10=; b=hcrT1D0Vd/9uSsIDjB2UxPNl7IVTsvf1Qn8R+hFHhaUcT8dg0ypx+xgd8xOXIHI46X 5mMg2WxKApkFZ6DUYT8kkSUfCtZ7TFMUFdmCbbTq+EFeD6KAuZiQaXnqA0wDff2DFMzt Evg1wuEe1iFwsGGg4LoGvr5qKad6pFOrNVXmdhCumlSDZLevFj5XvTsRdt+Nkuf4m+6D qzenU+dmq+d3fGyY7Dp2vdQ8i6URv9WgILhYKpbwSrncNwvAd0akcJu9BZpFqUSnZfCo aKMpKywsSGXDDfu230dCgl5RYf+pdRh6r0GowAmU3kftOPW4HJ06DIKIflnN3HZfgPOI X4SA== 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; bh=/6tQN3/C37H3jHORKPjhXcW6Ia71KshlzM5KS24N+10=; b=VGF5zuH7nRHfpTLeIYUo7rHR7dGH4gtoOwargbGDVUjvMA9Leay3eNZObXdKYeEUfI th/Z1FVgD3yxUMsgzWlJxh4fejn9SCru+Bj6g2OGaXWXo2dtd9J/wP/qoSs09flR1hjo 2WEU8IU00egfcXWuGtOotfuVCup71i48Bsrg3GuPnOn1LQ+2c0TmSaeg/dZD24edcMAa hGgJ21kfsBu2L9CXudJtWieZ7f38JKNv/OG0QHh4/Irxg3U/5z7HI6Ui77VXZ1ZsReDm IMRRMQux+Kk3mfMyh8uVDDFPQR9tqpDEdsekoC6OxcLrgDWWoNV/aZGx0DrSzT2ykK67 TxOQ== X-Gm-Message-State: AODbwcBVKy+W295BezNqGO8opiTpBbIVCvfxlBcIhymkoebJSI/mLxBz m0WwQVpKFkHk7mZRvIM= X-Received: by 10.80.134.155 with SMTP id r27mr5262641eda.133.1494863660807; Mon, 15 May 2017 08:54:20 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:8e9:c000:b41f:f215:4aaf:182c]) by smtp.gmail.com with ESMTPSA id q52sm4154655eda.30.2017.05.15.08.54.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 May 2017 08:54:19 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH] fix missing reload Date: Mon, 15 May 2017 17:52:16 +0200 Message-Id: <20170515155216.23400-1-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.2 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 In dominates() there is the following comment: "We don't think two explicitly different symbols ever alias" but the corresponding test only check if the storage in the potentialy dominating instruction is a symbol and if so returns 0 meaning that it can't dominate. But that's without taking in account that a pointer can point to this symbol and thus that a store via this symbol can dominate a store via a pointer. Fix this by changing the test more in accordance to the comment: return 0 only if the 2 concerned location correspond to 2 *distinct* symbols (and thus do not return 0 if one of the location is not a symbol). Signed-off-by: Luc Van Oostenryck --- flow.c | 11 ++++++++++- validation/alias-distinct.c | 17 +++++++++++++++++ validation/alias-mixed.c | 30 ++++++++++++++++++++++++++++++ validation/alias-same.c | 17 +++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 validation/alias-distinct.c create mode 100644 validation/alias-mixed.c create mode 100644 validation/alias-same.c diff --git a/flow.c b/flow.c index 94a8ec746..4b32f5cc8 100644 --- a/flow.c +++ b/flow.c @@ -314,6 +314,15 @@ static inline int same_memop(struct instruction *a, struct instruction *b) return a->offset == b->offset && a->size == b->size; } +static inline int distinct_symbols(pseudo_t a, pseudo_t b) +{ + if (a->type != PSEUDO_SYM) + return 0; + if (b->type != PSEUDO_SYM) + return 0; + return a->sym != b->sym; +} + /* * Return 1 if "dom" dominates the access to "pseudo" * in "insn". @@ -332,7 +341,7 @@ int dominates(pseudo_t pseudo, struct instruction *insn, struct instruction *dom if (local) return 0; /* We don't think two explicitly different symbols ever alias */ - if (dom->src->type == PSEUDO_SYM) + if (distinct_symbols(insn->src, dom->src)) return 0; /* We could try to do some alias analysis here */ return -1; diff --git a/validation/alias-distinct.c b/validation/alias-distinct.c new file mode 100644 index 000000000..42937b24b --- /dev/null +++ b/validation/alias-distinct.c @@ -0,0 +1,17 @@ +extern int g; +extern int h; + +static int foo(void) +{ + g = 1; + h = 2; + return g == 1; +} + +/* + * check-name: alias distinct symbols + * check-command: test-linearize $file + * check-output-ignore + * + * check-output-contains: ret\\..* *\\$1 + */ diff --git a/validation/alias-mixed.c b/validation/alias-mixed.c new file mode 100644 index 000000000..429304774 --- /dev/null +++ b/validation/alias-mixed.c @@ -0,0 +1,30 @@ +extern int g; + + +static int foo(int *p) +{ + *p = 1; + g = 2; + return *p == 1; +} + +static int bar(int *p) +{ + g = 1; + *p = 2; + return g == 1; +} + +static test(void) +{ + foo(&g); + bar(&g); +} + +/* + * check-name: alias symbol/pointer + * check-command: test-linearize $file + * check-output-ignore + * + * check-output-excludes: ret\\..* *\\$1 + */ diff --git a/validation/alias-same.c b/validation/alias-same.c new file mode 100644 index 000000000..55cf42445 --- /dev/null +++ b/validation/alias-same.c @@ -0,0 +1,17 @@ +extern int g; + + +static int foo(void) +{ + g = 1; + g = 2; + return g != 1; +} + +/* + * check-name: alias same symbols + * check-command: test-linearize $file + * check-output-ignore + * + * check-output-contains: ret\\..* *\\$1 + */