From patchwork Mon Oct 23 11:29:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116707 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4533099qgn; Mon, 23 Oct 2017 04:29:24 -0700 (PDT) X-Received: by 10.84.168.69 with SMTP id e63mr10204115plb.340.1508758164323; Mon, 23 Oct 2017 04:29:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508758164; cv=none; d=google.com; s=arc-20160816; b=SmtcztqdGjo8YcD5IPMYcC5CzBN3UtI/2BYOnXgVJTfJB4NCtP0MpTK9D2nUSohsXV rhHb4jirYdliQbSpRsPKOgMnKZc9uBs3+Uk/WlU7GG1OOGyVJ1jw3ywhk+VNhP2B1J/A tBj2zJwbiKRr5ZZOYEhOCEEhlA49rGzYLRRjsutsJgzdjLZFzoCi2P6tEPXKyZe/jyeI vU94hBEJ3S3Z4Px36nv37WGulzEG+Seo3BzLdgiEMzuSat4jsjreeS0bgoQ5gXwkPu/l ngkl3bKJ6Bc9RY2Zn7UgwJPkj9s9EiFsqxb/nMMD/+M5Lwn99BPXdD6cbj41m1LbSthj jmPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=+wYc4nakvqmW401vTUl/Fv6Ft0X5Bi40mELzbo+QJdU=; b=oOKlmWxENkE/nNf222h/SlcVGD3xp2AoehjcUQQpKmUihK4IBoX++atmpK/1BbStgp DWtIaA+aTQw+kYDTP3mi7ywy+STphyd76MSob1ao92PiXbvBn/vmG4oYNcZwNq/hju5r sEQznjMLj1hEcIr2kNTCum60D52QBQkdIlg7FFnV5NR2y4hbGR4zyUQVsbr2lypBJPpx 15R2c0QAEfAkoz7JZyjglClwhmLtshUNI4K/OFfgXIIWM9RSti++WVI6tDv8kp5SaicS /nLWEbYkf81butXesLpW1TSDEZHt0hgthLcWlyvXYGy/8xskogTCWM1dqzkwcq3WfQIl yriQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uhwcxpZe; spf=pass (google.com: domain of gcc-patches-return-464747-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464747-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v62si4726854pgv.243.2017.10.23.04.29.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 04:29:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464747-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uhwcxpZe; spf=pass (google.com: domain of gcc-patches-return-464747-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464747-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=nK7XrwJBJkifHNbGALGRNkm6gqr43 2oAlA0CPdFcG9wn0qtF0C1OP4G/ekMRC16GhQqlDTR+d5WXpyA0MMnswxIdsvold Am30NhEynKJOVuJxuHC2d8fno50pMQKhHkyZ8khHB6SFr8TAjq4uL8FHs8idg0rg hNX//NoZx1zyBE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=hHtX1niUj5fJ/e0eCvqIAqEBI+k=; b=uhw cxpZeuM8hURNrTe6Jkh2C4MD+Am+2wtP91hFJoqmb9h5QdmbTxpWLq8caqFn7P2h v18oTzxDPU9pt6tEB4Fxvz/Z9CQ5HKYCH7K8bdnT8eFX+OheMAlMS9rhJOqbs/JJ DmTEQAjvAvqjspbmEvwZBJatq5Qr8QaB+IgqIVLM= Received: (qmail 93452 invoked by alias); 23 Oct 2017 11:29:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 93438 invoked by uid 89); 23 Oct 2017 11:29:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL, BAYES_00, 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-wr0-f177.google.com Received: from mail-wr0-f177.google.com (HELO mail-wr0-f177.google.com) (209.85.128.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 11:29:10 +0000 Received: by mail-wr0-f177.google.com with SMTP id k62so16979464wrc.9 for ; Mon, 23 Oct 2017 04:29:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=+wYc4nakvqmW401vTUl/Fv6Ft0X5Bi40mELzbo+QJdU=; b=E0iiW8bGx+AUwTpgr5dKO9F2zd8BL515UTQvPMJ0eQo5Iu1Mm6Qm+t3OgBQey4idPs NMgXCB4Qy22sj0PhBteWkHL3yS8aQTePd3m8eTrYByAuET7FdhmNFF/+GIrPjgNmH7jG 4p0dJhtblBM5qts2221I6xRg2hxyzk4zAOCOtLT01yuh+S8ztLffo1LwTZc8TUGm9wTe xpEfwFyWio8nT5FJLu9b0xlPdQYtMzrecpZ3R/cimC+HcYmC3rVzrViRmwiA262oUI5A ZTuMqDzDslrkPfpJ/prqt5GCqdKQKyz1lYn9vX/LVHwLotDuoyTdXGyig5jaQmpfbHdu QuCA== X-Gm-Message-State: AMCzsaV2oJW8vLzOrOPtO1HVYvYc2XesoEiufut7yjFBq2ngaPzYytMm Y0lRVEpWBoyM2S03eg1J6FTboyV9aYQ= X-Google-Smtp-Source: ABhQp+TGxDbjzXU4/0GekSv55uTaRZZnEAcZnoth0xDWdLR4Z58sbCM4kk7oTQr9YCW0W9WvRFRjvQ== X-Received: by 10.223.154.184 with SMTP id a53mr12102083wrc.48.1508758148076; Mon, 23 Oct 2017 04:29:08 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id u4sm6886036wre.1.2017.10.23.04.29.07 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 04:29:07 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [19/nn] Don't treat zero-sized ranges as overlapping References: <87wp3mxgir.fsf@linaro.org> Date: Mon, 23 Oct 2017 12:29:05 +0100 In-Reply-To: <87wp3mxgir.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 12:14:36 +0100") Message-ID: <87mv4iumpq.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 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. 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)))