[{"id":3673214,"web_url":"http://patchwork.ozlabs.org/comment/3673214/","msgid":"<4d3feac6-ece3-4846-bcb3-9265ff308999@oss.qualcomm.com>","list_archive_url":null,"date":"2026-04-03T16:33:20","subject":"Re: [PATCH] strlen: Fix up memcpy/strcpy/strcat handling [PR124754]","submitter":{"id":92310,"url":"http://patchwork.ozlabs.org/api/people/92310/","name":"Jeffrey Law","email":"jeffrey.law@oss.qualcomm.com"},"content":"On 4/3/2026 2:48 AM, Jakub Jelinek wrote:\n> Hi!\n>\n> The following testcase ICEs because it tries to use a freed strinfo.\n> strinfo uses refcounting and vectors of pointers to those are either shared\n> in between bbs or unshared when some later bb needs to modify something.\n>\n> The ICE is due to the second memcpy handling.  Since r10-5451 it first\n> calls get_stridx on dst (&a), then get_strinfo with the returned index and\n> then get_stridx on src (&a + 24).  &a has been referenced earlier and\n> the pass knows some details on its string length (let's ignore that the\n> testcase invokes UB for now, I think it can happen even on valid code,\n> just haven't managed to adjust the testcase, but supposedly the unreduced\n> original is valid), so the strinfo is shared with other bbs.\n> WHen get_stridx is called for &a + 24, it sees it doesn't know anything\n> about that yet and wants to create a strinfo for it.  But related strinfos\n> are chained, so &a's next should be &a + 24 in this testcase, that means\n> we need to unshare the &a strinfo so that we can modify it while keeping\n> the one entry used by earlier bbs unmodified.  The problem is that\n> handle_builtin_memcpy called get_strinfo before this, so it got hands on\n> the old still not unshared strinfo for &a and because it isn't refreshed\n> after the get_stridx call by another get_strinfo call, we try to unshare\n> it again and break the refcounting.\n>\n> So, basically for calls which call get_stridx twice, we need top make sure\n> we do both get_stridx calls before the first get_strinfo call, or repeat\n> get_strinfo after the second get_stridx call.\n>\n> In handle_builtin_memcpy it used to be right and got broken by r10-5451,\n> but I'm in strcpy/strcat handling I've screwed it up since the pass was\n> added.\n>\n> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,\n> ok for trunk and eventually backports?\n>\n> 2026-04-03  Jakub Jelinek  <jakub@redhat.com>\n>\n> \tPR tree-optimization/124754\n> \t* tree-ssa-strlen.cc (strlen_pass::handle_builtin_strcpy): Make\n> \tsure both get_stridx calls are done before first get_strinfo call.\n> \t(strlen_pass::handle_builtin_memcpy): Likewise.\n> \t(strlen_pass::handle_builtin_strcat): Likewise.\n>\n> \t* g++.dg/tree-ssa/strlenopt-3.C: New test.\nOK.\njeff","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=XoWnRpIp;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=BvyZWVBm;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=XoWnRpIp;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=BvyZWVBm","sourceware.org; dmarc=none (p=none dis=none)\n header.from=oss.qualcomm.com","sourceware.org;\n spf=pass smtp.mailfrom=oss.qualcomm.com","server2.sourceware.org;\n arc=none smtp.remote-ip=205.220.168.131"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fnPS60Xfnz1yCt\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 04 Apr 2026 03:33:58 +1100 (AEDT)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 2F2D54BA23D6\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  3 Apr 2026 16:33:56 +0000 (GMT)","from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com\n [205.220.168.131])\n by sourceware.org (Postfix) with ESMTPS id 417B14BA23C3\n for <gcc-patches@gcc.gnu.org>; Fri,  3 Apr 2026 16:33:25 +0000 (GMT)","from pps.filterd (m0279865.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 633BvmQA3780331\n for <gcc-patches@gcc.gnu.org>; Fri, 3 Apr 2026 16:33:24 GMT","from mail-dy1-f198.google.com (mail-dy1-f198.google.com\n [74.125.82.198])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4da663j3r8-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Fri, 03 Apr 2026 16:33:24 +0000 (GMT)","by mail-dy1-f198.google.com with SMTP id\n 5a478bee46e88-2cb6f605b95so4728599eec.1\n for <gcc-patches@gcc.gnu.org>; Fri, 03 Apr 2026 09:33:24 -0700 (PDT)","from [10.204.26.37] ([172.56.170.106])\n by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2ca7cf1271asm6909506eec.26.2026.04.03.09.33.21\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Fri, 03 Apr 2026 09:33:22 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 2F2D54BA23D6","OpenDKIM Filter v2.11.0 sourceware.org 417B14BA23C3"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 417B14BA23C3","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 417B14BA23C3","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775234005; cv=none;\n b=Rhn/DODVGtFDTgc3ntDAi6Bo8lwEOP0Qr+glnMoMbVUzfGZqW5/TbEaqn2/LsS/5W4CFQgFfDEEFWCxFT3cJniqlTtX7OvnVpfqRELJjYIJ5s7K3hd+AtHa0YjgR+kj8JAHuM1s4g06ku0CsqyTDOkbw9rcLdjCjtbgIL8FYdAM=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775234005; c=relaxed/simple;\n bh=ZKTnnDJSdlUYWABfjWKxouyNAomqaONao6BXml/cO1U=;\n h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:\n Subject:To:From;\n b=X+WB1PGH2UBaAUWCgL+oF9D2MSHBahwmhWUG3G0wjjXQoDTsdgm4tdyn1qbDEWTEYCxbd9ZpSaw2HmoUYpaqDcr0wODj2uAaYmVugtD9lMto8gTpR7XFtW3w6kjrb+l/vpmqdHbnXCPzz4xPr6iqZcpANU2MbHAUh2h+5/7qpDU=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:content-type:date:from:in-reply-to\n :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n zLZtBA8GA0OAYIDNtiQDvlLMfF05YFNjl87A4I+636E=; b=XoWnRpIpMSwtV9IY\n Nhe7zsMIkT4D5pl5ZOtBeCDZluOjUkmCq9odD4ZlSxQz1rMzsm0uFfBKARcgiRnb\n bWpD3OW4cXa8mnViwG006ZZVb3b8j4wwCDd2MphRrahmWDfGs8OehdzBYb8s8mLg\n WmbfpOm8oWLRntv6nFqz9qMGtnB+fJojkLxGo1NF5wkEEj5GR8PaW8+xkGCt5yK/\n i7T2eJzXZ95dX+LjN9vfz0oJeDk4pkaV3zWvTksNexUiYDQKOogtm9MS4Z7tb8y4\n iSoKPHQvZ2C4/bSWuKgQVQkMo7+sS7utFynIgwoGidytfKAIncLy1ro/LVYaLdVr\n t5MeHg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1775234003; x=1775838803; darn=gcc.gnu.org;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:cc:to:subject:user-agent:mime-version:date:message-id\n :from:to:cc:subject:date:message-id:reply-to;\n bh=zLZtBA8GA0OAYIDNtiQDvlLMfF05YFNjl87A4I+636E=;\n b=BvyZWVBmeYM7jYXO8BoPn0QlLBZ7kQdniOT+ppY/JCSUs1S+OaBAU+h/OzbW4N6Psk\n iUuWIVeyQS89nVgyxH8F+E2JoCbTcp84wd2CCLcVhWJFR43Kxes2iZ45lohFE0/LxRsr\n sCu3CIV8TAm83q7CMAvOOwaqUy6Krf/+faZ2N1dy7ZbhRMcCEto6lM/VifXHyiQpWauZ\n RglBaU4nl8sJins08Ap/RzTVCBQUZYfqfUmTqXJbhr5MULGvniwVdJLSnFzUsJ1boio4\n PbOyowHmTJJT/vPBHISH4VDrpKdOxFCuO8agwRCrL4FOFgUkwXMUERzVf+lVlDGrtg0b\n JqqA=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775234003; x=1775838803;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:cc:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=zLZtBA8GA0OAYIDNtiQDvlLMfF05YFNjl87A4I+636E=;\n b=DjkvsNlpBncUndp0PkFrnfgi1cYHMsL+NxopXgQZie7D5KjiUwQvsiCt+GH+6LqUYU\n pdbmZE84I6R22IBo6HUuqe+gmHQCazQ+tB/sLhlJDui3wqiIBOEio71EvQbIhbbUlBc4\n YUL2uEy5GB/tRqPrUEMKmEZQRVixCmxoFKhjvavGmiIujN/dVU8gfs1DRXwjK5OK3abe\n 6HGq5iP8nRq66QdnK0pahS7XEeZM5h6NuJ0rA+5nAHj+iV+JhguO6Z6fD+rKOFOI0Zoz\n izGQd1H1T5x2Pin/RfPhnL0UnLElpbTPABo6LHLDPwvdbjSPE67UFl9CTtuohpLow2vG\n MyPw==","X-Gm-Message-State":"AOJu0YxLHcI8ntztRXTfPI+DBTxpyyN1NE75ixRM1hiagvDlwFPuDvLV\n y/vjFuuaxq1nb0dMlSR8IC5r7YKlS8DcGMlLbj4GR6pLLled7pwS72QWHKiwCCKlcXdSHgL1uxL\n fDO7LykcSaSa0HZgvQ8M9WsaAg46DxP5LliO+kfaNsUWNHIhw1p5qKp2DiYS+","X-Gm-Gg":"AeBDievlF5Tn+UE6XYfsqqPLkG/d0zAoYo5/czuDUIr7asjyxPWqa2/gho0P6ha6jUx\n 1/p3Rj5YkIGrcEj0X+TrMwShbse4l8jBfwnv4+6E90oKfJUqj9BigotN/O7Bye4qgDmTzi4FSag\n tpmjrlzpHblf49E2yIPoSYWcBBDDupOgT/qUZq/+Yx4rMe7cigFJeRV6kuCVKk7Q060hDn6r6ej\n gqTFP7PoGyp3NeQHBnZ+Qla8Ek/8ORGlrrRKmoS6VQwiwk8E1GQANTkaRNEZ24FdeAIIdDNY6Eh\n MoE/XAksA8APi9F2LXD4Z8PWoqhBFFXCOI4RuTi6szbYDJf4oK2AMKsB6XQs8GzeYOl1ymUVMum\n 5w26Y5IMrKiVJye7HPRAavggD5S5ocADDmYC5R7NeKtuplbiZyXtTZcQ=","X-Received":["by 2002:a05:7300:214d:b0:2c1:6676:5ebd with SMTP id\n 5a478bee46e88-2cbf9ee8cd5mr2093321eec.10.1775234003332;\n Fri, 03 Apr 2026 09:33:23 -0700 (PDT)","by 2002:a05:7300:214d:b0:2c1:6676:5ebd with SMTP id\n 5a478bee46e88-2cbf9ee8cd5mr2093307eec.10.1775234002761;\n Fri, 03 Apr 2026 09:33:22 -0700 (PDT)"],"Message-ID":"<4d3feac6-ece3-4846-bcb3-9265ff308999@oss.qualcomm.com>","Date":"Fri, 3 Apr 2026 10:33:20 -0600","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] strlen: Fix up memcpy/strcpy/strcat handling [PR124754]","To":"Jakub Jelinek <jakub@redhat.com>, Richard Biener <rguenther@suse.de>,\n Andrew Pinski <andrew.pinski@oss.qualcomm.com>,\n Jeff Law <jeffreyalaw@gmail.com>","Cc":"gcc-patches@gcc.gnu.org","References":"<ac9-w0Cbkq_2NfXV@tucnak>","Content-Language":"en-US","From":"Jeffrey Law <jeffrey.law@oss.qualcomm.com>","In-Reply-To":"<ac9-w0Cbkq_2NfXV@tucnak>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDAzMDE0NyBTYWx0ZWRfX/an8BP6GwJGW\n 38O8MFKWL2ISut+jEZzQRJCGmosFNNUGAQ4C6+OiA51QqIUE+AtoZ17FJ1ohQ/QYpV7OFmWKBAR\n hmppe2DoqO5kQiPGcq0EVJzXFr9Eo7R9Mq8fcl5PFqdXsUZp28d5Si8SE18PixypX2mPYwUVe2Y\n UCzo+vZiRwc9TWwh2l8ZUVlrxLLG5cFEoxrYApmseh0DfzR1/am6Dpl/Lm6Ekcn9y8eBQ+EM7PW\n ZrO6cxk53lIJ0ek6Xrg9tOaOSOMUG2mj2Kg1IUgYoeSzyuNRyyLxZo3LL4pHCTl9RTLsDKR4Sjf\n pFNxhJAbRFVqCg/tIHxmKv3p0HmWnu4P03HEwa5fKYbXmmmA+VaUj68zfjbuzgw41o5svJpTzSR\n n7nG7tqR//K9jxMYTVFe6yB+kqsy7XBir6r02+6GLG2yYLDcutVWF3ssTmA0okBx4xfjm5/H86v\n qb5H3QoObhrBNLMbNEw==","X-Proofpoint-GUID":"fI9T5dqEOHCvreQv_pm3Iwb6JUPU9DwU","X-Proofpoint-ORIG-GUID":"fI9T5dqEOHCvreQv_pm3Iwb6JUPU9DwU","X-Authority-Analysis":"v=2.4 cv=Acu83nXG c=1 sm=1 tr=0 ts=69cfebd4 cx=c_pps\n a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=BBM2tUHNqzXHVbnkdcSAyw==:17\n a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10\n a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=Um2Pa8k9VHT-vaBCBUpS:22\n a=20KFwNOVAAAA:8 a=HGRp7mTLzKJOr3mUJHgA:9 a=QEXdDO2ut3YA:10\n a=bBxd6f-gb0O0v-kibOvt:22","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-03_05,2026-04-03_01,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n spamscore=0 suspectscore=0 adultscore=0 clxscore=1015 priorityscore=1501\n phishscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2604030147","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]