[LLVMdev] A potential bug in helper function "fieldFromInstruction" in tablegen'erated file "XXXGenDisassemblerTables.inc"

NAKAMURA Takumi geek4civic at gmail.com
Tue Dec 25 23:04:50 PST 2012


Yongyong, fixed in r171101. Thanks for your reporting!

...Takumi

2012/12/22 Triple Yang <triple.yang at gmail.com>:
> Helper function:
>
> template<typename InsnType>
> static InsnType fieldFromInstruction(InsnType insn, unsigned startBit,
>                                      unsigned numBits) {
>     assert(startBit + numBits <= (sizeof(InsnType)*8) &&
>            "Instruction field out of bounds!");
>     InsnType fieldMask;
>     if (numBits == sizeof(InsnType)*8)
>       fieldMask = (InsnType)(-1LL);
>     else
>       fieldMask = ((1 << numBits) - 1) << startBit;
>     return (insn & fieldMask) >> startBit;
> }
>
> may fail if the last parameter "startBit" is larger than 31 which is
> likely to occur when instruction sets have encodings more than 32
> bits.
>
> In "else" statement, RHS is evaluated on 32-bit integers, and thus
> might result in decoding errors in 32-bit platforms.
>
> *************************************************
> fieldMask = ((1 << numBits) - 1) << startBit;
> *************************************************
>
> should be:
>
> ********************************************
> fieldMask = ((uint64_t(1) << numBits) - 1) << startBit;
> ********************************************
>
> or something similar.
>
> Can someone clarify this situation? Thanks.
>
> --
> æšć‹‡ć‹‡ (Yang Yongyong)
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list