[[Crashed]] 0xC0000005 at bm::bit_out<bm::encoder>::put_bits
#include "Services/ScreenCompatibility/BitMagic/src/bm.h"
#include "Services/ScreenCompatibility/BitMagic/src/bmserial.h"
#include "Services/ScreenCompatibility/BitMagic/src/bmundef.h"
......
void test_bm()
{
bm::bvector<> f3;
f3.clear();
f3.set(65535);
f3.set(65526);
f3.set(65486);
f3.set(65447);
f3.set(65504);
f3.set(32639);
f3.set(18873);
f3.set(87);
f3.set(145);
f3.set(48);
f3.set(105);
f3.set(8);
f3.set(66);
f3.set(25);
bm::serializer<bm::bvector<>> ser;
ser.byte_order_serialization(false);
ser.gap_length_serialization(false);
bm::serializer<bm::bvector<>>::buffer buf;
ser.serialize(f3, buf);
}
......
int main(int argc, char *argv[])
{
test_bm();
......
Up here is my test code, it crashed at bm::bit_out<bm::encoder>::put_bits(unsigned value, unsigned count) like below:
It's weird that it only crash when I use this lib in my project. Once I write a simple test, I mean a simple C++ program contains only the two test_bm and main functions, it runs perfectly. And one more weird thing is that when the code crash, process stack seems not valid like below:
My compiler is 'VS Community 2022 Release msvc_x86' with Qt5.15, hope someone can help me, thank you.
Seems like it's the function below runs incorrect:
BMFORCEINLINE
unsigned int bsr_asm32(unsigned int value) BMNOEXCEPT
{
__asm bsr eax, value
}
It give a wrong result of logv
After modify those function, it finally runs correct:
BMFORCEINLINE
unsigned int bsr_asm32(unsigned int value) BMNOEXCEPT
{
// __asm bsr eax, value
return 31u - std::countl_zero(value);
}
BMFORCEINLINE
unsigned int bsf_asm32(unsigned int value) BMNOEXCEPT
{
// __asm bsf eax, value
return std::countr_zero(value);
}
I don't know why same compiler and same code can runs different, hope somebody can find out.
What is the compiler (ok, i see that it is VS 22) and the platform and the compile options here? These BSR asms are pretty old... always worked. Some compilers sometimes have bugs on -O3 level (just a guess).
We are looking at this issue and suspect a compilation bug... Can you please post a disassembly printout at the place of failure?