[llvm-dev] bug is APFloat assignment

Davis, Alan via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 16 11:21:43 PDT 2018


I am getting a segfault when assigning one APFloat to another, as in:

APFloat APF1(APFloat::IEEEdouble());
APFloat APF2 = APF1;

APFloat is a wrapper class that wraps either an IEEEFloat or a DoubleAPFloat. A union called Storage in APFloat contains the underlying object, which is one of those two types. The assignment APF2 = APF1 ends up calling APFloat::Storage::operator=() to copy the underlying object, which in this is an IEEEFloat, so we call IEEEFloat::operator=(). This assignment  operator uses the semantics field of the LHS to decide whether it needs to free any storage being used by the LHS before assigning the RHS over it. But in this case the LHS is a newly constructed IEEEFloat, with semantics == 0, hence the crash.

This seems like a bug to me, but seems surprising not to have been already encountered. Am I missing something?

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181016/a9ef88f2/attachment.html>


More information about the llvm-dev mailing list