Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Android/art/art/test/409-materialized-condition/src/   (Android Betriebssystem Version 17©)  Datei vom 26.5.2026 mit Größe 4 kB image not shown  

Quelle  Main.java

  Sprache: JAVA
 

/*
 * Copyright (C) 2014 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 {

  public static void doNothing(boolean b) {
    System.out.println("In do nothing.");
  }

  public static void inIf() {
    System.out.println("In if.");
  }

  public static int bar() {
    return 42;
  }

  public static int foo1() {
    int b = bar();
    doNothing(b == 42);
    // This second `b == 42` will be GVN'ed away.
    if (b == 42) {
      inIf();
      return b;
    }
    return 0;
  }

  public static int foo2() {
    int b = bar();
    doNothing(b == 41);
    // This second `b == 41` will be GVN'ed away.
    if (b == 41) {
      inIf();
      return 0;
    }
    return b;
  }

  public static boolean $noinline$intEq0(int x) {
    return x == 0;
  }

  public static boolean $noinline$intNe0(int x) {
    return x != 0;
  }

  public static boolean $noinline$longEq0(long x) {
    return x == 0;
  }

  public static boolean $noinline$longNe0(long x) {
    return x != 0;
  }

  public static boolean $noinline$longEqCst(long x) {
    return x == 0x0123456789ABCDEFL;
  }

  public static boolean $noinline$longNeCst(long x) {
    return x != 0x0123456789ABCDEFL;
  }

  public static void assertEqual(boolean expected, boolean actual) {
    if (expected != actual) {
      throw new Error("Assertion failed: " + expected + " != " + actual);
    }
  }

  // The purpose of this method is to test code generation for a materialized
  // HCondition that is not equality or inequality, and that has one boolean
  // input. That can't be done directly, so we have to rely on the instruction
  // simplifier to transform the control-flow graph appropriately.
  public static boolean $noinline$booleanCondition(boolean in) {
    int value = in ? 1 : 0;

    // Calling a non-inlineable method that uses `value` as well prevents a
    // transformation of the return value into `false`.
    $noinline$intNe0(value);
    return value > 127;
  }

  public static void main(String[] args) {
    System.out.println("foo1");
    int res = foo1();
    if (res != 42) {
      throw new Error("Unexpected return value for foo1: " + res + ", expected 42.");
    }

    System.out.println("foo2");
    res = foo2();
    if (res != 42) {
      throw new Error("Unexpected return value for foo2: " + res + ", expected 42.");
    }

    assertEqual($noinline$booleanCondition(false), false);
    assertEqual($noinline$booleanCondition(true), false);

    int[] int_inputs = {01, -1, Integer.MIN_VALUE, Integer.MAX_VALUE, 42, -9000};
    long[] long_inputs = {
        0L, 1L, -1L, Long.MIN_VALUE, Long.MAX_VALUE, 0x100000000L,
        0x100000001L, -9000L, 0x0123456789ABCDEFL};

    boolean[] int_eq_0_expected = {truefalsefalsefalsefalsefalsefalse};

    for (int i = 0; i < int_inputs.length; i++) {
      assertEqual(int_eq_0_expected[i], $noinline$intEq0(int_inputs[i]));
    }

    boolean[] int_ne_0_expected = {falsetruetruetruetruetruetrue};

    for (int i = 0; i < int_inputs.length; i++) {
      assertEqual(int_ne_0_expected[i], $noinline$intNe0(int_inputs[i]));
    }

    boolean[] long_eq_0_expected = {truefalsefalsefalsefalsefalsefalsefalsefalse};

    for (int i = 0; i < long_inputs.length; i++) {
      assertEqual(long_eq_0_expected[i], $noinline$longEq0(long_inputs[i]));
    }

    boolean[] long_ne_0_expected = {falsetruetruetruetruetruetruetruetrue};

    for (int i = 0; i < long_inputs.length; i++) {
      assertEqual(long_ne_0_expected[i], $noinline$longNe0(long_inputs[i]));
    }

    boolean[] long_eq_cst_expected = {falsefalsefalsefalsefalsefalsefalsefalsetrue};

    for (int i = 0; i < long_inputs.length; i++) {
      assertEqual(long_eq_cst_expected[i], $noinline$longEqCst(long_inputs[i]));
    }

    boolean[] long_ne_cst_expected = {truetruetruetruetruetruetruetruefalse};

    for (int i = 0; i < long_inputs.length; i++) {
      assertEqual(long_ne_cst_expected[i], $noinline$longNeCst(long_inputs[i]));
    }
  }
}

Messung V0.5 in Prozent
C=85 H=94 G=89

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-29) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.