public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35878]  New: Useless NULL pointer check when constructing object
@ 2008-04-08 21:37 ian at airs dot com
  2008-04-08 21:41 ` [Bug c++/35878] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 6+ messages in thread
From: ian at airs dot com @ 2008-04-08 21:37 UTC (permalink / raw)
  To: gcc-bugs

Consider this trivial C++ test case:

#include <vector>
void foo(std::vector<int>* 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-29 19:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-35878-4@http.gcc.gnu.org/bugzilla/>
2013-09-11 12:59 ` [Bug c++/35878] Useless NULL pointer check when constructing object glisse at gcc dot gnu.org
2013-09-11 13:39 ` redi at gcc dot gnu.org
2013-09-11 16:58 ` [Bug libstdc++/35878] " glisse at gcc dot gnu.org
2013-09-11 19:08 ` redi at gcc dot gnu.org
2014-11-29 19:40 ` [Bug libstdc++/35878] [LWG 2302] " glisse at gcc dot gnu.org
2008-04-08 21:37 [Bug c++/35878] New: " ian at airs dot com
2008-04-08 21:41 ` [Bug c++/35878] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).