umul.carbon 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/int.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/umul.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/umul.carbon
  12. // --- int_mul.carbon
  13. library "[[@TEST_NAME]]";
  14. fn Mul(a: i32, b: i32) -> i32 = "int.umul";
  15. var arr: array(i32, Mul(3, 2));
  16. let arr_p: array(i32, 6)* = &arr;
  17. fn RuntimeCallIsValid(a: i32, b: i32) -> i32 {
  18. //@dump-sem-ir-begin
  19. return Mul(a, b);
  20. //@dump-sem-ir-end
  21. }
  22. // --- overflow.carbon
  23. library "[[@TEST_NAME]]";
  24. fn Mul(a: i32, b: i32) -> i32 = "int.umul";
  25. let a: i32 = Mul(0x7FFF, 0x10000);
  26. let b: i32 = Mul(0x8000, 0x10000);
  27. // CHECK:STDOUT: --- int_mul.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  31. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  32. // CHECK:STDOUT: %Mul.type: type = fn_type @Mul [concrete]
  33. // CHECK:STDOUT: %Mul: %Mul.type = struct_value () [concrete]
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: imports {
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: fn @RuntimeCallIsValid(%a.param: %i32, %b.param: %i32) -> %i32 {
  40. // CHECK:STDOUT: !entry:
  41. // CHECK:STDOUT: %Mul.ref: %Mul.type = name_ref Mul, file.%Mul.decl [concrete = constants.%Mul]
  42. // CHECK:STDOUT: %a.ref: %i32 = name_ref a, %a
  43. // CHECK:STDOUT: %b.ref: %i32 = name_ref b, %b
  44. // CHECK:STDOUT: %Mul.call: init %i32 = call %Mul.ref(%a.ref, %b.ref)
  45. // CHECK:STDOUT: return %Mul.call to %return
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: fn @__global_init() {
  49. // CHECK:STDOUT: !entry:
  50. // CHECK:STDOUT: <elided>
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: