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: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]


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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to