From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 550663858D3C for ; Wed, 22 May 2024 06:20:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 550663858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 550663858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716358828; cv=none; b=oKMUmKNeZcZ62kHfIYcwPAsb/wjk3ZmUoBPEdOZmZG4tg0g2ZPUndXFcKbP7FXG5o1XML+Ae9hN/wAzN82fk9fSSBe7cTdB1UHrssv2ay0pOyf485uWHm2nMyWcxKXNfM7DV+/Zltbzssg7e/VlqtE0SBVB6mBmGDjnVhIixzaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716358828; c=relaxed/simple; bh=79pmZd0/6Qvhy/+eTBpo68WK7eHHDAvY4X8+Rrnn0GY=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=XE9NCIScT8RW8zYxkeSWCZWmNAuJZPhkqf/psXS8A7trTWQqTPNLYzz4kw5/iH2mekDWlToyCG9VILBkoCC4dlXyPsR1M5EvCYZ5AILVyfLil1ica3Z/jWmBdPmbQ5kChiZjU/DK6nC/YLk88Ot/uJzVDORpTYWq7bYxIMzJjUk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 77F6C5C676; Wed, 22 May 2024 06:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716358824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AP4yfTKVZ2a0lULnb0BKjNLQboDxH2LDTAntnsHgRfg=; b=q9wy4/1OVC6SqQomnmdC5hfnK1OuKtepjlKULIPqyWe7W1iryObpZIe0Tapy0NHfGQjAYi 1qu0XGcDOMx20LtYTI+Lvhhjy1HdMLRtOcm5B00Xm3cbhwfzErF8bxiy+likg7/rs0Ay98 PwPkxkWroXSaSTluU4mMJPsR+FNpv9Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716358824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AP4yfTKVZ2a0lULnb0BKjNLQboDxH2LDTAntnsHgRfg=; b=AOW+e80v7YB4uoTykCdAsFV4P5bo7Y7ZbVi4joQcCn/fxPXj4YlK4IewvBERdjLBmRHtve 91Ki449i9tUZwgBw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716358824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AP4yfTKVZ2a0lULnb0BKjNLQboDxH2LDTAntnsHgRfg=; b=q9wy4/1OVC6SqQomnmdC5hfnK1OuKtepjlKULIPqyWe7W1iryObpZIe0Tapy0NHfGQjAYi 1qu0XGcDOMx20LtYTI+Lvhhjy1HdMLRtOcm5B00Xm3cbhwfzErF8bxiy+likg7/rs0Ay98 PwPkxkWroXSaSTluU4mMJPsR+FNpv9Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716358824; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AP4yfTKVZ2a0lULnb0BKjNLQboDxH2LDTAntnsHgRfg=; b=AOW+e80v7YB4uoTykCdAsFV4P5bo7Y7ZbVi4joQcCn/fxPXj4YlK4IewvBERdjLBmRHtve 91Ki449i9tUZwgBw== Date: Wed, 22 May 2024 08:20:24 +0200 (CEST) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] strlen: Fix up !si->full_string_p handling in count_nonzero_bytes_addr [PR115152] In-Reply-To: Message-ID: <7npo049p-5529-r1s3-o112-r0oo2po93sr6@fhfr.qr> References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Level: X-Spamd-Result: default: False [-4.23 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.13)[-0.665]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; RCPT_COUNT_TWO(0.00)[2]; SUBJECT_HAS_EXCLAIM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email] X-Spam-Score: -4.23 X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 21 May 2024, Jakub Jelinek wrote: > Hi! > > The following testcase is miscompiled because > strlen_pass::count_nonzero_bytes_addr doesn't handle correctly > the !si->full_string_p case. > If si->full_string_p, it correctly computes minlen and maxlen as > minimum and maximum length of the '\0' terminated stgring and > clears *nulterm (ie. makes sure !full_string_p in the ultimate > caller) if minlen is equal or larger than nbytes and so > '\0' isn't guaranteed to be among those bytes. > But in the !si->full_string_p case, all we know is that there > are [minlen,maxlen] non-zero bytes followed by unknown bytes, > so effectively the maxlen is infinite (but caller cares about only > the first nbytes bytes) and furthermore, we never know if there is > any '\0' char among those, so *nulterm needs to be always cleared. > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, > ok for trunk and affected release branches? OK. Richard. > 2024-05-21 Jakub Jelinek > > PR tree-optimization/115152 > * tree-ssa-strlen.cc (strlen_pass::count_nonzero_bytes_addr): If > !si->full_string_p, clear *nulterm and set maxlen to nbytes. > > * gcc.dg/pr115152.c: New test. > > --- gcc/tree-ssa-strlen.cc.jj 2024-04-29 11:00:45.000000000 +0200 > +++ gcc/tree-ssa-strlen.cc 2024-05-21 13:43:31.031208000 +0200 > @@ -4829,7 +4829,7 @@ strlen_pass::count_nonzero_bytes_addr (t > if (maxlen + 1 < nbytes) > return false; > > - if (nbytes <= minlen) > + if (nbytes <= minlen || !si->full_string_p) > *nulterm = false; > > if (nbytes < minlen) > @@ -4839,6 +4839,9 @@ strlen_pass::count_nonzero_bytes_addr (t > maxlen = nbytes; > } > > + if (!si->full_string_p) > + maxlen = nbytes; > + > if (minlen < lenrange[0]) > lenrange[0] = minlen; > if (lenrange[1] < maxlen) > --- gcc/testsuite/gcc.dg/pr115152.c.jj 2024-05-21 13:46:02.793214348 +0200 > +++ gcc/testsuite/gcc.dg/pr115152.c 2024-05-21 12:49:38.791626073 +0200 > @@ -0,0 +1,17 @@ > +/* PR tree-optimization/115152 */ > +/* { dg-do run } */ > +/* { dg-options "-O3 -fno-tree-fre -fno-tree-dominator-opts -fno-tree-loop-im" } */ > + > +int a, b, c, d; > +signed char e[1] = { 1 }; > + > +int > +main () > +{ > + for (a = 0; a < 3; a++) > + for (b = 0; b < 2; b++) > + c = e[0] = e[0] ^ d; > + if (!c) > + __builtin_abort (); > + return 0; > +} > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)