[LLVMbugs] [Bug 8504] New: Unused calls to operator new/delete not optimized away

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Oct 29 07:10:23 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=8504

           Summary: Unused calls to operator new/delete not optimized away
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: benny.kra at gmail.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


for this silly testcase:

void t() {
  int *x = new int;
  delete x;
}

clang generates at -O3:

define void @_Z1tv() ssp {
entry:
  %call = tail call noalias i8* @_Znwm(i64 4)
  %isnull = icmp eq i8* %call, null
  br i1 %isnull, label %delete.end, label %delete.notnull

delete.notnull:                                   ; preds = %entry
  tail call void @_ZdlPv(i8* %call) nounwind
  ret void

delete.end:                                       ; preds = %entry
  ret void
}


One issue is that we unconditionally emit the isnull check even if it's
unneeded. We could teach llvm to optimize away null checks before operator
delete (or free), which I'm not entirely sure is what the user expects, or just
avoid emitting the check when we don't need it.

Another problem is that LLVM knows nothing about operator new/delete so it
cannot remove the calls if the allocated memory isn't used at all.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list