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

           Summary: SmallVector::insert should use copy_backward
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core LLVM classes
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


Created an attachment (id=2791)
 --> (http://llvm.org/bugs/attachment.cgi?id=2791)
Testcase demonstrating the issue

SmallVector::insert() (for multiple elements) uses std::copy to copy the
elements that get replaced:
      // Copy the existing elements that get replaced.
      std::copy(I, OldEnd-NumToInsert, I+NumToInsert);

Unfortunately, I+NumToInsert can easily be within the (I, OldEnd-NumToInsert)
range.  Using std::copy_backward() fixes the problem:
      // Copy the existing elements that get replaced.
      std::copy_backward(I, OldEnd-NumToInsert, OldEnd);

We don't need to decide at runtime between these versions as OldEnd is always
after OldEnd-NumToInsert.


-- 
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