From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12641 invoked by alias); 8 Apr 2008 21:37:51 -0000 Received: (qmail 12522 invoked by uid 48); 8 Apr 2008 21:37:08 -0000 Date: Tue, 08 Apr 2008 21:37:00 -0000 Subject: [Bug c++/35878] New: Useless NULL pointer check when constructing object X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "ian at airs dot com" 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 X-SW-Source: 2008-04/txt/msg00659.txt.bz2 Consider this trivial C++ test case: #include void foo(std::vector* v, int i) { v->push_back(i); } When I compile this with current trunk with -O2 on i686-pc-linux-gnu I see, among other things, this: movl 4(%edi), %edx cmpl 8(%edi), %edx je .L2 testl %edx, %edx je .L3 movl -4(%edx), %eax movl %eax, (%edx) movl 4(%edi), %edx .L3: leal 4(%edx), %eax movl %eax, 4(%edi) Note that test for whether %edx is NULL. That comes from this in the .004t.gimple file: D.7266 = operator new (4, D.7265); D.7264 = (int *) D.7266; if (D.7264 != 0B) { try { D.7268 = *__val; *D.7264 = D.7268; } catch { operator delete (D.7264, D.7265); } iftmp.48 = D.7264; } else { iftmp.48 = D.7264; } We get rid of the try/catch pretty quickly, but we never manage to get rid of the NULL pointer check. I believe the NULL pointer check is being generated by build_new_1 in cp/init.c because we are using a type for which TYPE_NOTHROW_P is true. This NULL pointer check serves no useful purpose. It is essentially an abtraction penalty. We should figure out some way to get rid of it, either in the C++ frontend, or in some later optimization pass. -- Summary: Useless NULL pointer check when constructing object Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ian at airs dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35878