[LLVMdev] Bug in FoldingSetNodeID::AddInteger(unsigned long long I)?

Xu Zhongxing xuzhongxing at foxmail.com
Wed Jun 1 02:39:10 PDT 2011


The current implementation is:


void FoldingSetNodeID::AddInteger(unsigned long long I) {
  AddInteger(unsigned(I));
  if ((uint64_t)(int)I != I)
    Bits.push_back(unsigned(I >> 32));
}
 
(uint64_t)(int)I first truncates I to signed int, which causes the second cast to sign extend the value to 64 bits. The problem is that if the 31st bit of the original value is 1, the sign extended value would be different than the original one even if the high 32 bits of the original value are all 0. This may contradict the original intention of this code.


Should the correct implementation be:  if ((uint64_t)(unsigned)I != I) ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110601/f6214d63/attachment.html>


More information about the llvm-dev mailing list