From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2671 invoked by alias); 24 Mar 2014 11:49:33 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 2637 invoked by uid 48); 24 Mar 2014 11:49:30 -0000 From: "mark at infocomm dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug lto/51744] Erroneous warning: memset used with constant zero length parameter Date: Mon, 24 Mar 2014 11:49:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: lto X-Bugzilla-Version: 4.6.2 X-Bugzilla-Keywords: diagnostic, lto X-Bugzilla-Severity: major X-Bugzilla-Who: mark at infocomm dot com X-Bugzilla-Status: NEW 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: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-03/txt/msg02139.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51744 --- Comment #7 from Mark Pizzolato --- Thanks for reducing this test case further. That illuminates something for me: Specifically: Notice in the following lines: if (__builtin_constant_p (__len) && __len == 0 && (!__builtin_constant_p (__ch) || __ch != 0)) { The part of the expression "|| __ch != 0)" What could possibly be the purpose of this check? That is exactly why the 3rd condition I previously mentioned: > 3) memset is called with a NON zero fill value argument. triggers this issue. The warning is about the length, but it is checking the value being set. How could that make sense? Clearly this check lets the vast majority of uses of memset pass without issue since all of those cases use 0 as the value to be set. >>From my point of view, if that check wasn't there (i.e. remove "|| __ch != 0" from the expression), the problem would not exist.