eq.carbon 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/float/eq.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/float/eq.carbon
  12. // --- float_eq.carbon
  13. fn Eq(a: f64, b: f64) -> bool = "float.eq";
  14. class True {}
  15. class False {}
  16. fn F(true_: True, false_: False) {
  17. true_ as (if Eq(1.0, 1.0) then True else False);
  18. false_ as (if Eq(1.0, 2.0) then True else False);
  19. }
  20. fn RuntimeCallIsValid(a: f64, b: f64) -> bool {
  21. //@dump-sem-ir-begin
  22. return Eq(a, b);
  23. //@dump-sem-ir-end
  24. }
  25. // --- fail_bad_decl.carbon
  26. library "[[@TEST_NAME]]";
  27. // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "float.eq" [InvalidBuiltinSignature]
  28. // CHECK:STDERR: fn WrongResult(a: f64, b: f64) -> f64 = "float.eq";
  29. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  30. // CHECK:STDERR:
  31. fn WrongResult(a: f64, b: f64) -> f64 = "float.eq";
  32. // --- fail_literal.carbon
  33. library "[[@TEST_NAME]]";
  34. // CHECK:STDERR: fail_literal.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "float.eq" [InvalidBuiltinSignature]
  35. // CHECK:STDERR: fn Eq(a: Core.FloatLiteral(), b: Core.FloatLiteral()) -> bool = "float.eq";
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. // CHECK:STDERR:
  38. fn Eq(a: Core.FloatLiteral(), b: Core.FloatLiteral()) -> bool = "float.eq";
  39. // CHECK:STDOUT: --- float_eq.carbon
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: constants {
  42. // CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [concrete]
  43. // CHECK:STDOUT: %f64.d77: type = class_type @Float, @Float(%int_64) [concrete]
  44. // CHECK:STDOUT: %Eq.type: type = fn_type @Eq [concrete]
  45. // CHECK:STDOUT: %Eq: %Eq.type = struct_value () [concrete]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: imports {
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: fn @RuntimeCallIsValid(%a.param: %f64.d77, %b.param: %f64.d77) -> bool {
  52. // CHECK:STDOUT: !entry:
  53. // CHECK:STDOUT: %Eq.ref: %Eq.type = name_ref Eq, file.%Eq.decl [concrete = constants.%Eq]
  54. // CHECK:STDOUT: %a.ref: %f64.d77 = name_ref a, %a
  55. // CHECK:STDOUT: %b.ref: %f64.d77 = name_ref b, %b
  56. // CHECK:STDOUT: %Eq.call: init bool = call %Eq.ref(%a.ref, %b.ref)
  57. // CHECK:STDOUT: return %Eq.call to %return.param
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: