negate.carbon 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/negate.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/float/negate.carbon
  10. // --- float_negate.carbon
  11. library "[[@TEST_NAME]]";
  12. fn Negate(a: f64) -> f64 = "float.negate";
  13. fn RuntimeCallIsValid(a: f64, b: f64) -> f64 {
  14. //@dump-sem-ir-begin
  15. return Negate(a);
  16. //@dump-sem-ir-end
  17. }
  18. let a: f64 = Negate(1.5);
  19. // --- fail_too_few.carbon
  20. library "[[@TEST_NAME]]";
  21. // CHECK:STDERR: fail_too_few.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "float.negate" [InvalidBuiltinSignature]
  22. // CHECK:STDERR: fn TooFew() -> f64 = "float.negate";
  23. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  24. // CHECK:STDERR:
  25. fn TooFew() -> f64 = "float.negate";
  26. fn RuntimeCallIsValidTooFew() -> f64 {
  27. return TooFew();
  28. }
  29. // --- fail_too_many.carbon
  30. library "[[@TEST_NAME]]";
  31. // CHECK:STDERR: fail_too_many.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "float.negate" [InvalidBuiltinSignature]
  32. // CHECK:STDERR: fn TooMany(a: f64, b: f64) -> f64 = "float.negate";
  33. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. // CHECK:STDERR:
  35. fn TooMany(a: f64, b: f64) -> f64 = "float.negate";
  36. fn RuntimeCallIsValidTooMany(a: f64, b: f64) -> f64 {
  37. return TooMany(a, b);
  38. }
  39. // --- fail_bad_return_type.carbon
  40. library "[[@TEST_NAME]]";
  41. // CHECK:STDERR: fail_bad_return_type.carbon:[[@LINE+4]]:1: error: invalid signature for builtin function "float.negate" [InvalidBuiltinSignature]
  42. // CHECK:STDERR: fn BadReturnType(a: f64) -> bool = "float.negate";
  43. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. // CHECK:STDERR:
  45. fn BadReturnType(a: f64) -> bool = "float.negate";
  46. fn RuntimeCallIsValidBadReturnType(a: f64) -> bool {
  47. return BadReturnType(a);
  48. }
  49. // CHECK:STDOUT: --- float_negate.carbon
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: constants {
  52. // CHECK:STDOUT: %Negate.type: type = fn_type @Negate [concrete]
  53. // CHECK:STDOUT: %Negate: %Negate.type = struct_value () [concrete]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: imports {
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @RuntimeCallIsValid(%a.param: f64, %b.param: f64) -> f64 {
  60. // CHECK:STDOUT: !entry:
  61. // CHECK:STDOUT: %Negate.ref: %Negate.type = name_ref Negate, file.%Negate.decl [concrete = constants.%Negate]
  62. // CHECK:STDOUT: %a.ref: f64 = name_ref a, %a
  63. // CHECK:STDOUT: %float.negate: init f64 = call %Negate.ref(%a.ref)
  64. // CHECK:STDOUT: %.loc8_19.1: f64 = value_of_initializer %float.negate
  65. // CHECK:STDOUT: %.loc8_19.2: f64 = converted %float.negate, %.loc8_19.1
  66. // CHECK:STDOUT: return %.loc8_19.2
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: fn @__global_init() {
  70. // CHECK:STDOUT: !entry:
  71. // CHECK:STDOUT: <elided>
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: