greater_eq.carbon 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // EXTRA-ARGS: --no-dump-sem-ir
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/int/greater_eq.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/greater_eq.carbon
  12. // --- int_greater_eq.carbon
  13. library "[[@TEST_NAME]]";
  14. fn GreaterEq(a: i32, b: i32) -> bool = "int.greater_eq";
  15. fn Negate(a: i32) -> i32 = "int.snegate";
  16. class True {}
  17. class False {}
  18. fn F(true_: True, false_: False) {
  19. false_ as (if GreaterEq(1, 2) then True else False);
  20. true_ as (if GreaterEq(1, 1) then True else False);
  21. true_ as (if GreaterEq(1, 0) then True else False);
  22. false_ as (if GreaterEq(Negate(1), 0) then True else False);
  23. true_ as (if GreaterEq(0, Negate(1)) then True else False);
  24. }
  25. fn RuntimeCallIsValid(a: i32, b: i32) -> bool {
  26. return GreaterEq(a, b);
  27. }
  28. // --- literal.carbon
  29. library "[[@TEST_NAME]]";
  30. fn GreaterEq(a: Core.IntLiteral(), b: Core.IntLiteral()) -> bool = "int.greater_eq";
  31. class Expect(B:! bool) {}
  32. fn Test(B:! bool) -> Expect(B) { return {}; }
  33. fn F() {
  34. Test(GreaterEq(5, 5)) as Expect(true);
  35. Test(GreaterEq(5, 6)) as Expect(false);
  36. Test(GreaterEq(6, 5)) as Expect(true);
  37. Test(GreaterEq(-1, -1)) as Expect(true);
  38. Test(GreaterEq(-1, 1)) as Expect(false);
  39. Test(GreaterEq(1, -1)) as Expect(true);
  40. }
  41. // --- mixed.carbon
  42. library "[[@TEST_NAME]]";
  43. fn GreaterEq(a: Core.IntLiteral(), b: i32) -> bool = "int.greater_eq";
  44. class Expect(B:! bool) {}
  45. fn Test(B:! bool) -> Expect(B) { return {}; }
  46. fn F() {
  47. Test(GreaterEq(5, 5)) as Expect(true);
  48. Test(GreaterEq(5, 6)) as Expect(false);
  49. Test(GreaterEq(6, 5)) as Expect(true);
  50. Test(GreaterEq(-1, -1)) as Expect(true);
  51. Test(GreaterEq(-1, 1)) as Expect(false);
  52. Test(GreaterEq(1, -1)) as Expect(true);
  53. }