ART: Fix divide-by-zero for ARM

There was an infinite loop in the code generation for a divide
by literal zero.

Bug: 18887754
Change-Id: Ibd481918d3c6d7bc62fdd1a6807042009f561d95
diff --git a/compiler/dex/quick/arm/int_arm.cc b/compiler/dex/quick/arm/int_arm.cc
index fe1d126..b1ed11c 100644
--- a/compiler/dex/quick/arm/int_arm.cc
+++ b/compiler/dex/quick/arm/int_arm.cc
@@ -567,6 +567,14 @@
 
 // Try to convert *lit to 1 RegRegRegShift/RegRegShift form.
 bool ArmMir2Lir::GetEasyMultiplyOp(int lit, ArmMir2Lir::EasyMultiplyOp* op) {
+  if (lit == 0) {
+    // Special case for *divide-by-zero*. The ops won't actually be used to generate code, as
+    // GenArithOpIntLit will directly generate exception-throwing code, and multiply-by-zero will
+    // have been optimized away earlier.
+    op->op = kOpInvalid;
+    return true;
+  }
+
   if (IsPowerOfTwo(lit)) {
     op->op = kOpLsl;
     op->shift = LowestSetBit(lit);
diff --git a/test/800-smali/expected.txt b/test/800-smali/expected.txt
index d7aede3..6cb08f4 100644
--- a/test/800-smali/expected.txt
+++ b/test/800-smali/expected.txt
@@ -12,4 +12,5 @@
 b/18718277
 b/18800943 (1)
 b/18800943 (2)
+MoveExc
 Done!
diff --git a/test/800-smali/smali/move_exc.smali b/test/800-smali/smali/move_exc.smali
new file mode 100644
index 0000000..4ade4bc
--- /dev/null
+++ b/test/800-smali/smali/move_exc.smali
@@ -0,0 +1,29 @@
+.class public LMoveExc;
+.super Ljava/lang/Object;
+
+
+.method public constructor <init>()V
+.registers 1
+       invoke-direct {p0}, Ljava/lang/Object;-><init>()V
+       return-void
+.end method
+
+.method public static run()V
+.registers 6
+:Label1
+       const v1, 15
+       const v2, 0
+       div-int v0, v1, v2
+
+:Label2
+       goto :Label4
+
+:Label3
+       move-exception v3
+       throw v3
+
+:Label4
+       return-void
+
+.catchall {:Label1 .. :Label2} :Label3
+.end method
diff --git a/test/800-smali/src/Main.java b/test/800-smali/src/Main.java
index ea25da6..2eda850 100644
--- a/test/800-smali/src/Main.java
+++ b/test/800-smali/src/Main.java
@@ -68,6 +68,7 @@
         testCases.add(new TestCase("b/18718277", "B18718277", "getInt", null, null, 0));
         testCases.add(new TestCase("b/18800943 (1)", "B18800943_1", "n_a", null, new VerifyError(), 0));
         testCases.add(new TestCase("b/18800943 (2)", "B18800943_2", "n_a", null, new VerifyError(), 0));
+        testCases.add(new TestCase("MoveExc", "MoveExc", "run", null, new ArithmeticException(), null));
     }
 
     public void runTests() {