Skip to content

Commit

Permalink
Adjust verifier behavior in the presence of unresolved class.
Browse files Browse the repository at this point in the history
Make filled-new-array not set its type as conflict if we fail to verify
assignability. Instead, rely on the assignability check to either hard
fail or record that there is an unresolved type check.

Test: 847-filled-new-array
Bug: 269228249
Change-Id: Iaede8e243d2c833d75e6befea5a4452ac70f7293
  • Loading branch information
Nicolas Geoffray committed Feb 16, 2023
1 parent 03baeff commit ba4ab8e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
5 changes: 1 addition & 4 deletions runtime/verifier/method_verifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4318,10 +4318,7 @@ void MethodVerifier<kVerifierDebug>::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);
Expand Down
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions test/847-filled-new-aray/info.txt
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 42 additions & 0 deletions test/847-filled-new-aray/smali/Main.smali
Original file line number Diff line number Diff line change
@@ -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;-><init>()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

0 comments on commit ba4ab8e

Please sign in to comment.