left_shift.carbon 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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/left_shift.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/int/left_shift.carbon
  10. // --- int_left_shift.carbon
  11. fn LeftShift(a: i32, b: i32) -> i32 = "int.left_shift";
  12. var arr: [i32; LeftShift(5, 2)];
  13. let arr_p: [i32; 20]* = &arr;
  14. fn RuntimeCall(a: i32, b: i32) -> i32 {
  15. return LeftShift(a, b);
  16. }
  17. // TODO: Test mixed types for LHS and RHS.
  18. // --- fail_bad_shift.carbon
  19. package BadShift;
  20. fn LeftShift(a: i32, b: i32) -> i32 = "int.left_shift";
  21. fn Negate(a: i32) -> i32 = "int.snegate";
  22. // Shift greater than size is disallowed.
  23. let size_1: i32 = LeftShift(1, 31);
  24. // CHECK:STDERR: fail_bad_shift.carbon:[[@LINE+4]]:19: ERROR: Shift distance not in range [0, 32) in 1 << 32.
  25. // CHECK:STDERR: let size_2: i32 = LeftShift(1, 32);
  26. // CHECK:STDERR: ^~~~~~~~~~
  27. // CHECK:STDERR:
  28. let size_2: i32 = LeftShift(1, 32);
  29. // CHECK:STDERR: fail_bad_shift.carbon:[[@LINE+4]]:19: ERROR: Shift distance not in range [0, 32) in 1 << 33.
  30. // CHECK:STDERR: let size_3: i32 = LeftShift(1, 33);
  31. // CHECK:STDERR: ^~~~~~~~~~
  32. // CHECK:STDERR:
  33. let size_3: i32 = LeftShift(1, 33);
  34. // Overflow is allowed if the shift distance is in bounds.
  35. let overflow_1: i32 = LeftShift(1000, 31);
  36. // CHECK:STDERR: fail_bad_shift.carbon:[[@LINE+4]]:23: ERROR: Shift distance not in range [0, 32) in 1000 << 32.
  37. // CHECK:STDERR: let overflow_2: i32 = LeftShift(1000, 32);
  38. // CHECK:STDERR: ^~~~~~~~~~
  39. // CHECK:STDERR:
  40. let overflow_2: i32 = LeftShift(1000, 32);
  41. // Oversize shifts aren't allowed even if there's no overflow.
  42. let no_overflow_1: i32 = LeftShift(0, 31);
  43. // CHECK:STDERR: fail_bad_shift.carbon:[[@LINE+4]]:26: ERROR: Shift distance not in range [0, 32) in 0 << 32.
  44. // CHECK:STDERR: let no_overflow_2: i32 = LeftShift(0, 32);
  45. // CHECK:STDERR: ^~~~~~~~~~
  46. // CHECK:STDERR:
  47. let no_overflow_2: i32 = LeftShift(0, 32);
  48. // Negative shifts aren't allowed either.
  49. // CHECK:STDERR: fail_bad_shift.carbon:[[@LINE+3]]:21: ERROR: Shift distance not in range [0, 32) in 1 << -1.
  50. // CHECK:STDERR: let negative: i32 = LeftShift(1, Negate(1));
  51. // CHECK:STDERR: ^~~~~~~~~~
  52. let negative: i32 = LeftShift(1, Negate(1));
  53. // CHECK:STDOUT: --- int_left_shift.carbon
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: constants {
  56. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  57. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  58. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  59. // CHECK:STDOUT: %LeftShift.type: type = fn_type @LeftShift [template]
  60. // CHECK:STDOUT: %LeftShift: %LeftShift.type = struct_value () [template]
  61. // CHECK:STDOUT: %.2: i32 = int_literal 5 [template]
  62. // CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
  63. // CHECK:STDOUT: %.4: i32 = int_literal 20 [template]
  64. // CHECK:STDOUT: %.5: type = array_type %.4, i32 [template]
  65. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  66. // CHECK:STDOUT: %RuntimeCall.type: type = fn_type @RuntimeCall [template]
  67. // CHECK:STDOUT: %RuntimeCall: %RuntimeCall.type = struct_value () [template]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: file {
  71. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  72. // CHECK:STDOUT: .Core = %Core
  73. // CHECK:STDOUT: .LeftShift = %LeftShift.decl
  74. // CHECK:STDOUT: .arr = %arr
  75. // CHECK:STDOUT: .arr_p = @__global_init.%arr_p
  76. // CHECK:STDOUT: .RuntimeCall = %RuntimeCall.decl
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  79. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  80. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  81. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  82. // CHECK:STDOUT: %LeftShift.decl: %LeftShift.type = fn_decl @LeftShift [template = constants.%LeftShift] {
  83. // CHECK:STDOUT: %int.make_type_32.loc2_17: init type = call constants.%Int32() [template = i32]
  84. // CHECK:STDOUT: %.loc2_17.1: type = value_of_initializer %int.make_type_32.loc2_17 [template = i32]
  85. // CHECK:STDOUT: %.loc2_17.2: type = converted %int.make_type_32.loc2_17, %.loc2_17.1 [template = i32]
  86. // CHECK:STDOUT: %a.loc2_14.1: i32 = param a
  87. // CHECK:STDOUT: @LeftShift.%a: i32 = bind_name a, %a.loc2_14.1
  88. // CHECK:STDOUT: %int.make_type_32.loc2_25: init type = call constants.%Int32() [template = i32]
  89. // CHECK:STDOUT: %.loc2_25.1: type = value_of_initializer %int.make_type_32.loc2_25 [template = i32]
  90. // CHECK:STDOUT: %.loc2_25.2: type = converted %int.make_type_32.loc2_25, %.loc2_25.1 [template = i32]
  91. // CHECK:STDOUT: %b.loc2_22.1: i32 = param b
  92. // CHECK:STDOUT: @LeftShift.%b: i32 = bind_name b, %b.loc2_22.1
  93. // CHECK:STDOUT: %int.make_type_32.loc2_33: init type = call constants.%Int32() [template = i32]
  94. // CHECK:STDOUT: %.loc2_33.1: type = value_of_initializer %int.make_type_32.loc2_33 [template = i32]
  95. // CHECK:STDOUT: %.loc2_33.2: type = converted %int.make_type_32.loc2_33, %.loc2_33.1 [template = i32]
  96. // CHECK:STDOUT: @LeftShift.%return: ref i32 = var <return slot>
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  99. // CHECK:STDOUT: %int.make_type_32.loc4: init type = call constants.%Int32() [template = i32]
  100. // CHECK:STDOUT: %LeftShift.ref: %LeftShift.type = name_ref LeftShift, %LeftShift.decl [template = constants.%LeftShift]
  101. // CHECK:STDOUT: %.loc4_26: i32 = int_literal 5 [template = constants.%.2]
  102. // CHECK:STDOUT: %.loc4_29: i32 = int_literal 2 [template = constants.%.3]
  103. // CHECK:STDOUT: %int.left_shift: init i32 = call %LeftShift.ref(%.loc4_26, %.loc4_29) [template = constants.%.4]
  104. // CHECK:STDOUT: %.loc4_11.1: type = value_of_initializer %int.make_type_32.loc4 [template = i32]
  105. // CHECK:STDOUT: %.loc4_11.2: type = converted %int.make_type_32.loc4, %.loc4_11.1 [template = i32]
  106. // CHECK:STDOUT: %.loc4_31: type = array_type %int.left_shift, i32 [template = constants.%.5]
  107. // CHECK:STDOUT: %arr.var: ref %.5 = var arr
  108. // CHECK:STDOUT: %arr: ref %.5 = bind_name arr, %arr.var
  109. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  110. // CHECK:STDOUT: %int.make_type_32.loc5: init type = call constants.%Int32() [template = i32]
  111. // CHECK:STDOUT: %.loc5_18: i32 = int_literal 20 [template = constants.%.4]
  112. // CHECK:STDOUT: %.loc5_13.1: type = value_of_initializer %int.make_type_32.loc5 [template = i32]
  113. // CHECK:STDOUT: %.loc5_13.2: type = converted %int.make_type_32.loc5, %.loc5_13.1 [template = i32]
  114. // CHECK:STDOUT: %.loc5_20: type = array_type %.loc5_18, i32 [template = constants.%.5]
  115. // CHECK:STDOUT: %.loc5_21: type = ptr_type %.5 [template = constants.%.6]
  116. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  117. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  118. // CHECK:STDOUT: %import_ref.8: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  119. // CHECK:STDOUT: %RuntimeCall.decl: %RuntimeCall.type = fn_decl @RuntimeCall [template = constants.%RuntimeCall] {
  120. // CHECK:STDOUT: %int.make_type_32.loc7_19: init type = call constants.%Int32() [template = i32]
  121. // CHECK:STDOUT: %.loc7_19.1: type = value_of_initializer %int.make_type_32.loc7_19 [template = i32]
  122. // CHECK:STDOUT: %.loc7_19.2: type = converted %int.make_type_32.loc7_19, %.loc7_19.1 [template = i32]
  123. // CHECK:STDOUT: %a.loc7_16.1: i32 = param a
  124. // CHECK:STDOUT: @RuntimeCall.%a: i32 = bind_name a, %a.loc7_16.1
  125. // CHECK:STDOUT: %int.make_type_32.loc7_27: init type = call constants.%Int32() [template = i32]
  126. // CHECK:STDOUT: %.loc7_27.1: type = value_of_initializer %int.make_type_32.loc7_27 [template = i32]
  127. // CHECK:STDOUT: %.loc7_27.2: type = converted %int.make_type_32.loc7_27, %.loc7_27.1 [template = i32]
  128. // CHECK:STDOUT: %b.loc7_24.1: i32 = param b
  129. // CHECK:STDOUT: @RuntimeCall.%b: i32 = bind_name b, %b.loc7_24.1
  130. // CHECK:STDOUT: %int.make_type_32.loc7_35: init type = call constants.%Int32() [template = i32]
  131. // CHECK:STDOUT: %.loc7_35.1: type = value_of_initializer %int.make_type_32.loc7_35 [template = i32]
  132. // CHECK:STDOUT: %.loc7_35.2: type = converted %int.make_type_32.loc7_35, %.loc7_35.1 [template = i32]
  133. // CHECK:STDOUT: @RuntimeCall.%return: ref i32 = var <return slot>
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: fn @LeftShift(%a: i32, %b: i32) -> i32 = "int.left_shift";
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: fn @RuntimeCall(%a: i32, %b: i32) -> i32 {
  142. // CHECK:STDOUT: !entry:
  143. // CHECK:STDOUT: %LeftShift.ref: %LeftShift.type = name_ref LeftShift, file.%LeftShift.decl [template = constants.%LeftShift]
  144. // CHECK:STDOUT: %a.ref: i32 = name_ref a, %a
  145. // CHECK:STDOUT: %b.ref: i32 = name_ref b, %b
  146. // CHECK:STDOUT: %int.left_shift: init i32 = call %LeftShift.ref(%a.ref, %b.ref)
  147. // CHECK:STDOUT: %.loc8_25.1: i32 = value_of_initializer %int.left_shift
  148. // CHECK:STDOUT: %.loc8_25.2: i32 = converted %int.left_shift, %.loc8_25.1
  149. // CHECK:STDOUT: return %.loc8_25.2
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: fn @__global_init() {
  153. // CHECK:STDOUT: !entry:
  154. // CHECK:STDOUT: %arr.ref: ref %.5 = name_ref arr, file.%arr
  155. // CHECK:STDOUT: %.loc5: %.6 = addr_of %arr.ref
  156. // CHECK:STDOUT: %arr_p: %.6 = bind_name arr_p, %.loc5
  157. // CHECK:STDOUT: return
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: --- fail_bad_shift.carbon
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: constants {
  163. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  164. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  165. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  166. // CHECK:STDOUT: %LeftShift.type: type = fn_type @LeftShift [template]
  167. // CHECK:STDOUT: %LeftShift: %LeftShift.type = struct_value () [template]
  168. // CHECK:STDOUT: %Negate.type: type = fn_type @Negate [template]
  169. // CHECK:STDOUT: %Negate: %Negate.type = struct_value () [template]
  170. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  171. // CHECK:STDOUT: %.3: i32 = int_literal 31 [template]
  172. // CHECK:STDOUT: %.4: i32 = int_literal -2147483648 [template]
  173. // CHECK:STDOUT: %.5: i32 = int_literal 32 [template]
  174. // CHECK:STDOUT: %.6: i32 = int_literal 33 [template]
  175. // CHECK:STDOUT: %.7: i32 = int_literal 1000 [template]
  176. // CHECK:STDOUT: %.8: i32 = int_literal 0 [template]
  177. // CHECK:STDOUT: %.9: i32 = int_literal -1 [template]
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: file {
  181. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  182. // CHECK:STDOUT: .Core = %Core
  183. // CHECK:STDOUT: .LeftShift = %LeftShift.decl
  184. // CHECK:STDOUT: .Negate = %Negate.decl
  185. // CHECK:STDOUT: .size_1 = @__global_init.%size_1
  186. // CHECK:STDOUT: .size_2 = @__global_init.%size_2
  187. // CHECK:STDOUT: .size_3 = @__global_init.%size_3
  188. // CHECK:STDOUT: .overflow_1 = @__global_init.%overflow_1
  189. // CHECK:STDOUT: .overflow_2 = @__global_init.%overflow_2
  190. // CHECK:STDOUT: .no_overflow_1 = @__global_init.%no_overflow_1
  191. // CHECK:STDOUT: .no_overflow_2 = @__global_init.%no_overflow_2
  192. // CHECK:STDOUT: .negative = @__global_init.%negative
  193. // CHECK:STDOUT: }
  194. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  195. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  196. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  197. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  198. // CHECK:STDOUT: %LeftShift.decl: %LeftShift.type = fn_decl @LeftShift [template = constants.%LeftShift] {
  199. // CHECK:STDOUT: %int.make_type_32.loc4_17: init type = call constants.%Int32() [template = i32]
  200. // CHECK:STDOUT: %.loc4_17.1: type = value_of_initializer %int.make_type_32.loc4_17 [template = i32]
  201. // CHECK:STDOUT: %.loc4_17.2: type = converted %int.make_type_32.loc4_17, %.loc4_17.1 [template = i32]
  202. // CHECK:STDOUT: %a.loc4_14.1: i32 = param a
  203. // CHECK:STDOUT: @LeftShift.%a: i32 = bind_name a, %a.loc4_14.1
  204. // CHECK:STDOUT: %int.make_type_32.loc4_25: init type = call constants.%Int32() [template = i32]
  205. // CHECK:STDOUT: %.loc4_25.1: type = value_of_initializer %int.make_type_32.loc4_25 [template = i32]
  206. // CHECK:STDOUT: %.loc4_25.2: type = converted %int.make_type_32.loc4_25, %.loc4_25.1 [template = i32]
  207. // CHECK:STDOUT: %b.loc4_22.1: i32 = param b
  208. // CHECK:STDOUT: @LeftShift.%b: i32 = bind_name b, %b.loc4_22.1
  209. // CHECK:STDOUT: %int.make_type_32.loc4_33: init type = call constants.%Int32() [template = i32]
  210. // CHECK:STDOUT: %.loc4_33.1: type = value_of_initializer %int.make_type_32.loc4_33 [template = i32]
  211. // CHECK:STDOUT: %.loc4_33.2: type = converted %int.make_type_32.loc4_33, %.loc4_33.1 [template = i32]
  212. // CHECK:STDOUT: @LeftShift.%return: ref i32 = var <return slot>
  213. // CHECK:STDOUT: }
  214. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  215. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  216. // CHECK:STDOUT: %Negate.decl: %Negate.type = fn_decl @Negate [template = constants.%Negate] {
  217. // CHECK:STDOUT: %int.make_type_32.loc5_14: init type = call constants.%Int32() [template = i32]
  218. // CHECK:STDOUT: %.loc5_14.1: type = value_of_initializer %int.make_type_32.loc5_14 [template = i32]
  219. // CHECK:STDOUT: %.loc5_14.2: type = converted %int.make_type_32.loc5_14, %.loc5_14.1 [template = i32]
  220. // CHECK:STDOUT: %a.loc5_11.1: i32 = param a
  221. // CHECK:STDOUT: @Negate.%a: i32 = bind_name a, %a.loc5_11.1
  222. // CHECK:STDOUT: %int.make_type_32.loc5_22: init type = call constants.%Int32() [template = i32]
  223. // CHECK:STDOUT: %.loc5_22.1: type = value_of_initializer %int.make_type_32.loc5_22 [template = i32]
  224. // CHECK:STDOUT: %.loc5_22.2: type = converted %int.make_type_32.loc5_22, %.loc5_22.1 [template = i32]
  225. // CHECK:STDOUT: @Negate.%return: ref i32 = var <return slot>
  226. // CHECK:STDOUT: }
  227. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  228. // CHECK:STDOUT: %int.make_type_32.loc8: init type = call constants.%Int32() [template = i32]
  229. // CHECK:STDOUT: %.loc8_13.1: type = value_of_initializer %int.make_type_32.loc8 [template = i32]
  230. // CHECK:STDOUT: %.loc8_13.2: type = converted %int.make_type_32.loc8, %.loc8_13.1 [template = i32]
  231. // CHECK:STDOUT: %import_ref.7: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  232. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  233. // CHECK:STDOUT: %.loc13_13.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  234. // CHECK:STDOUT: %.loc13_13.2: type = converted %int.make_type_32.loc13, %.loc13_13.1 [template = i32]
  235. // CHECK:STDOUT: %import_ref.8: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  236. // CHECK:STDOUT: %int.make_type_32.loc18: init type = call constants.%Int32() [template = i32]
  237. // CHECK:STDOUT: %.loc18_13.1: type = value_of_initializer %int.make_type_32.loc18 [template = i32]
  238. // CHECK:STDOUT: %.loc18_13.2: type = converted %int.make_type_32.loc18, %.loc18_13.1 [template = i32]
  239. // CHECK:STDOUT: %import_ref.9: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  240. // CHECK:STDOUT: %int.make_type_32.loc21: init type = call constants.%Int32() [template = i32]
  241. // CHECK:STDOUT: %.loc21_17.1: type = value_of_initializer %int.make_type_32.loc21 [template = i32]
  242. // CHECK:STDOUT: %.loc21_17.2: type = converted %int.make_type_32.loc21, %.loc21_17.1 [template = i32]
  243. // CHECK:STDOUT: %import_ref.10: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  244. // CHECK:STDOUT: %int.make_type_32.loc26: init type = call constants.%Int32() [template = i32]
  245. // CHECK:STDOUT: %.loc26_17.1: type = value_of_initializer %int.make_type_32.loc26 [template = i32]
  246. // CHECK:STDOUT: %.loc26_17.2: type = converted %int.make_type_32.loc26, %.loc26_17.1 [template = i32]
  247. // CHECK:STDOUT: %import_ref.11: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  248. // CHECK:STDOUT: %int.make_type_32.loc29: init type = call constants.%Int32() [template = i32]
  249. // CHECK:STDOUT: %.loc29_20.1: type = value_of_initializer %int.make_type_32.loc29 [template = i32]
  250. // CHECK:STDOUT: %.loc29_20.2: type = converted %int.make_type_32.loc29, %.loc29_20.1 [template = i32]
  251. // CHECK:STDOUT: %import_ref.12: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  252. // CHECK:STDOUT: %int.make_type_32.loc34: init type = call constants.%Int32() [template = i32]
  253. // CHECK:STDOUT: %.loc34_20.1: type = value_of_initializer %int.make_type_32.loc34 [template = i32]
  254. // CHECK:STDOUT: %.loc34_20.2: type = converted %int.make_type_32.loc34, %.loc34_20.1 [template = i32]
  255. // CHECK:STDOUT: %import_ref.13: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  256. // CHECK:STDOUT: %int.make_type_32.loc40: init type = call constants.%Int32() [template = i32]
  257. // CHECK:STDOUT: %.loc40_15.1: type = value_of_initializer %int.make_type_32.loc40 [template = i32]
  258. // CHECK:STDOUT: %.loc40_15.2: type = converted %int.make_type_32.loc40, %.loc40_15.1 [template = i32]
  259. // CHECK:STDOUT: }
  260. // CHECK:STDOUT:
  261. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  262. // CHECK:STDOUT:
  263. // CHECK:STDOUT: fn @LeftShift(%a: i32, %b: i32) -> i32 = "int.left_shift";
  264. // CHECK:STDOUT:
  265. // CHECK:STDOUT: fn @Negate(%a: i32) -> i32 = "int.snegate";
  266. // CHECK:STDOUT:
  267. // CHECK:STDOUT: fn @__global_init() {
  268. // CHECK:STDOUT: !entry:
  269. // CHECK:STDOUT: %LeftShift.ref.loc8: %LeftShift.type = name_ref LeftShift, file.%LeftShift.decl [template = constants.%LeftShift]
  270. // CHECK:STDOUT: %.loc8_29: i32 = int_literal 1 [template = constants.%.2]
  271. // CHECK:STDOUT: %.loc8_32: i32 = int_literal 31 [template = constants.%.3]
  272. // CHECK:STDOUT: %int.left_shift.loc8: init i32 = call %LeftShift.ref.loc8(%.loc8_29, %.loc8_32) [template = constants.%.4]
  273. // CHECK:STDOUT: %.loc8_35.1: i32 = value_of_initializer %int.left_shift.loc8 [template = constants.%.4]
  274. // CHECK:STDOUT: %.loc8_35.2: i32 = converted %int.left_shift.loc8, %.loc8_35.1 [template = constants.%.4]
  275. // CHECK:STDOUT: %size_1: i32 = bind_name size_1, %.loc8_35.2
  276. // CHECK:STDOUT: %LeftShift.ref.loc13: %LeftShift.type = name_ref LeftShift, file.%LeftShift.decl [template = constants.%LeftShift]
  277. // CHECK:STDOUT: %.loc13_29: i32 = int_literal 1 [template = constants.%.2]
  278. // CHECK:STDOUT: %.loc13_32: i32 = int_literal 32 [template = constants.%.5]
  279. // CHECK:STDOUT: %int.left_shift.loc13: init i32 = call %LeftShift.ref.loc13(%.loc13_29, %.loc13_32) [template = <error>]
  280. // CHECK:STDOUT: %.loc13_35.1: i32 = value_of_initializer %int.left_shift.loc13 [template = <error>]
  281. // CHECK:STDOUT: %.loc13_35.2: i32 = converted %int.left_shift.loc13, %.loc13_35.1 [template = <error>]
  282. // CHECK:STDOUT: %size_2: i32 = bind_name size_2, %.loc13_35.2
  283. // CHECK:STDOUT: %LeftShift.ref.loc18: %LeftShift.type = name_ref LeftShift, file.%LeftShift.decl [template = constants.%LeftShift]
  284. // CHECK:STDOUT: %.loc18_29: i32 = int_literal 1 [template = constants.%.2]
  285. // CHECK:STDOUT: %.loc18_32: i32 = int_literal 33 [template = constants.%.6]
  286. // CHECK:STDOUT: %int.left_shift.loc18: init i32 = call %LeftShift.ref.loc18(%.loc18_29, %.loc18_32) [template = <error>]
  287. // CHECK:STDOUT: %.loc18_35.1: i32 = value_of_initializer %int.left_shift.loc18 [template = <error>]
  288. // CHECK:STDOUT: %.loc18_35.2: i32 = converted %int.left_shift.loc18, %.loc18_35.1 [template = <error>]
  289. // CHECK:STDOUT: %size_3: i32 = bind_name size_3, %.loc18_35.2
  290. // CHECK:STDOUT: %LeftShift.ref.loc21: %LeftShift.type = name_ref LeftShift, file.%LeftShift.decl [template = constants.%LeftShift]
  291. // CHECK:STDOUT: %.loc21_33: i32 = int_literal 1000 [template = constants.%.7]
  292. // CHECK:STDOUT: %.loc21_39: i32 = int_literal 31 [template = constants.%.3]
  293. // CHECK:STDOUT: %int.left_shift.loc21: init i32 = call %LeftShift.ref.loc21(%.loc21_33, %.loc21_39) [template = constants.%.8]
  294. // CHECK:STDOUT: %.loc21_42.1: i32 = value_of_initializer %int.left_shift.loc21 [template = constants.%.8]
  295. // CHECK:STDOUT: %.loc21_42.2: i32 = converted %int.left_shift.loc21, %.loc21_42.1 [template = constants.%.8]
  296. // CHECK:STDOUT: %overflow_1: i32 = bind_name overflow_1, %.loc21_42.2
  297. // CHECK:STDOUT: %LeftShift.ref.loc26: %LeftShift.type = name_ref LeftShift, file.%LeftShift.decl [template = constants.%LeftShift]
  298. // CHECK:STDOUT: %.loc26_33: i32 = int_literal 1000 [template = constants.%.7]
  299. // CHECK:STDOUT: %.loc26_39: i32 = int_literal 32 [template = constants.%.5]
  300. // CHECK:STDOUT: %int.left_shift.loc26: init i32 = call %LeftShift.ref.loc26(%.loc26_33, %.loc26_39) [template = <error>]
  301. // CHECK:STDOUT: %.loc26_42.1: i32 = value_of_initializer %int.left_shift.loc26 [template = <error>]
  302. // CHECK:STDOUT: %.loc26_42.2: i32 = converted %int.left_shift.loc26, %.loc26_42.1 [template = <error>]
  303. // CHECK:STDOUT: %overflow_2: i32 = bind_name overflow_2, %.loc26_42.2
  304. // CHECK:STDOUT: %LeftShift.ref.loc29: %LeftShift.type = name_ref LeftShift, file.%LeftShift.decl [template = constants.%LeftShift]
  305. // CHECK:STDOUT: %.loc29_36: i32 = int_literal 0 [template = constants.%.8]
  306. // CHECK:STDOUT: %.loc29_39: i32 = int_literal 31 [template = constants.%.3]
  307. // CHECK:STDOUT: %int.left_shift.loc29: init i32 = call %LeftShift.ref.loc29(%.loc29_36, %.loc29_39) [template = constants.%.8]
  308. // CHECK:STDOUT: %.loc29_42.1: i32 = value_of_initializer %int.left_shift.loc29 [template = constants.%.8]
  309. // CHECK:STDOUT: %.loc29_42.2: i32 = converted %int.left_shift.loc29, %.loc29_42.1 [template = constants.%.8]
  310. // CHECK:STDOUT: %no_overflow_1: i32 = bind_name no_overflow_1, %.loc29_42.2
  311. // CHECK:STDOUT: %LeftShift.ref.loc34: %LeftShift.type = name_ref LeftShift, file.%LeftShift.decl [template = constants.%LeftShift]
  312. // CHECK:STDOUT: %.loc34_36: i32 = int_literal 0 [template = constants.%.8]
  313. // CHECK:STDOUT: %.loc34_39: i32 = int_literal 32 [template = constants.%.5]
  314. // CHECK:STDOUT: %int.left_shift.loc34: init i32 = call %LeftShift.ref.loc34(%.loc34_36, %.loc34_39) [template = <error>]
  315. // CHECK:STDOUT: %.loc34_42.1: i32 = value_of_initializer %int.left_shift.loc34 [template = <error>]
  316. // CHECK:STDOUT: %.loc34_42.2: i32 = converted %int.left_shift.loc34, %.loc34_42.1 [template = <error>]
  317. // CHECK:STDOUT: %no_overflow_2: i32 = bind_name no_overflow_2, %.loc34_42.2
  318. // CHECK:STDOUT: %LeftShift.ref.loc40: %LeftShift.type = name_ref LeftShift, file.%LeftShift.decl [template = constants.%LeftShift]
  319. // CHECK:STDOUT: %.loc40_31: i32 = int_literal 1 [template = constants.%.2]
  320. // CHECK:STDOUT: %Negate.ref: %Negate.type = name_ref Negate, file.%Negate.decl [template = constants.%Negate]
  321. // CHECK:STDOUT: %.loc40_41: i32 = int_literal 1 [template = constants.%.2]
  322. // CHECK:STDOUT: %int.snegate: init i32 = call %Negate.ref(%.loc40_41) [template = constants.%.9]
  323. // CHECK:STDOUT: %.loc40_30.1: i32 = value_of_initializer %int.snegate [template = constants.%.9]
  324. // CHECK:STDOUT: %.loc40_30.2: i32 = converted %int.snegate, %.loc40_30.1 [template = constants.%.9]
  325. // CHECK:STDOUT: %int.left_shift.loc40: init i32 = call %LeftShift.ref.loc40(%.loc40_31, %.loc40_30.2) [template = <error>]
  326. // CHECK:STDOUT: %.loc40_44.1: i32 = value_of_initializer %int.left_shift.loc40 [template = <error>]
  327. // CHECK:STDOUT: %.loc40_44.2: i32 = converted %int.left_shift.loc40, %.loc40_44.1 [template = <error>]
  328. // CHECK:STDOUT: %negative: i32 = bind_name negative, %.loc40_44.2
  329. // CHECK:STDOUT: return
  330. // CHECK:STDOUT: }
  331. // CHECK:STDOUT: