From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 125342 invoked by alias); 26 Oct 2017 12:13:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 125325 invoked by uid 89); 26 Oct 2017 12:13:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Oct 2017 12:13:29 +0000 Received: by mail-wm0-f51.google.com with SMTP id t139so7887403wmt.1 for ; Thu, 26 Oct 2017 05:13:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=4vOxdR0OIpMy0VO9tmWDcI0w/FFwbxWbUlT8hkfG++c=; b=IQAxttPxLtvvsqdIaX4jSkuU/KUtMQ+mzNps02ryhXWDfZRIYvPxqFZloQ0qdTSFnS LdgSjBfpbLh2F2Lb2k7FZBBAb8f5/xpKvsEgzXfysU+t6yRcFg1lf2ksJK7wVTi7orLg pnQB7dpJ8dzuCQq8CnwYnIY9+faYTa9vbJetOQ1lbVChEzbZAfQFtwkwz/A4/P53TMt/ QrrjdqWukIer82ckkEXUzFpGqyNFFEkjhAoXQy8j6yrAMsplgHjOMFCuyhagc2zkVUcQ Xh2Tu+XZTFlfp104RXtZsxWt8EVTYLLZB8exvdFHGOngIpcNBRsdfakewF5EjN51+qEk dfaw== X-Gm-Message-State: AMCzsaUeDZjCnYt2T2wOySHw+UmkfqPf9VR42Ou1JsdX3HfNhsHTuZru UfouCsCpplPCKwFOBaBVekuRtbOoJLOUmeHbpG1djQ== X-Google-Smtp-Source: ABhQp+Q/wMLcUyo4zwFpf5rNjD4cI7GCWh+bwr/rBNhiduCwrbum2v33knO7GnJ78g9qb7s0c73Qmt5hXv5jWYpJDqQ= X-Received: by 10.80.173.210 with SMTP id b18mr28516508edd.148.1509020007135; Thu, 26 Oct 2017 05:13:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.143.34 with HTTP; Thu, 26 Oct 2017 05:13:26 -0700 (PDT) In-Reply-To: <87mv4iumpq.fsf@linaro.org> References: <87wp3mxgir.fsf@linaro.org> <87mv4iumpq.fsf@linaro.org> From: Richard Biener Date: Thu, 26 Oct 2017 12:14:00 -0000 Message-ID: Subject: Re: [19/nn] Don't treat zero-sized ranges as overlapping To: GCC Patches , Richard Sandiford Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-10/txt/msg01926.txt.bz2 On Mon, Oct 23, 2017 at 1:29 PM, Richard Sandiford wrote: > Most GCC ranges seem to be represented as an offset and a size (rather > than a start and inclusive end or start and exclusive end). The usual > test for whether X is in a range is of course: > > x >= start && x < start + size > or: > x >= start && x - start < size > > which means that an empty range of size 0 contains nothing. But other > range tests aren't as obvious. > > The usual test for whether one range is contained within another > range is: > > start1 >= start2 && start1 + size1 <= start2 + size2 > > while the test for whether two ranges overlap (from ranges_overlap_p) is: > > (start1 >= start2 && start1 < start2 + size2) > || (start2 >= start1 && start2 < start1 + size1) > > i.e. the ranges overlap if one range contains the start of the other > range. This leads to strange results like: > > (start X, size 0) is a subrange of (start X, size 0) but > (start X, size 0) does not overlap (start X, size 0) > > Similarly: > > (start 4, size 0) is a subrange of (start 2, size 2) but > (start 4, size 0) does not overlap (start 2, size 2) > > It seems like "X is a subrange of Y" should imply "X overlaps Y". > > This becomes harder to ignore with the runtime sizes and offsets > added for SVE. The most obvious fix seemed to be to say that > an empty range does not overlap anything, and is therefore not > a subrange of anything. > > Using the new definition of subranges didn't seem to cause any > codegen differences in the testsuite. But there was one change > with the new definition of overlapping ranges. strncpy-chk.c has: > > memset (dst, 0, sizeof (dst)); > if (strncpy (dst, src, 0) != dst || strcmp (dst, "")) > abort(); > > The strncpy is detected as a zero-size write, and so with the new > definition of overlapping ranges, we treat the strncpy as having > no effect on the strcmp (which is true). The reaching definition > is the memset instead. > > This patch makes ranges_overlap_p return false for zero-sized > ranges, even if the other range has an unknown size. Ok. Thanks, Richard. > > 2017-10-23 Richard Sandiford > > gcc/ > * tree-ssa-alias.h (ranges_overlap_p): Return false if either > range is known to be empty. > > Index: gcc/tree-ssa-alias.h > =================================================================== > --- gcc/tree-ssa-alias.h 2017-03-28 16:19:22.000000000 +0100 > +++ gcc/tree-ssa-alias.h 2017-10-23 11:47:38.181155696 +0100 > @@ -171,6 +171,8 @@ ranges_overlap_p (HOST_WIDE_INT pos1, > HOST_WIDE_INT pos2, > unsigned HOST_WIDE_INT size2) > { > + if (size1 == 0 || size2 == 0) > + return false; > if (pos1 >= pos2 > && (size2 == (unsigned HOST_WIDE_INT)-1 > || pos1 < (pos2 + (HOST_WIDE_INT) size2)))