[PATCH] D14694: [ARM] Prevent use of a value pointed by end() iterator when placing a jump table
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 16 00:41:09 PST 2015
LGTM!
On Mon, 16 Nov 2015 at 08:37, Petr Pavlu via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> petpav01 created this revision.
> petpav01 added a subscriber: llvm-commits.
> Herald added subscribers: rengolin, aemerson.
>
> 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
> this value is incorrect. Avoid this problem by checking the result of
> `getLastNonDebugInstr()`.
>
> The problem can be shown by compiling the following example with `clang
> --target=armv8a-none-none-eabi -O3`:
> ```
> void v0();
> void v1();
> void v2();
> void v3();
> void v4();
> int a;
>
> void test(void) {
> switch (a) {
> default:
> v0();
> break;
> case 1:
> v1();
> break;
> case 2:
> v2();
> break;
> case 3:
> v3();
> break;
> case 4:
> v4();
> break;
> }
> try {
> throw 0;
> } catch (int) {
> }
> }
> ```
>
> http://reviews.llvm.org/D14694
>
> Files:
> lib/Target/ARM/ARMConstantIslandPass.cpp
>
> Index: lib/Target/ARM/ARMConstantIslandPass.cpp
> ===================================================================
> --- lib/Target/ARM/ARMConstantIslandPass.cpp
> +++ lib/Target/ARM/ARMConstantIslandPass.cpp
> @@ -589,6 +589,8 @@
> MachineBasicBlock *LastCorrectlyNumberedBB = nullptr;
> for (MachineBasicBlock &MBB : *MF) {
> auto MI = MBB.getLastNonDebugInstr();
> + if (MI == MBB.end())
> + continue;
>
> unsigned JTOpcode;
> switch (MI->getOpcode()) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151116/add89c1b/attachment.html>
More information about the llvm-commits
mailing list