Vdex: Workaround arrays with erroneous component type.

The assignability DCHECK is only reliable when classes are not
erroneous. For arrays whose component type could be erroneous,
the verifier can join types even if they're not assignable.

bug:33770646
Test: verifier_deps_test
Change-Id: I4ec1b12b2e2c7d5b57b51a64aea381f951a38dcd
diff --git a/compiler/verifier_deps_test.cc b/compiler/verifier_deps_test.cc
index fa7e985..3b6b9cc 100644
--- a/compiler/verifier_deps_test.cc
+++ b/compiler/verifier_deps_test.cc
@@ -207,9 +207,9 @@
     ScopedObjectAccess soa(Thread::Current());
     LoadDexFile(&soa);
     mirror::Class* klass_dst = FindClassByName(dst, &soa);
-    DCHECK(klass_dst != nullptr);
+    DCHECK(klass_dst != nullptr) << dst;
     mirror::Class* klass_src = FindClassByName(src, &soa);
-    DCHECK(klass_src != nullptr);
+    DCHECK(klass_src != nullptr) << src;
     verifier_deps_->AddAssignability(*primary_dex_file_,
                                      klass_dst,
                                      klass_src,
@@ -1536,5 +1536,16 @@
   ASSERT_TRUE(HasAssignable("Ljava/lang/Exception;", "LIface;", false));
 }
 
+TEST_F(VerifierDepsTest, Assignable_Arrays) {
+  ASSERT_TRUE(TestAssignabilityRecording(/* dst */ "[LIface;",
+                                         /* src */ "[LMyClassExtendingInterface;",
+                                         /* is_strict */ false,
+                                         /* is_assignable */ true));
+  ASSERT_FALSE(HasAssignable(
+      "LIface;", "LMyClassExtendingInterface;", /* expected_is_assignable */ true));
+  ASSERT_FALSE(HasAssignable(
+      "LIface;", "LMyClassExtendingInterface;", /* expected_is_assignable */ false));
+}
+
 }  // namespace verifier
 }  // namespace art
diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc
index 8e4c166..55e7935 100644
--- a/runtime/verifier/verifier_deps.cc
+++ b/runtime/verifier/verifier_deps.cc
@@ -428,8 +428,6 @@
     return;
   }
 
-  DCHECK_EQ(is_assignable, destination->IsAssignableFrom(source));
-
   if (destination->IsArrayClass() && source->IsArrayClass()) {
     // Both types are arrays. Break down to component types and add recursively.
     // This helps filter out destinations from compiled DEX files (see below)
@@ -447,6 +445,10 @@
                        is_assignable);
       return;
     }
+  } else {
+    // We only do this check for non-array types, as arrays might have erroneous
+    // component types which makes the IsAssignableFrom check unreliable.
+    DCHECK_EQ(is_assignable, destination->IsAssignableFrom(source));
   }
 
   DexFileDeps* dex_deps = GetDexFileDeps(dex_file);
diff --git a/test/VerifierDeps/MyClassExtendingInterface.smali b/test/VerifierDeps/MyClassExtendingInterface.smali
new file mode 100644
index 0000000..43cf13b
--- /dev/null
+++ b/test/VerifierDeps/MyClassExtendingInterface.smali
@@ -0,0 +1,16 @@
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LMyClassExtendingInterface;
+.super LIface;