negate.carbon 3.2 KB

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