-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for incorrect member value propagation
Bug: 138912149 Change-Id: Ic2c5567e7ed0f04b919f205ce820f1bbc5991f8c
- Loading branch information
Showing
2 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/test/java/com/android/tools/r8/ir/optimize/membervaluepropagation/B138912149.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
package com.android.tools.r8.ir.optimize.membervaluepropagation; | ||
|
||
import static org.junit.Assume.assumeTrue; | ||
|
||
import com.android.tools.r8.TestBase; | ||
import com.android.tools.r8.TestParameters; | ||
import com.android.tools.r8.TestParametersCollection; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
@RunWith(Parameterized.class) | ||
public class B138912149 extends TestBase { | ||
|
||
private final TestParameters parameters; | ||
|
||
@Parameters(name = "{0}") | ||
public static TestParametersCollection data() { | ||
return getTestParameters().withAllRuntimes().build(); | ||
} | ||
|
||
public B138912149(TestParameters parameters) { | ||
this.parameters = parameters; | ||
} | ||
|
||
@Test | ||
public void test() throws Exception { | ||
testForR8(parameters.getBackend()) | ||
.addInnerClasses(B138912149.class) | ||
.addKeepMainRule(TestClass.class) | ||
.setMinApi(parameters.getRuntime()) | ||
.compile() | ||
.run(parameters.getRuntime(), TestClass.class) | ||
// TODO(b/138912149): Should be "The end". | ||
.assertSuccessWithOutputLines("Dead code 2", "The end"); | ||
} | ||
|
||
@Test | ||
public void testJvm() throws Exception { | ||
assumeTrue(parameters.isCfRuntime()); | ||
testForJvm() | ||
.addTestClasspath() | ||
.run(parameters.getRuntime(), TestClass.class) | ||
.assertSuccessWithOutputLines("The end"); | ||
} | ||
|
||
static class TestClass { | ||
|
||
public static void main(String... args) { | ||
if (A.alwaysFalse) { | ||
System.out.println("Dead code 1"); | ||
} | ||
if (B.alwaysFalse || !B.alwaysTrue) { | ||
System.out.println("Dead code 2"); | ||
} | ||
System.out.println("The end"); | ||
} | ||
} | ||
|
||
static class A { | ||
static boolean alwaysFalse; | ||
|
||
static { | ||
alwaysFalse = false; | ||
} | ||
} | ||
|
||
static class B extends A { | ||
static boolean alwaysTrue; | ||
|
||
static { | ||
alwaysTrue = alwaysFalse; | ||
// Either keep this static-put or remove both static-put's and put `true` to `alwaysTrue`. | ||
alwaysTrue = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters