diff options
| -rw-r--r-- | compiler/optimizing/graph_visualizer.cc | 10 | ||||
| -rw-r--r-- | test/486-checker-must-do-null-check/expected.txt | 0 | ||||
| -rw-r--r-- | test/486-checker-must-do-null-check/info.txt | 1 | ||||
| -rw-r--r-- | test/486-checker-must-do-null-check/src/Main.java | 53 |
4 files changed, 64 insertions, 0 deletions
diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc index 424a393f93..7da4f2d1fd 100644 --- a/compiler/optimizing/graph_visualizer.cc +++ b/compiler/optimizing/graph_visualizer.cc @@ -270,6 +270,16 @@ class HGraphVisualizerPrinter : public HGraphVisitor { << load_cass->MustGenerateClinitCheck() << std::noboolalpha; } + void VisitCheckCast(HCheckCast* check_cast) OVERRIDE { + StartAttributeStream("must_do_null_check") << std::boolalpha + << check_cast->MustDoNullCheck() << std::noboolalpha; + } + + void VisitInstanceOf(HInstanceOf* instance_of) OVERRIDE { + StartAttributeStream("must_do_null_check") << std::boolalpha + << instance_of->MustDoNullCheck() << std::noboolalpha; + } + bool IsPass(const char* name) { return strcmp(pass_name_, name) == 0; } diff --git a/test/486-checker-must-do-null-check/expected.txt b/test/486-checker-must-do-null-check/expected.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/486-checker-must-do-null-check/expected.txt diff --git a/test/486-checker-must-do-null-check/info.txt b/test/486-checker-must-do-null-check/info.txt new file mode 100644 index 0000000000..494ff1cbc0 --- /dev/null +++ b/test/486-checker-must-do-null-check/info.txt @@ -0,0 +1 @@ +Verifies MustDoNullCheck() on InstanceOf and CheckCast diff --git a/test/486-checker-must-do-null-check/src/Main.java b/test/486-checker-must-do-null-check/src/Main.java new file mode 100644 index 0000000000..f285566ea7 --- /dev/null +++ b/test/486-checker-must-do-null-check/src/Main.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2015 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. + */ + +public class Main { + // CHECK-START: void Main.InstanceOfPreChecked(java.lang.Object) instruction_simplifier (after) + // CHECK: InstanceOf must_do_null_check:false + public void InstanceOfPreChecked(Object o) throws Exception { + o.toString(); + if (o instanceof Main) { + throw new Exception(); + } + } + + // CHECK-START: void Main.InstanceOf(java.lang.Object) instruction_simplifier (after) + // CHECK: InstanceOf must_do_null_check:true + public void InstanceOf(Object o) throws Exception { + if (o instanceof Main) { + throw new Exception(); + } + } + + // CHECK-START: void Main.CheckCastPreChecked(java.lang.Object) instruction_simplifier (after) + // CHECK: CheckCast must_do_null_check:false + public void CheckCastPreChecked(Object o) { + o.toString(); + ((Main)o).Bar(); + } + + // CHECK-START: void Main.CheckCast(java.lang.Object) instruction_simplifier (after) + // CHECK: CheckCast must_do_null_check:true + public void CheckCast(Object o) { + ((Main)o).Bar(); + } + + void Bar() {throw new RuntimeException();} + + public static void main(String[] sa) { + Main t = new Main(); + } +} |