https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94981
--- Comment #5 from Tony Reix <tony.reix at atos dot net> ---
I'm not invoking myself directly this conversion. It is made by C++.
The original issue appeared when running tests of Boost v1.73 math library,
dealing with include code of C++ , line 324 of file:
include/c++/bits/stl_algobase.h (GCC v8), with _OI being: char* .
Thus, this was deeply hidden in C++ internal code while doing some
initialization of a vector, with:
boost::array<double, 4> const d3a = { { 10, -6, -4, 3 } };
polynomial<T> const a(d3a.begin(), d3a.end());
where a is built wrong silently: (10, 0, 0, 3).
The Boost line generating the issue seems to be:
std::vector<T> m_data;
That seems to mean that anyone using standard C++ code , with his own kind of
array, could face this issue silently and break some data.
include/c++/bits/stl_algobase.h :
std::__copy_move<false, false,
std::random_access_iterator_tag>::__copy_m<double const*, char*>
( __first=0x10002e80 <_GLOBAL__F__ZSt4bug3i+1168>,
__last =0x10002ea0 <_GLOBAL__F__ZSt4bug3i+1200>,
__result=0x20001ce8 "")
+314 template<>
+315 struct __copy_move<false, false, random_access_iterator_tag>
+316 {
+317 template<typename _II, typename _OI>
+318 static _OI
+319 __copy_m(_II __first, _II __last, _OI __result)
+320 {
+321 typedef typename iterator_traits<_II>::difference_type
_Distance;
+322 for(_Distance __n = __last - __first; __n > 0; --__n)
+323 {
+324 *__result = *__first;
+325 ++__first;
+326 ++__result;
+327 }
+328 return __result;
+329 }
+330 };
generating the assembler code:
0x10001978 <+56>: lwz r9,88(r31)
0x1000197c <+60>: lfd f0,0(r9)
0x10001980 <+64>: fctiwuz f0,f0
0x10001984 <+68>: addi r9,r31,40
0x10001988 <+72>: stfiwx f0,0,r9
where fctiwuz replaces f0 by 0 when contents of f0 is negative.
Complete stack is below. Showing that Boost test code is testing with "char"
type.
Does it means that:
- C++ should check that _OI cannot be "char*" because such conversion is
undefined ?
- or that Boost should not use the char type in that code ?
Thread 2 hit Breakpoint 1, std::__copy_move<false, false,
std::random_access_iterator_tag>::__copy_m<double const*, char*> (
__first=0x1003f8928 <_GLOBAL__F__ZSt4bug3i+136760>, __last=0x1003f8940
<_GLOBAL__F__ZSt4bug3i+136784>, __result=0x110042931 "")
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_algobase.h:324
324 *__result = *__first;
(gdb) where
#0 std::__copy_move<false, false,
std::random_access_iterator_tag>::__copy_m<double const*, char*>
(__first=0x1003f8928 <_GLOBAL__F__ZSt4bug3i+136760>,
__last=0x1003f8940 <_GLOBAL__F__ZSt4bug3i+136784>, __result=0x110042931 "")
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_algobase.h:324
#1 0x0fffffffffffd410 in ?? ()
#2 0x0000000100195338 in std::__copy_move_a2<false, double const*, char*>
(__first=0x1003f8920 <_GLOBAL__F__ZSt4bug3i+136752>,
__last=0x1003f8940 <_GLOBAL__F__ZSt4bug3i+136784>, __result=0x110042930
"\n")
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_algobase.h:422
#3 0x0000000100195278 in std::copy<double const*, char*> (__first=0x1003f8920
<_GLOBAL__F__ZSt4bug3i+136752>,
__last=0x1003f8940 <_GLOBAL__F__ZSt4bug3i+136784>, __result=0x110042930
"\n")
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_algobase.h:455
#4 0x00000001001951a8 in std::__uninitialized_copy<true>::__uninit_copy<double
const*, char*> (__first=0x1003f8920 <_GLOBAL__F__ZSt4bug3i+136752>,
__last=0x1003f8940 <_GLOBAL__F__ZSt4bug3i+136784>, __result=0x110042930
"\n")
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_uninitialized.h:101
#5 0x0000000100195114 in std::uninitialized_copy<double const*, char*>
(__first=0x1003f8920 <_GLOBAL__F__ZSt4bug3i+136752>,
__last=0x1003f8940 <_GLOBAL__F__ZSt4bug3i+136784>, __result=0x110042930
"\n")
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_uninitialized.h:134
#6 0x000000010019506c in std::__uninitialized_copy_a<double const*, char*,
char> (__first=0x1003f8920 <_GLOBAL__F__ZSt4bug3i+136752>,
__last=0x1003f8940 <_GLOBAL__F__ZSt4bug3i+136784>, __result=0x110042930
"\n")
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_uninitialized.h:289
#7 0x0000000100194db4 in std::vector<char, std::allocator<char>
>::_M_range_initialize<double const*> (this=0xfffffffffffda08,
__first=0x1003f8920 <_GLOBAL__F__ZSt4bug3i+136752>, __last=0x1003f8940
<_GLOBAL__F__ZSt4bug3i+136784>)
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_vector.h:1474
#8 0x0000000100194c90 in std::vector<char, std::allocator<char>
>::_M_initialize_dispatch<double const*> (this=0xfffffffffffda08,
__first=0x1003f8920 <_GLOBAL__F__ZSt4bug3i+136752>, __last=0x1003f8940
<_GLOBAL__F__ZSt4bug3i+136784>)
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_vector.h:1442
#9 0x0000000100194a74 in std::vector<char, std::allocator<char>
>::vector<double const*, void> (this=0xfffffffffffda08,
__first=0x1003f8920 <_GLOBAL__F__ZSt4bug3i+136752>, __last=0x1003f8940
<_GLOBAL__F__ZSt4bug3i+136784>, __a=...)
at
/opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8/include/c++/bits/stl_vector.h:551
#10 0x0000000100194930 in
boost::math::tools::polynomial<char>::polynomial<double const*>
(this=0xfffffffffffda08,
first=0x1003f8920 <_GLOBAL__F__ZSt4bug3i+136752>, last=0x1003f8940
<_GLOBAL__F__ZSt4bug3i+136784>) at ../boost/math/tools/polynomial.hpp:304
#11 0x00000001001d2f60 in test_multiplication<char>::test_method
(this=0xfffffffffffe3e0) at ../libs/math/test/test_polynomial.cpp:417
#12 0x00000001001d2a5c in test_multiplication_invoker::run<char> () at
../libs/math/test/test_polynomial.cpp:415
#13 0x00000001001d2640 in
boost::unit_test::ut_detail::test_case_template_invoker<test_multiplication_invoker,
char>::operator() (this=0x110045a90)
at ../boost/test/tree/test_case_template.hpp:70
#14 0x00000001001d2540 in
boost::detail::function::void_function_obj_invoker0<boost::unit_test::ut_detail::test_case_template_invoker<test_multiplication_invoker,
char>, void>::invoke (function_obj_ptr=...) at
../boost/function/function_template.hpp:158