std::rotate fails in some cases due to std::memmove

Bug #1299510 reported by Daniele Di Proietto
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cheerp
Fix Released
Undecided
Unassigned

Bug Description

Testcase attached

I've noticed a weird failure of std::rotate(first, middle, last) that happens when middle == last - 1, i.e. when trying to rotate_right.

The library has a special case for that: it detects that we are rotating right and __rotate_right gets called (algorithm:2325)

__rotate_right moves the last element in the first place and then tries to move all the other elements forwards by one position by calling move_backward (algorithm:1897)

There are different versions of move_backward: one of them is selected based on the result of a __unwrap_iter (algorithm:1674).

In this case __move_backward (algorithm:1885) gets called: this version deals with memory pointers, and calls std::memmove to actually move objects. This some how fails

One of the possible solutions would probably be to remove __unwrap_iter that returns a pointer and deal always with iterators.

Revision history for this message
Daniele Di Proietto (d-diproietto) wrote :
Revision history for this message
Daniele Di Proietto (d-diproietto) wrote :

There appears to be a bug in memmove (testcase attached)

the generated code is:

Lv[1] = Lv[0];
Lv.set(Lv.subarray(0,3),1);

where Lv is the v vector. The first line is harmful: it is generated by DuettoWriter.cpp:467 to translate a @llvm.memcpy.p0i8.p0i8.i32.
Unfortunately I'm not very familiar with duetto internals so, this is as far as I can get.

Changed in duetto:
status: New → Confirmed
Revision history for this message
Alessandro Pignotti (a-pignotti) wrote :
Changed in duetto:
status: Confirmed → Fix Committed
Changed in duetto:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.