diff options
author | 2016-03-30 19:09:03 +0100 | |
---|---|---|
committer | 2016-03-30 19:09:03 +0100 | |
commit | f355c3ff08710ac2eba3aac2aacc5e65caa06b4c (patch) | |
tree | 1d9f9487897fabc539f748be881f9c8140c16cef /compiler/optimizing | |
parent | 6f51d7756a9c66007fe7666b19399e1f60ff6092 (diff) |
Fix Boolean to integral types conversions.
Bug: 27616343
Change-Id: I050f92045bca1b8b5d6da53547cc617f17be84b1
Diffstat (limited to 'compiler/optimizing')
-rw-r--r-- | compiler/optimizing/graph_checker.cc | 15 | ||||
-rw-r--r-- | compiler/optimizing/graph_checker.h | 1 | ||||
-rw-r--r-- | compiler/optimizing/instruction_simplifier.cc | 15 | ||||
-rw-r--r-- | compiler/optimizing/nodes.h | 2 |
4 files changed, 29 insertions, 4 deletions
diff --git a/compiler/optimizing/graph_checker.cc b/compiler/optimizing/graph_checker.cc index f2e77e28a6..c790d013b5 100644 --- a/compiler/optimizing/graph_checker.cc +++ b/compiler/optimizing/graph_checker.cc @@ -1005,4 +1005,19 @@ void GraphChecker::VisitBoundType(HBoundType* instruction) { } } +void GraphChecker::VisitTypeConversion(HTypeConversion* instruction) { + VisitInstruction(instruction); + Primitive::Type result_type = instruction->GetResultType(); + Primitive::Type input_type = instruction->GetInputType(); + // Invariant: We should never generate a conversion to a Boolean value. + if (result_type == Primitive::kPrimBoolean) { + AddError(StringPrintf( + "%s %d converts to a %s (from a %s).", + instruction->DebugName(), + instruction->GetId(), + Primitive::PrettyDescriptor(result_type), + Primitive::PrettyDescriptor(input_type))); + } +} + } // namespace art diff --git a/compiler/optimizing/graph_checker.h b/compiler/optimizing/graph_checker.h index a536b30fcd..83b198474c 100644 --- a/compiler/optimizing/graph_checker.h +++ b/compiler/optimizing/graph_checker.h @@ -67,6 +67,7 @@ class GraphChecker : public HGraphDelegateVisitor { void VisitReturnVoid(HReturnVoid* ret) OVERRIDE; void VisitSelect(HSelect* instruction) OVERRIDE; void VisitTryBoundary(HTryBoundary* try_boundary) OVERRIDE; + void VisitTypeConversion(HTypeConversion* instruction) OVERRIDE; void HandleLoop(HBasicBlock* loop_header); void HandleBooleanInput(HInstruction* instruction, size_t input_index); diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index 1249b48e1e..1f66db7909 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -786,14 +786,21 @@ void InstructionSimplifierVisitor::VisitArraySet(HArraySet* instruction) { } static bool IsTypeConversionImplicit(Primitive::Type input_type, Primitive::Type result_type) { + // Invariant: We should never generate a conversion to a Boolean value. + DCHECK_NE(Primitive::kPrimBoolean, result_type); + // Besides conversion to the same type, widening integral conversions are implicit, // excluding conversions to long and the byte->char conversion where we need to // clear the high 16 bits of the 32-bit sign-extended representation of byte. return result_type == input_type || - (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimByte) || - (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimShort) || - (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimChar) || - (result_type == Primitive::kPrimShort && input_type == Primitive::kPrimByte); + (result_type == Primitive::kPrimInt && (input_type == Primitive::kPrimBoolean || + input_type == Primitive::kPrimByte || + input_type == Primitive::kPrimShort || + input_type == Primitive::kPrimChar)) || + (result_type == Primitive::kPrimChar && input_type == Primitive::kPrimBoolean) || + (result_type == Primitive::kPrimShort && (input_type == Primitive::kPrimBoolean || + input_type == Primitive::kPrimByte)) || + (result_type == Primitive::kPrimByte && input_type == Primitive::kPrimBoolean); } static bool IsTypeConversionLossless(Primitive::Type input_type, Primitive::Type result_type) { diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index e9a42cb0ce..0be75b5a2f 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -4902,6 +4902,8 @@ class HTypeConversion : public HExpression<1> { dex_pc) { SetRawInputAt(0, input); DCHECK_NE(input->GetType(), result_type); + // Invariant: We should never generate a conversion to a Boolean value. + DCHECK_NE(Primitive::kPrimBoolean, result_type); } HInstruction* GetInput() const { return InputAt(0); } |