complement.carbon 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // --- int_complement.carbon
  7. fn Complement(a: i32) -> i32 = "int.complement";
  8. fn And(a: i32, b: i32) -> i32 = "int.and";
  9. var arr: [i32; And(Complement(0x123456), 0xFFFFFF)];
  10. let arr_p: [i32; 0xEDCBA9]* = &arr;
  11. fn RuntimeCall(a: i32) -> i32 {
  12. return Complement(a);
  13. }
  14. // CHECK:STDOUT: --- int_complement.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %Complement: type = fn_type @Complement [template]
  18. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  19. // CHECK:STDOUT: %struct.1: Complement = struct_value () [template]
  20. // CHECK:STDOUT: %And: type = fn_type @And [template]
  21. // CHECK:STDOUT: %struct.2: And = struct_value () [template]
  22. // CHECK:STDOUT: %.2: i32 = int_literal 1193046 [template]
  23. // CHECK:STDOUT: %.3: i32 = int_literal -1193047 [template]
  24. // CHECK:STDOUT: %.4: i32 = int_literal 16777215 [template]
  25. // CHECK:STDOUT: %.5: i32 = int_literal 15584169 [template]
  26. // CHECK:STDOUT: %.6: type = array_type %.5, i32 [template]
  27. // CHECK:STDOUT: %.7: type = ptr_type [i32; 15584169] [template]
  28. // CHECK:STDOUT: %RuntimeCall: type = fn_type @RuntimeCall [template]
  29. // CHECK:STDOUT: %struct.3: RuntimeCall = struct_value () [template]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: file {
  33. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  34. // CHECK:STDOUT: .Core = %Core
  35. // CHECK:STDOUT: .Complement = %Complement.decl
  36. // CHECK:STDOUT: .And = %And.decl
  37. // CHECK:STDOUT: .arr = %arr
  38. // CHECK:STDOUT: .RuntimeCall = %RuntimeCall.decl
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  41. // CHECK:STDOUT: %Complement.decl: Complement = fn_decl @Complement [template = constants.%struct.1] {
  42. // CHECK:STDOUT: %a.loc2_15.1: i32 = param a
  43. // CHECK:STDOUT: @Complement.%a: i32 = bind_name a, %a.loc2_15.1
  44. // CHECK:STDOUT: @Complement.%return: ref i32 = var <return slot>
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %And.decl: And = fn_decl @And [template = constants.%struct.2] {
  47. // CHECK:STDOUT: %a.loc3_8.1: i32 = param a
  48. // CHECK:STDOUT: @And.%a: i32 = bind_name a, %a.loc3_8.1
  49. // CHECK:STDOUT: %b.loc3_16.1: i32 = param b
  50. // CHECK:STDOUT: @And.%b: i32 = bind_name b, %b.loc3_16.1
  51. // CHECK:STDOUT: @And.%return: ref i32 = var <return slot>
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %And.ref: And = name_ref And, %And.decl [template = constants.%struct.2]
  54. // CHECK:STDOUT: %Complement.ref: Complement = name_ref Complement, %Complement.decl [template = constants.%struct.1]
  55. // CHECK:STDOUT: %.loc5_31: i32 = int_literal 1193046 [template = constants.%.2]
  56. // CHECK:STDOUT: %int.complement: init i32 = call %Complement.ref(%.loc5_31) [template = constants.%.3]
  57. // CHECK:STDOUT: %.loc5_42: i32 = int_literal 16777215 [template = constants.%.4]
  58. // CHECK:STDOUT: %.loc5_19.1: i32 = value_of_initializer %int.complement [template = constants.%.3]
  59. // CHECK:STDOUT: %.loc5_19.2: i32 = converted %int.complement, %.loc5_19.1 [template = constants.%.3]
  60. // CHECK:STDOUT: %int.and: init i32 = call %And.ref(%.loc5_19.2, %.loc5_42) [template = constants.%.5]
  61. // CHECK:STDOUT: %.loc5_51: type = array_type %int.and, i32 [template = constants.%.6]
  62. // CHECK:STDOUT: %arr.var: ref [i32; 15584169] = var arr
  63. // CHECK:STDOUT: %arr: ref [i32; 15584169] = bind_name arr, %arr.var
  64. // CHECK:STDOUT: %.loc6_18: i32 = int_literal 15584169 [template = constants.%.5]
  65. // CHECK:STDOUT: %.loc6_26: type = array_type %.loc6_18, i32 [template = constants.%.6]
  66. // CHECK:STDOUT: %.loc6_27: type = ptr_type [i32; 15584169] [template = constants.%.7]
  67. // CHECK:STDOUT: %arr.ref: ref [i32; 15584169] = name_ref arr, %arr
  68. // CHECK:STDOUT: %.loc6_31: [i32; 15584169]* = addr_of %arr.ref
  69. // CHECK:STDOUT: %arr_p: [i32; 15584169]* = bind_name arr_p, %.loc6_31
  70. // CHECK:STDOUT: %RuntimeCall.decl: RuntimeCall = fn_decl @RuntimeCall [template = constants.%struct.3] {
  71. // CHECK:STDOUT: %a.loc8_16.1: i32 = param a
  72. // CHECK:STDOUT: @RuntimeCall.%a: i32 = bind_name a, %a.loc8_16.1
  73. // CHECK:STDOUT: @RuntimeCall.%return: ref i32 = var <return slot>
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @Complement(%a: i32) -> i32 = "int.complement";
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @And(%a: i32, %b: i32) -> i32 = "int.and";
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @RuntimeCall(%a: i32) -> i32 {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: %Complement.ref: Complement = name_ref Complement, file.%Complement.decl [template = constants.%struct.1]
  84. // CHECK:STDOUT: %a.ref: i32 = name_ref a, %a
  85. // CHECK:STDOUT: %int.complement: init i32 = call %Complement.ref(%a.ref)
  86. // CHECK:STDOUT: %.loc9_23.1: i32 = value_of_initializer %int.complement
  87. // CHECK:STDOUT: %.loc9_23.2: i32 = converted %int.complement, %.loc9_23.1
  88. // CHECK:STDOUT: return %.loc9_23.2
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: