less.carbon 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/int/less.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/less.carbon
  10. // --- int_less.carbon
  11. fn Less(a: i32, b: i32) -> bool = "int.less";
  12. fn Negate(a: i32) -> i32 = "int.snegate";
  13. class True {}
  14. class False {}
  15. fn F(true_: True, false_: False) {
  16. true_ as (if Less(1, 2) then True else False);
  17. false_ as (if Less(1, 1) then True else False);
  18. false_ as (if Less(1, 0) then True else False);
  19. true_ as (if Less(Negate(1), 0) then True else False);
  20. false_ as (if Less(0, Negate(1)) then True else False);
  21. }
  22. fn RuntimeCallIsValid(a: i32, b: i32) -> bool {
  23. //@dump-sem-ir-begin
  24. return Less(a, b);
  25. //@dump-sem-ir-end
  26. }
  27. // CHECK:STDOUT: --- int_less.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  31. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  32. // CHECK:STDOUT: %Less.type.3f8: type = fn_type @Less.1 [concrete]
  33. // CHECK:STDOUT: %Less.f01: %Less.type.3f8 = struct_value () [concrete]
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: imports {
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: fn @RuntimeCallIsValid(%a.param: %i32, %b.param: %i32) -> bool {
  40. // CHECK:STDOUT: !entry:
  41. // CHECK:STDOUT: %Less.ref: %Less.type.3f8 = name_ref Less, file.%Less.decl [concrete = constants.%Less.f01]
  42. // CHECK:STDOUT: %a.ref: %i32 = name_ref a, %a
  43. // CHECK:STDOUT: %b.ref: %i32 = name_ref b, %b
  44. // CHECK:STDOUT: %int.less: init bool = call %Less.ref(%a.ref, %b.ref)
  45. // CHECK:STDOUT: %.loc18_20.1: bool = value_of_initializer %int.less
  46. // CHECK:STDOUT: %.loc18_20.2: bool = converted %int.less, %.loc18_20.1
  47. // CHECK:STDOUT: return %.loc18_20.2
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: