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