dex2oat: Do not crash on InitializeClass() exceptions.

Previously `ClassLinker::EnsureInitialized()` could have
returned with a pending exception even when initializing
fields and parents was not allowed and the CompilerDriver
did not expect it, leading to a crash. Change the behavior
to consistently suppress exceptions when initializing
fields and/or parents is not allowed.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 184094466
Change-Id: I6a8af8c1da792c946f8f52ed4513ab1f0ccf2c9f
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 745e7cf..df49a3a 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -5862,6 +5862,10 @@
   if (!success) {
     if (can_init_fields && can_init_parents) {
       CHECK(self->IsExceptionPending()) << c->PrettyClass();
+    } else {
+      // There may or may not be an exception pending. If there is, clear it.
+      // We propagate the exception only if we can initialize fields and parents.
+      self->ClearException();
     }
   } else {
     self->AssertNoPendingException();