diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index 1d1d3eee11..9cdbce93cf 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -4318,10 +4318,7 @@ void MethodVerifier::VerifyNewArray(const Instruction* inst, } for (size_t ui = 0; ui < arg_count; ui++) { uint32_t get_reg = is_range ? inst->VRegC_3rc() + ui : arg[ui]; - if (!work_line_->VerifyRegisterType(this, get_reg, expected_type)) { - work_line_->SetResultRegisterType(this, reg_types_.Conflict()); - return; - } + work_line_->VerifyRegisterType(this, get_reg, expected_type); } // filled-array result goes into "result" register const RegType& precise_type = reg_types_.FromUninitialized(res_type); diff --git a/test/847-filled-new-aray/expected-stderr.txt b/test/847-filled-new-aray/expected-stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/847-filled-new-aray/expected-stdout.txt b/test/847-filled-new-aray/expected-stdout.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/847-filled-new-aray/info.txt b/test/847-filled-new-aray/info.txt new file mode 100644 index 0000000000..6244ffb4f7 --- /dev/null +++ b/test/847-filled-new-aray/info.txt @@ -0,0 +1,3 @@ +Regression test for the verifier which used to hard fail when using +filled-new-array with an unresolved type. We now accept it, and a +NoClassDefFoundError will be thrown at runtime. diff --git a/test/847-filled-new-aray/smali/Main.smali b/test/847-filled-new-aray/smali/Main.smali new file mode 100644 index 0000000000..3149e3cca4 --- /dev/null +++ b/test/847-filled-new-aray/smali/Main.smali @@ -0,0 +1,42 @@ +# Copyright 2023 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 LMain; +.super Ljava/lang/Object; + +.method public static main([Ljava/lang/String;)V +.registers 1 + :try_start + new-instance v0, LMissingClass; + invoke-direct {v0}, LMissingClass;->()V + # The verifier used to fail on this instruction used to type v0 as a conflict, + # because LSuperMissingClass was unresolved. This lead to the `move-result-object` + # below to make the class hard fail. + filled-new-array {v0}, [LSuperMissingClass; + move-result-object v0 + invoke-static {v0}, LMain;->doCall([LSuperMissingClass;)V + # Throw a NPE to signal we don't expect to enter here. + const/4 v0, 0 + throw v0 + :try_end + .catch Ljava/lang/NoClassDefFoundError; {:try_start .. :try_end} :catch_0 + :catch_0 + # NoClassDefFoundError expected + return-void +.end method + +.method public static doCall([LSuperMissingClass;)V +.registers 1 + return-void +.end method