From patchwork Tue Jul 4 11:14:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 106942 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp904229obb; Tue, 4 Jul 2017 04:15:13 -0700 (PDT) X-Received: by 10.98.44.205 with SMTP id s196mr91168pfs.168.1499166913532; Tue, 04 Jul 2017 04:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499166913; cv=none; d=google.com; s=arc-20160816; b=f8df5eUIkS4aN/f62fVDZCIDBnUTZ8R73+xZUIJh1OxjHnUl46MTiIEdFSmjhPbMA1 5a20zDLd9twpuI/9u8juCic35qaq2spsaI8n4ux5aOmYoVoJQnHHvlbRA61jHczmP7yw XLsmUyYuuJ3JY/YKNREHjA/ybhWb/3bPu0sYZo/hKC1u+/JCGyMBMmT3mUuT9FlG9gi2 nJjeC2qa9oMkbsyJrMfcxX9oPYGyb2X6jVL+Fjs7fhzDgpiIiW5kt90swFdNanTM8ppq KPtSCxI4kkXaBHodb3sWvwEuwq2MXKo4L42oOwOnJMv1TE6BhFIB6gi3tEjWCn4OqXrl 2mtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date: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=/JwWh7s1dLngazi/0EQ/kzDSHP/vhNzaSST2z8ZEUbw=; b=t+h8y6hIIaYFWr2WcfUErhI3qtrZJc1MCZR44rIbYvrJa6ZN/XJVcU1cX+f72O2om6 DZnR/OWHeKGHdowVSCZYjaX5ZMIg9f8biN24lidv2ZHE7MLT7asXDSa/Mvj1NT3Bv/Z/ UZeBYOX/hJN55eTPtdsHXza9X+Krcr3mzQvk87vVNivEH4LkOgPWOSbeFuo/xW7qRNds fLNMsurYW4fSPIF2rnQYF1Hwjep3ueUVvIme2BDQik2dqCG3x9HKCYhCQcx5EgnyTXF8 SON9UCEnSosGKZ686j5DSDa+6yfPn/NeYasrhNgjUSu7krdxAq7FRnhmq4mgRHUXsOTc 6lIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=YQtqXz81; spf=pass (google.com: domain of gcc-patches-return-457530-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-457530-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 n12si5360446pfg.407.2017.07.04.04.15.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jul 2017 04:15:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-457530-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.b=YQtqXz81; spf=pass (google.com: domain of gcc-patches-return-457530-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-457530-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:date:message-id:mime-version:content-type; q=dns; s= default; b=L85U+0cdrkjRAKCz+ZPeOd6WWnU4YMxj1a09lTZ+AV20dlUumV8pt yLzTcjcEM1AWHSwl/9+dpEtcdxKOUIfe7r26MGux2vWVG6gvztuPj75e+DhibyfH QnWBTgR9+RPzymwbycDtjEiVDmiGgJ+HII2HUh7xLOnX0j5YJaKdhQ= 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:date:message-id:mime-version:content-type; s= default; bh=BLDomRuvIdtjcnbsawQFbwf0crQ=; b=YQtqXz81H/tb1De979Xm JkJ99xO2FlUIRyR2ub2l27dl1HukPy+tyYoMmdYJwPdw/UPQ9JFevf/X5cuo0wvU YU6WWgaxsFunBCklmE0yw7B9+fTsHg/p1l5innjEHVXCUTl8qTjvrUkEfjYIE8Yg QceTJ0W9/wjyJLIjC038HU4= Received: (qmail 112263 invoked by alias); 4 Jul 2017 11:14:54 -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 111059 invoked by uid 89); 4 Jul 2017 11:14:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=invalidates X-HELO: mail-wr0-f172.google.com Received: from mail-wr0-f172.google.com (HELO mail-wr0-f172.google.com) (209.85.128.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Jul 2017 11:14:52 +0000 Received: by mail-wr0-f172.google.com with SMTP id r103so247499466wrb.0 for ; Tue, 04 Jul 2017 04:14:51 -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:date:message-id :user-agent:mime-version; bh=/JwWh7s1dLngazi/0EQ/kzDSHP/vhNzaSST2z8ZEUbw=; b=FhA7jdWsrtLOcpdwJmEDyK2SbZQ1qQmUCHR0gg/qlYI2NgX7JfA7TZA/Qxi71H1QN2 p8DJjnKexkxdtNrTf2r5IrO8YGDd9eLSMhSOjiv+alT3XATMNKBcAluMxSsrLCsKjj6g LvuU8ntWdJEt+2aBx2V5CZSLzAmJ8tr/6U8wyUS9NF5yxbgYDKOl6LrDn9JLUDLPKAck uxTXINQoBA36zfqclZ1EJmjsApgG+xPJwfh0hobUEFKPf+JqIWtG6U60ERiBr4tfbdio A4rEkSnVfocje5tTgb9K6fOEVVR8lVBgJgMd2HPv+gyqpHsCehdS0IiIBWucUOoCWGWE V6gA== X-Gm-Message-State: AKS2vOyPutZsVBJ2aiqQKFzFaaCK7Alpq7MRmon5YgBOlj8BztzXeX73 O330tICuND77pOQAxdMOZQ== X-Received: by 10.223.175.18 with SMTP id z18mr39209610wrc.22.1499166889810; Tue, 04 Jul 2017 04:14:49 -0700 (PDT) Received: from localhost ([2.26.27.176]) by smtp.gmail.com with ESMTPSA id o4sm20384382wrb.27.2017.07.04.04.14.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jul 2017 04:14:48 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: PR 81292: ICE on related strlens after r249880 Date: Tue, 04 Jul 2017 12:14:48 +0100 Message-ID: <87tw2spi6v.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 r249880 installed the result of a strlen in a strinfo if the strinfo wasn't previously a full string. But as Jakub says in the PR comments, we can't just do that in isolation, because there are no vdefs on the call that would invalidate any related strinfos. This patch updates the related strinfos if the adjustment is simple and invalidates them otherwise. As elsewhere, we treat adjustments of the form strlen +/- INTEGER_CST as simple but anything else as too complex. Tested on x86_64-linux-gnu and aarch64-linux-gnu. OK to install? Sorry for the breakage. Richard gcc/ PR tree-optimization/81292 * tree-ssa-strlen.c (handle_builtin_strlen): When setting full_string_p, also call adjust_related_strinfos if the adjustment is simple, otherwise invalidate related strinfos. gcc/testsuite/ PR tree-optimization/81292 * gcc.dg/pr81292-1.c: New test. * gcc.dg/pr81292-2.c: Likewise. Index: gcc/tree-ssa-strlen.c =================================================================== --- gcc/tree-ssa-strlen.c 2017-07-03 21:00:21.438433126 +0100 +++ gcc/tree-ssa-strlen.c 2017-07-03 21:00:34.971809881 +0100 @@ -1214,8 +1214,23 @@ handle_builtin_strlen (gimple_stmt_itera /* Until now we only had a lower bound on the string length. Install LHS as the actual length. */ si = unshare_strinfo (si); + tree old = si->nonzero_chars; si->nonzero_chars = lhs; si->full_string_p = true; + if (TREE_CODE (old) == INTEGER_CST) + { + location_t loc = gimple_location (stmt); + old = fold_convert_loc (loc, TREE_TYPE (lhs), old); + tree adj = fold_build2_loc (loc, MINUS_EXPR, + TREE_TYPE (lhs), lhs, old); + adjust_related_strinfos (loc, si, adj); + } + else + { + si->first = 0; + si->prev = 0; + si->next = 0; + } } return; } Index: gcc/testsuite/gcc.dg/pr81292-1.c =================================================================== --- /dev/null 2017-07-03 19:11:31.344941082 +0100 +++ gcc/testsuite/gcc.dg/pr81292-1.c 2017-07-03 21:00:34.971809881 +0100 @@ -0,0 +1,35 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fdump-tree-strlen" } */ + +#include "strlenopt.h" + +char a[10]; + +int __attribute__ ((noinline, noclone)) +f1 (int n) +{ + a[0] = '1'; + a[1] = '2'; + return strlen (a + 1) < n ? strlen (a) : 100; +} + +int __attribute__ ((noinline, noclone)) +f2 (char *a, int n) +{ + a[0] = '1'; + a[1] = '2'; + return strlen (a + 1) < n ? strlen (a) : 100; +} + +int +main (void) +{ + char b[10]; + strcpy (a + 2, "345"); + strcpy (b + 2, "34567"); + if (f1 (100) != 5 || f2 (b, 100) != 7) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */ Index: gcc/testsuite/gcc.dg/pr81292-2.c =================================================================== --- /dev/null 2017-07-03 19:11:31.344941082 +0100 +++ gcc/testsuite/gcc.dg/pr81292-2.c 2017-07-03 21:00:34.971809881 +0100 @@ -0,0 +1,35 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fdump-tree-strlen" } */ + +#include "strlenopt.h" + +char a[] = { 0, 'a', 0, 'b', 'c', 0, 'd', 'e', 'f', 0 }; + +int __attribute__ ((noinline, noclone)) +f1 (void) +{ + a[0] = '1'; + a[strlen (a)] = '2'; + a[strlen (a)] = '3'; + return strlen (a); +} + +int __attribute__ ((noinline, noclone)) +f2 (char *a) +{ + a[0] = '1'; + a[strlen (a)] = '2'; + a[strlen (a)] = '3'; + return strlen (a); +} + +int +main (void) +{ + char b[] = { 0, 0, 'a', 'b', 0, 0 }; + if (f1 () != 9 || f2 (b) != 5) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "strlen \\(" 6 "strlen" } } */