Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 
     18 public class Main {
     19   public static void assertBooleanEquals(boolean expected, boolean result) {
     20     if (expected != result) {
     21       throw new Error("Expected: " + expected + ", found: " + result);
     22     }
     23   }
     24 
     25   public static boolean inlinePhi(boolean x, boolean y, boolean z) {
     26     boolean phi;
     27     if (z) {
     28       phi = x;
     29     } else {
     30       phi = y;
     31     }
     32     return phi;
     33   }
     34 
     35   public static boolean dontUseParam(boolean x) {
     36     return false;
     37   }
     38 
     39   public static boolean testCase(boolean x, boolean y, boolean z) {
     40     // First create a Phi(x, y).
     41     boolean phi = inlinePhi(x, y, z);
     42     // Now use the phi as a condition which the boolean simplifier will try to
     43     // optimize out. If the result is not used, the algorithm will try to remove
     44     // the original condition (phi) and crash.
     45     return dontUseParam(phi == false ? false : true);
     46   }
     47 
     48   public static void main(String[] args) {
     49     assertBooleanEquals(false, testCase(true, true, true));
     50   }
     51 }
     52