Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | package com.android.tools.r8; |
| 6 | |
| 7 | import static org.junit.Assert.assertEquals; |
| 8 | |
| 9 | import com.android.tools.r8.dex.ApplicationReader; |
| 10 | import com.android.tools.r8.graph.AppInfoWithSubtyping; |
| 11 | import com.android.tools.r8.graph.DexApplication; |
| 12 | import com.android.tools.r8.graph.DexEncodedMethod; |
| 13 | import com.android.tools.r8.graph.DexProgramClass; |
| 14 | import com.android.tools.r8.ir.conversion.IRConverter; |
| 15 | import com.android.tools.r8.utils.AndroidApp; |
| 16 | import com.android.tools.r8.utils.InternalOptions; |
| 17 | import com.android.tools.r8.utils.Timing; |
| 18 | import java.io.IOException; |
| 19 | import java.nio.file.Path; |
| 20 | import java.nio.file.Paths; |
| 21 | import java.util.concurrent.ExecutionException; |
| 22 | import java.util.concurrent.ExecutorService; |
| 23 | import java.util.concurrent.Executors; |
| 24 | import org.junit.Test; |
| 25 | |
| 26 | public class R8UnreachableCodeTest { |
| 27 | |
| 28 | private static final Path SMALI_DIR = Paths.get(ToolHelper.SMALI_BUILD_DIR); |
| 29 | |
| 30 | @Test |
| 31 | public void UnreachableCode() throws IOException, ExecutionException { |
| 32 | String name = "unreachable-code-1"; |
| 33 | AndroidApp input = AndroidApp.fromProgramFiles(SMALI_DIR.resolve(name).resolve(name + ".dex")); |
| 34 | ExecutorService executorService = Executors.newSingleThreadExecutor(); |
| 35 | Timing timing = new Timing("R8UnreachableCodeTest"); |
| 36 | DexApplication application = |
| 37 | new ApplicationReader(input, new InternalOptions(), timing).read(executorService); |
| 38 | IRConverter converter = |
| 39 | new IRConverter( |
| 40 | application, new AppInfoWithSubtyping(application), new InternalOptions(), null); |
| 41 | converter.optimize(); |
| 42 | DexProgramClass clazz = application.classes().iterator().next(); |
| 43 | assertEquals(4, clazz.directMethods().length); |
| 44 | for (DexEncodedMethod method : clazz.directMethods()) { |
| 45 | if (!method.method.name.toString().equals("main")) { |
| 46 | assertEquals(2, method.getCode().asDexCode().instructions.length); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |