staticafi/llvm2c

bitcast instruction

suarezvictor opened this issue · 1 comments

There's a bug with respect to bitcast instruction: it shoudln't be cast with (float) or (unsigned int) operations: the bitcast should be a reinterpretation of the memory (i.e. corresponding to "memcpy"). If not, the compiler issues a conversion from float to interger or interger to float.

  %17 = bitcast float %13 to i32
  %21 = bitcast i32 %20 to float

Possible implementation:

inline unsigned int bitcast_to_uint(float a) { union _noname { float f; unsigned int i;} conv; conv.f = a; return conv.i; }
inline float bitcast_to_float(unsigned int a) { union _noname { float f; unsigned int i;} conv; conv.i = a; return conv.f; }

Thanks for reporting this and sorry for not re-acting. This should be fixed, I think:

cl::opt<bool> BitcastUnions("bitcasts-with-unions", cl::desc("Use unions to translate bitcasts"), cl::cat(options), cl::init(false));

Although it is not enabled by default for now.