<vector>
: _Copy_vbool()
mishandles vector<bool>
s of size 32 and 64, revealed by constexpr
Clang
#5345
Labels
bug
Something isn't working
Found by an upcoming libcxx test update.
Reduced repro
Size 32 error
This correctly points to
_LastSourceMask
which is performing a forbidden full shift:STL/stl/inc/vector
Lines 3817 to 3820 in 1f6e5b1
It looks like we can patch this with the same pattern used for
_FirstDestMask
, but I haven't exhaustively verified this.Size 64 error
This one's sneaky because above there's a runtime-only optimization that absorbs this case:
STL/stl/inc/vector
Lines 3861 to 3865 in 1f6e5b1
Commenting it out allows runtime execution to follow the same path as constexpr evaluation, and ASan can notice the same badness that
constexpr
does here.After the runtime-only optimization, things start looking bad. It starts by talking about having "Unaligned _VbFirst and _VbLast":
STL/stl/inc/vector
Lines 3897 to 3898 in 1f6e5b1
But in this case we're not unaligned -
_Dest._Myoff
is equal to_First._Myoff
. So we're not_IsRightShift
, but we're also not performing a left shift either. So theelse
block appears to perform a forbidden full shift:STL/stl/inc/vector
Lines 3934 to 3940 in 1f6e5b1
When I debugged into this, I saw that
_SourceShift
was 0, so_CarryShift
was 32. I'm not sure whyconstexpr
evaluation didn't stop right here.In any event, things get worse from here. Eventually we get a "read of dereferenced one-past-the-end pointer".
I think this one needs more significant surgery than just handling the forbidden full shift. It looks like we need an entire third case handling "no shift".
The text was updated successfully, but these errors were encountered: