eq.carbon 2.1 KB

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