From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B558E386EC59; Tue, 22 Sep 2020 07:18:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B558E386EC59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600759103; bh=Ngx38Do627TBairGP6odcQWxmtYNVh83GcAl2/Zq7ko=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xYsqqj9PaVn6ftznqOYMUn5ec9gMbayzcDDV8Z5/SwoHHiWWFYmb6yCxXZQBa3dxR oPHT4OIhNsXpKlWCLa6y0LMYCBMYBuRXXk5UEawA0MprfO49ItJu3akekFLfckaLvv XYQrATXNJRPZ2YHExaHdrTU6lXqIkz/eFGJRkipc= From: "marat at slonopotamus dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97151] GCC fails to optimize away uselessly allocated arrays (C++) Date: Tue, 22 Sep 2020 07:18:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: marat at slonopotamus dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Sep 2020 07:18:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97151 --- Comment #4 from Marat Radchenko --- (In reply to Martin Li=C5=A1ka from comment #3) > It's caused by what was mentioned as 2) which transforms to: >=20 > _6 =3D operator new [] (40); > __builtin_memset (_6, 0, 40); > operator delete [] (_6); >=20 > So there's a use of _6 and we probably can't remove it as memset can > potentially access NULL pointer if operator new [] fails. 1. If operator new[] fails, there would be an exception instead of NULL, no? 2. It doesn't matter, you may guard accessing array with NULL check and sti= ll observe described behavior. What puzzles me the most is why removal of delete[] allows it to optimize.=