complement.carbon 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/int/complement.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/complement.carbon
  10. // --- int_complement.carbon
  11. fn Complement(a: i32) -> i32 = "int.complement";
  12. fn And(a: i32, b: i32) -> i32 = "int.and";
  13. var arr: [i32; And(Complement(0x123456), 0xFFFFFF)];
  14. let arr_p: [i32; 0xEDCBA9]* = &arr;
  15. fn RuntimeCall(a: i32) -> i32 {
  16. return Complement(a);
  17. }
  18. // CHECK:STDOUT: --- int_complement.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  22. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  23. // CHECK:STDOUT: %Complement.type: type = fn_type @Complement [template]
  24. // CHECK:STDOUT: %Complement: %Complement.type = struct_value () [template]
  25. // CHECK:STDOUT: %And.type: type = fn_type @And [template]
  26. // CHECK:STDOUT: %And: %And.type = struct_value () [template]
  27. // CHECK:STDOUT: %int_15584169.2: Core.IntLiteral = int_value 15584169 [template]
  28. // CHECK:STDOUT: %array_type: type = array_type %int_15584169.2, %i32 [template]
  29. // CHECK:STDOUT: %ptr: type = ptr_type %array_type [template]
  30. // CHECK:STDOUT: %RuntimeCall.type: type = fn_type @RuntimeCall [template]
  31. // CHECK:STDOUT: %RuntimeCall: %RuntimeCall.type = struct_value () [template]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  36. // CHECK:STDOUT: .Int = %import_ref.1
  37. // CHECK:STDOUT: .ImplicitAs = %import_ref.5
  38. // CHECK:STDOUT: import Core//prelude
  39. // CHECK:STDOUT: import Core//prelude/...
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .Core = imports.%Core
  46. // CHECK:STDOUT: .Complement = %Complement.decl
  47. // CHECK:STDOUT: .And = %And.decl
  48. // CHECK:STDOUT: .arr = %arr
  49. // CHECK:STDOUT: .arr_p = @__global_init.%arr_p
  50. // CHECK:STDOUT: .RuntimeCall = %RuntimeCall.decl
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %Core.import = import Core
  53. // CHECK:STDOUT: %Complement.decl: %Complement.type = fn_decl @Complement [template = constants.%Complement] {
  54. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  55. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  56. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  57. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  58. // CHECK:STDOUT: } {
  59. // CHECK:STDOUT: %int_32.loc2_26: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  60. // CHECK:STDOUT: %i32.loc2_26: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  61. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  62. // CHECK:STDOUT: %.loc2: type = splice_block %i32.loc2_18 [template = constants.%i32] {
  63. // CHECK:STDOUT: %int_32.loc2_18: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  64. // CHECK:STDOUT: %i32.loc2_18: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  67. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  68. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %And.decl: %And.type = fn_decl @And [template = constants.%And] {
  71. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  72. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  73. // CHECK:STDOUT: %b.patt: %i32 = binding_pattern b
  74. // CHECK:STDOUT: %b.param_patt: %i32 = value_param_pattern %b.patt, runtime_param1
  75. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  76. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param2
  77. // CHECK:STDOUT: } {
  78. // CHECK:STDOUT: %int_32.loc3_27: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  79. // CHECK:STDOUT: %i32.loc3_27: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  80. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  81. // CHECK:STDOUT: %.loc3_11: type = splice_block %i32.loc3_11 [template = constants.%i32] {
  82. // CHECK:STDOUT: %int_32.loc3_11: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  83. // CHECK:STDOUT: %i32.loc3_11: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  86. // CHECK:STDOUT: %b.param: %i32 = value_param runtime_param1
  87. // CHECK:STDOUT: %.loc3_19: type = splice_block %i32.loc3_19 [template = constants.%i32] {
  88. // CHECK:STDOUT: %int_32.loc3_19: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  89. // CHECK:STDOUT: %i32.loc3_19: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  92. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param2
  93. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %arr.var: ref %array_type = var arr
  96. // CHECK:STDOUT: %arr: ref %array_type = bind_name arr, %arr.var
  97. // CHECK:STDOUT: %RuntimeCall.decl: %RuntimeCall.type = fn_decl @RuntimeCall [template = constants.%RuntimeCall] {
  98. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  99. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  100. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  101. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  102. // CHECK:STDOUT: } {
  103. // CHECK:STDOUT: %int_32.loc8_27: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  104. // CHECK:STDOUT: %i32.loc8_27: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  105. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  106. // CHECK:STDOUT: %.loc8: type = splice_block %i32.loc8_19 [template = constants.%i32] {
  107. // CHECK:STDOUT: %int_32.loc8_19: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  108. // CHECK:STDOUT: %i32.loc8_19: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  111. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  112. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: fn @Complement(%a.param_patt: %i32) -> %i32 = "int.complement";
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: fn @And(%a.param_patt: %i32, %b.param_patt: %i32) -> %i32 = "int.and";
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: fn @RuntimeCall(%a.param_patt: %i32) -> %i32 {
  121. // CHECK:STDOUT: !entry:
  122. // CHECK:STDOUT: %Complement.ref: %Complement.type = name_ref Complement, file.%Complement.decl [template = constants.%Complement]
  123. // CHECK:STDOUT: %a.ref: %i32 = name_ref a, %a
  124. // CHECK:STDOUT: %int.complement: init %i32 = call %Complement.ref(%a.ref)
  125. // CHECK:STDOUT: %.loc9_23.1: %i32 = value_of_initializer %int.complement
  126. // CHECK:STDOUT: %.loc9_23.2: %i32 = converted %int.complement, %.loc9_23.1
  127. // CHECK:STDOUT: return %.loc9_23.2
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: fn @__global_init() {
  131. // CHECK:STDOUT: !entry:
  132. // CHECK:STDOUT: %arr.ref: ref %array_type = name_ref arr, file.%arr
  133. // CHECK:STDOUT: %addr: %ptr = addr_of %arr.ref
  134. // CHECK:STDOUT: %arr_p: %ptr = bind_name arr_p, %addr
  135. // CHECK:STDOUT: return
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: