llvm.org GIT mirror llvm / 4350fb9
[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 Jessica Paquette 3 years ago
2 changed file(s) with 44 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
20822082 return true;
20832083 StringRef V = S.substr(2);
20842084 APInt A(V.size()*4, V, 16);
2085 Result = APInt(A.getActiveBits(),
2086 ArrayRef(A.getRawData(), A.getNumWords()));
2085
2086 // If A is 0, then A.getActiveBits() is 0. This isn't a valid bitwidth. Make
2087 // sure it isn't the case before constructing result.
2088 unsigned NumBits = (A == 0) ? 32 : A.getActiveBits();
2089 Result = APInt(NumBits, ArrayRef(A.getRawData(), A.getNumWords()));
20872090 return false;
20882091 }
20892092
0 # RUN: llc -o /dev/null %s
1 # REQUIRES: asserts
2 # Makes sure that having a probability of 0x00000000 to branch to a successor
3 # doesn't hit an APInt assert in the MIParser.
4
5 --- |
6 define i32 @main() local_unnamed_addr #0 {
7 entry:
8 ret i32 0
9
10 other:
11 ret i32 0
12 }
13
14 attributes #0 = { nounwind }
15
16 !llvm.module.flags = !{!0, !1}
17 !llvm.ident = !{!2}
18
19 !0 = !{i32 1, !"wchar_size", i32 4}
20 !1 = !{i32 7, !"PIC Level", i32 2}
21 !2 = !{!"clang version 6.0.0"}
22 !3 = !{!"branch_weights", i32 0, i32 -1}
23
24 ...
25 ---
26 name: main
27 alignment: 2
28 exposesReturnsTwice: false
29 legalized: false
30 regBankSelected: false
31 selected: false
32 tracksRegLiveness: true
33 body: |
34 bb.0.entry:
35 successors: %bb.1.other(0x00000000)
36 bb.1.other:
37
38 ...