LGTM!<br><div class="gmail_quote"><div dir="ltr">On Mon, 16 Nov 2015 at 08:37, Petr Pavlu via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">petpav01 created this revision.<br>
petpav01 added a subscriber: llvm-commits.<br>
Herald added subscribers: rengolin, aemerson.<br>
<br>
Function `ARMConstantIslands::doInitialJumpTablePlacement()` iterates over all basic blocks in a machine function. It calls `MI = MBB.getLastNonDebugInstr()` to get the last instruction in each block and then uses `MI->getOpcode()` to decide what to do. If `getLastNonDebugInstr()` returns `MBB.end()` (for example, when the block does not contain any instructions) then calling `getOpcode()` on<br>
this value is incorrect. Avoid this problem by checking the result of `getLastNonDebugInstr()`.<br>
<br>
The problem can be shown by compiling the following example with `clang --target=armv8a-none-none-eabi -O3`:<br>
```<br>
void v0();<br>
void v1();<br>
void v2();<br>
void v3();<br>
void v4();<br>
int a;<br>
<br>
void test(void) {<br>
switch (a) {<br>
default:<br>
v0();<br>
break;<br>
case 1:<br>
v1();<br>
break;<br>
case 2:<br>
v2();<br>
break;<br>
case 3:<br>
v3();<br>
break;<br>
case 4:<br>
v4();<br>
break;<br>
}<br>
try {<br>
throw 0;<br>
} catch (int) {<br>
}<br>
}<br>
```<br>
<br>
<a href="http://reviews.llvm.org/D14694" rel="noreferrer" target="_blank">http://reviews.llvm.org/D14694</a><br>
<br>
Files:<br>
lib/Target/ARM/ARMConstantIslandPass.cpp<br>
<br>
Index: lib/Target/ARM/ARMConstantIslandPass.cpp<br>
===================================================================<br>
--- lib/Target/ARM/ARMConstantIslandPass.cpp<br>
+++ lib/Target/ARM/ARMConstantIslandPass.cpp<br>
@@ -589,6 +589,8 @@<br>
MachineBasicBlock *LastCorrectlyNumberedBB = nullptr;<br>
for (MachineBasicBlock &MBB : *MF) {<br>
auto MI = MBB.getLastNonDebugInstr();<br>
+ if (MI == MBB.end())<br>
+ continue;<br>
<br>
unsigned JTOpcode;<br>
switch (MI->getOpcode()) {<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>