OSDN Git Service

[MIParser] Ensure getHexUint doesn't produce APInts with a bitwidth of 0
authorJessica Paquette <jpaquette@apple.com>
Fri, 1 Sep 2017 22:17:14 +0000 (22:17 +0000)
committerJessica Paquette <jpaquette@apple.com>
Fri, 1 Sep 2017 22:17:14 +0000 (22:17 +0000)
commit4350fb93af21d62e7007b05969bf68f0c849a9e0
treedf9c00c97e3ec8c1bf67e276358acc8426b85ef1
parentcecd8f18e21715f6a4aaa374a38100943a3f811c
[MIParser] Ensure getHexUint doesn't produce APInts with a bitwidth of 0

If getHexUint reads in a hex 0, it will create an APInt with a value of 0.
The number of active bits on this APInt is used to calculate the bitwidth of
Result. The number of active bits is defined as an APInt's bitwidth - its
number of leading 0s. Since this APInt is 0, its bitwidth and number of leading
0s are equal.

Thus, Result is constructed with a bitwidth of 0, triggering an APInt assert.

This commit fixes that by checking if the APInt is equal to 0, and setting the
bitwidth to 32 if it is. Otherwise, it sets the bitwidth using getActiveBits.

This caused issues when compiling MIR files with successor probabilities. In
the case that a successor is tagged with a probability of 0, this assert would
fire on debug builds.

https://reviews.llvm.org/D37401

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312387 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/MIRParser/MIParser.cpp
test/CodeGen/Generic/zero-probability.mir [new file with mode: 0644]