summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kyle <stephen.kyle@arm.com>2014-10-03 13:47:56 +0100
committerStephen Kyle <stephen.kyle@arm.com>2014-11-07 12:51:33 +0000
commit40d3518414202f33c9569ddd8daceabb30208fc2 (patch)
treea28dd757a6a9d212a8d2feb3dfdbcfe584e18c6d
parent88af00a788002196e6f98acd3748f3f4956032bf (diff)
downloadart-40d3518414202f33c9569ddd8daceabb30208fc2.zip
art-40d3518414202f33c9569ddd8daceabb30208fc2.tar.gz
art-40d3518414202f33c9569ddd8daceabb30208fc2.tar.bz2
ART: Fix crash with unreachable void check-cast
return-void check-cast v0, V return-void The above code sequence will not be rejected for the check-cast of a void type because the check-cast is not reachable. However, when GenerateSafeCastSet() is called from the compiler, this will cause IsAssignableFrom(Conflict, Undefined) to be called, as it scans for all check-casts across the code, regardless of its reachableness. RegType::AssignableFrom() has been changed to handle a Conflict type, whereas previously this would break the check that the lhs type is a ReferenceType. Additionally, GenerateSafeCastSet has been changed to never assess instructions that weren't visited during verification. Included is a new test DEX file, 801-VoidCheckCast, that uses this code sequence. Change-Id: I600055ab670ee48a075ffa867b46d2e74f5aa9c0 Signed-off-by: Stephen Kyle <stephen.kyle@arm.com>
-rw-r--r--compiler/dex/verified_method.cc4
-rw-r--r--runtime/verifier/reg_type-inl.h3
-rw-r--r--test/801-VoidCheckCast/classes.dexbin0 -> 660 bytes
-rw-r--r--test/801-VoidCheckCast/expected.txt0
-rw-r--r--test/801-VoidCheckCast/info.txt4
-rwxr-xr-xtest/etc/default-build5
6 files changed, 16 insertions, 0 deletions
diff --git a/compiler/dex/verified_method.cc b/compiler/dex/verified_method.cc
index 9f0a696..17328c4 100644
--- a/compiler/dex/verified_method.cc
+++ b/compiler/dex/verified_method.cc
@@ -282,6 +282,10 @@ void VerifiedMethod::GenerateSafeCastSet(verifier::MethodVerifier* method_verifi
Instruction::Code code = inst->Opcode();
if ((code == Instruction::CHECK_CAST) || (code == Instruction::APUT_OBJECT)) {
uint32_t dex_pc = inst->GetDexPc(code_item->insns_);
+ if (!method_verifier->GetInstructionFlags(dex_pc).IsVisited()) {
+ // Do not attempt to quicken this instruction, it's unreachable anyway.
+ continue;
+ }
const verifier::RegisterLine* line = method_verifier->GetRegLine(dex_pc);
bool is_safe_cast = false;
if (code == Instruction::CHECK_CAST) {
diff --git a/runtime/verifier/reg_type-inl.h b/runtime/verifier/reg_type-inl.h
index 480ed40..f445132 100644
--- a/runtime/verifier/reg_type-inl.h
+++ b/runtime/verifier/reg_type-inl.h
@@ -81,6 +81,9 @@ inline bool RegType::AssignableFrom(const RegType& lhs, const RegType& rhs, bool
return rhs.IsLongTypes();
} else if (lhs.IsDoubleLo()) {
return rhs.IsDoubleTypes();
+ } else if (lhs.IsConflict()) {
+ LOG(WARNING) << "RegType::AssignableFrom lhs is Conflict!";
+ return false;
} else {
CHECK(lhs.IsReferenceTypes())
<< "Unexpected register type in IsAssignableFrom: '"
diff --git a/test/801-VoidCheckCast/classes.dex b/test/801-VoidCheckCast/classes.dex
new file mode 100644
index 0000000..e6f0f02
--- /dev/null
+++ b/test/801-VoidCheckCast/classes.dex
Binary files differ
diff --git a/test/801-VoidCheckCast/expected.txt b/test/801-VoidCheckCast/expected.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/801-VoidCheckCast/expected.txt
diff --git a/test/801-VoidCheckCast/info.txt b/test/801-VoidCheckCast/info.txt
new file mode 100644
index 0000000..422f740
--- /dev/null
+++ b/test/801-VoidCheckCast/info.txt
@@ -0,0 +1,4 @@
+A test that is only available as a DEX binary.
+
+This tests that an attempt to use check-cast with the void type doesn't
+cause the compiler to crash.
diff --git a/test/etc/default-build b/test/etc/default-build
index ab859ec..6731ad3 100755
--- a/test/etc/default-build
+++ b/test/etc/default-build
@@ -17,6 +17,11 @@
# Stop if something fails.
set -e
+if [ -e classes.dex ]; then
+ zip $TEST_NAME.jar classes.dex
+ exit 0
+fi
+
mkdir classes
${JAVAC} -d classes `find src -name '*.java'`