Boost logo

Boost Users :

Subject: [Boost-users] [unordered_map]: Unexpected exception on value insertion
From: Johannes Brunen (jbrunen_at_[hidden])
Date: 2012-08-21 04:47:03


Hello,

My program is crashing (not handling an unexpected exception) on
inserting a value into a unorderd map of type:
unordered_map<osg::Pnt3f, std::size_t, Pnt3fHashT> with

struct Pnt3fHashT : public std::unary_function<osg::Pnt3f, std::size_t>
{
    std::size_t operator()(const osg::Pnt3f& pnt) const
    {
        std::size_t seed = 0;
        boost::hash_combine(seed, pnt[0]);
        boost::hash_combine(seed, pnt[1]);
        boost::hash_combine(seed, pnt[2]);

        return seed;
    }
};

Pnt3f is a common 3D float point.

The program is compiled with Microsoft Visual C++ 2008 9.0.30729.1SP
64Bit and Boost 1.48.0.
The crash does only occur on 64Bit compilations.

After inspection, I found the crash to be happening in the function

inline std::size_t float_hash_impl2(T v)

found in source hash_float_generic.hpp.

Since the code looks fine for me I investigated the generated assembler
code and found

std::size_t seed = static_cast<std::size_t>(v);
000007FEE8A4D3C0 xor ecx,ecx
000007FEE8A4D3C2 movss xmm0,dword ptr [v]
000007FEE8A4D3CB comiss xmm0,dword ptr [__real_at_5f000000
(7FEE8FB7A34h)]
000007FEE8A4D3D2 jbe
boost::hash_detail::float_hash_impl2<float>+0D2h (7FEE8A4D3F2h)
000007FEE8A4D3D4 subss xmm0,dword ptr [__real_at_5f000000
(7FEE8FB7A34h)]
000007FEE8A4D3DC comiss xmm0,dword ptr [__real_at_5f000000
(7FEE8FB7A34h)]
000007FEE8A4D3E3 jae
boost::hash_detail::float_hash_impl2<float>+0D2h (7FEE8A4D3F2h)
000007FEE8A4D3E5 mov rax,8000000000000000h
000007FEE8A4D3EF add rcx,rax
000007FEE8A4D3F2 cvttss2si rax,xmm0
000007FEE8A4D3F7 add rax,rcx
000007FEE8A4D3FA mov qword ptr [seed],rax

The crash happens at the

000007FEE8A4D3F2 cvttss2si rax,xmm0

instruction since the value in xmm0 is larger than the maximum signed
32bit integer.
In this case depending on the settings an floating-point invalid
exception is raised. It crashes since
my code is not prepared for this exception.

Now I have some questions:
1. Is it known that this mapping into the realm of 32Bit is happening
for the above cast operation?
2. Is this a compiler bug? The generated assembler code does not allow
'safe' casting into 64bit integer?
3. Any advice how I should handle this situation?

Best,
Johannes

____________
Virus checked by G DATA AntiVirusKit
Version: AVF 22.889 from 20.08.2012
Virus news: www.antiviruslab.com


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net