From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10085 invoked by alias); 29 Aug 2013 19:40:13 -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 9771 invoked by uid 48); 29 Aug 2013 19:40:05 -0000 From: "tijl at coosemans dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/58275] New: __builtin_constant_p( expr ) returns true if expr is eliminated by CSE Date: Thu, 29 Aug 2013 19:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: tijl at coosemans dot org X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: 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: 2013-08/txt/msg01580.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58275 Bug ID: 58275 Summary: __builtin_constant_p( expr ) returns true if expr is eliminated by CSE Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: tijl at coosemans dot org It appears that whenever the expression in __builtin_constant_p( expression ) can be eliminated __builtin_constant_p returns true even if expression is not a compile-time constant. Here is an example program. When compiled with -O it returns 1 instead of 2: int main( int argc, char **argv ) { return( argc == 23 ? 0 : __builtin_constant_p( argc != 23 ) ? 1 : 2 ); } % gcc49 -o test test.c -O % ./test ; echo $? 1 If you change the first 23 into 24 the program returns 2. (gcc49 (FreeBSD Ports Collection) 4.9.0 20130818 (experimental))