or.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. fn F() -> bool { return true; }
  7. fn G() -> bool { return true; }
  8. fn Or() -> bool {
  9. return F() or G();
  10. }
  11. fn Constant() {
  12. var a: if true or true then bool else () = true;
  13. var b: if true or false then bool else () = true;
  14. var c: if false or true then bool else () = true;
  15. var d: if false or false then bool else () = ();
  16. }
  17. fn PartialConstant(x: bool) {
  18. var a: if true or x then bool else () = true;
  19. }
  20. // CHECK:STDOUT: --- or.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %F: type = fn_type @F [template]
  24. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  25. // CHECK:STDOUT: %struct.1: F = struct_value () [template]
  26. // CHECK:STDOUT: %.2: bool = bool_literal true [template]
  27. // CHECK:STDOUT: %G: type = fn_type @G [template]
  28. // CHECK:STDOUT: %struct.2: G = struct_value () [template]
  29. // CHECK:STDOUT: %Or: type = fn_type @Or [template]
  30. // CHECK:STDOUT: %struct.3: Or = struct_value () [template]
  31. // CHECK:STDOUT: %Constant: type = fn_type @Constant [template]
  32. // CHECK:STDOUT: %struct.4: Constant = struct_value () [template]
  33. // CHECK:STDOUT: %.3: bool = bool_literal false [template]
  34. // CHECK:STDOUT: %tuple: () = tuple_value () [template]
  35. // CHECK:STDOUT: %PartialConstant: type = fn_type @PartialConstant [template]
  36. // CHECK:STDOUT: %struct.5: PartialConstant = struct_value () [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: file {
  40. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  41. // CHECK:STDOUT: .Core = %Core
  42. // CHECK:STDOUT: .F = %F.decl
  43. // CHECK:STDOUT: .G = %G.decl
  44. // CHECK:STDOUT: .Or = %Or.decl
  45. // CHECK:STDOUT: .Constant = %Constant.decl
  46. // CHECK:STDOUT: .PartialConstant = %PartialConstant.decl
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  49. // CHECK:STDOUT: %F.decl: F = fn_decl @F [template = constants.%struct.1] {
  50. // CHECK:STDOUT: @F.%return: ref bool = var <return slot>
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %G.decl: G = fn_decl @G [template = constants.%struct.2] {
  53. // CHECK:STDOUT: @G.%return: ref bool = var <return slot>
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %Or.decl: Or = fn_decl @Or [template = constants.%struct.3] {
  56. // CHECK:STDOUT: @Or.%return: ref bool = var <return slot>
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Constant.decl: Constant = fn_decl @Constant [template = constants.%struct.4] {}
  59. // CHECK:STDOUT: %PartialConstant.decl: PartialConstant = fn_decl @PartialConstant [template = constants.%struct.5] {
  60. // CHECK:STDOUT: %x.loc21_20.1: bool = param x
  61. // CHECK:STDOUT: @PartialConstant.%x: bool = bind_name x, %x.loc21_20.1
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: fn @F() -> bool {
  66. // CHECK:STDOUT: !entry:
  67. // CHECK:STDOUT: %.loc7: bool = bool_literal true [template = constants.%.2]
  68. // CHECK:STDOUT: return %.loc7
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @G() -> bool {
  72. // CHECK:STDOUT: !entry:
  73. // CHECK:STDOUT: %.loc8: bool = bool_literal true [template = constants.%.2]
  74. // CHECK:STDOUT: return %.loc8
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @Or() -> bool {
  78. // CHECK:STDOUT: !entry:
  79. // CHECK:STDOUT: %F.ref: F = name_ref F, file.%F.decl [template = constants.%struct.1]
  80. // CHECK:STDOUT: %F.call: init bool = call %F.ref()
  81. // CHECK:STDOUT: %.loc11_14.1: bool = value_of_initializer %F.call
  82. // CHECK:STDOUT: %.loc11_14.2: bool = converted %F.call, %.loc11_14.1
  83. // CHECK:STDOUT: %.loc11_14.3: bool = not %.loc11_14.2
  84. // CHECK:STDOUT: %.loc11_14.4: bool = bool_literal true [template = constants.%.2]
  85. // CHECK:STDOUT: if %.loc11_14.3 br !or.rhs else br !or.result(%.loc11_14.4)
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !or.rhs:
  88. // CHECK:STDOUT: %G.ref: G = name_ref G, file.%G.decl [template = constants.%struct.2]
  89. // CHECK:STDOUT: %G.call: init bool = call %G.ref()
  90. // CHECK:STDOUT: %.loc11_14.5: bool = value_of_initializer %G.call
  91. // CHECK:STDOUT: %.loc11_14.6: bool = converted %G.call, %.loc11_14.5
  92. // CHECK:STDOUT: br !or.result(%.loc11_14.6)
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: !or.result:
  95. // CHECK:STDOUT: %.loc11_14.7: bool = block_arg !or.result
  96. // CHECK:STDOUT: return %.loc11_14.7
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: fn @Constant() {
  100. // CHECK:STDOUT: !entry:
  101. // CHECK:STDOUT: %.loc15_13: bool = bool_literal true [template = constants.%.2]
  102. // CHECK:STDOUT: %.loc15_18.1: bool = not %.loc15_13 [template = constants.%.3]
  103. // CHECK:STDOUT: %.loc15_18.2: bool = bool_literal true [template = constants.%.2]
  104. // CHECK:STDOUT: if %.loc15_18.1 br !or.rhs.loc15 else br !or.result.loc15(%.loc15_18.2)
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: !or.rhs.loc15:
  107. // CHECK:STDOUT: %.loc15_21: bool = bool_literal true [template = constants.%.2]
  108. // CHECK:STDOUT: br !or.result.loc15(%.loc15_21)
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: !or.result.loc15:
  111. // CHECK:STDOUT: %.loc15_18.3: bool = block_arg !or.result.loc15 [template = constants.%.2]
  112. // CHECK:STDOUT: if %.loc15_18.3 br !if.expr.then.loc15 else br !if.expr.else.loc15
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: !if.expr.then.loc15:
  115. // CHECK:STDOUT: br !if.expr.result.loc15(bool)
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: !if.expr.else.loc15:
  118. // CHECK:STDOUT: %.loc15_42: () = tuple_literal ()
  119. // CHECK:STDOUT: %.loc15_36: type = converted %.loc15_42, constants.%.1 [template = constants.%.1]
  120. // CHECK:STDOUT: br !if.expr.result.loc15(%.loc15_36)
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: !if.expr.result.loc15:
  123. // CHECK:STDOUT: %.loc15_10: type = block_arg !if.expr.result.loc15 [template = bool]
  124. // CHECK:STDOUT: %a.var: ref bool = var a
  125. // CHECK:STDOUT: %a: ref bool = bind_name a, %a.var
  126. // CHECK:STDOUT: %.loc15_46: bool = bool_literal true [template = constants.%.2]
  127. // CHECK:STDOUT: assign %a.var, %.loc15_46
  128. // CHECK:STDOUT: %.loc16_13: bool = bool_literal true [template = constants.%.2]
  129. // CHECK:STDOUT: %.loc16_18.1: bool = not %.loc16_13 [template = constants.%.3]
  130. // CHECK:STDOUT: %.loc16_18.2: bool = bool_literal true [template = constants.%.2]
  131. // CHECK:STDOUT: if %.loc16_18.1 br !or.rhs.loc16 else br !or.result.loc16(%.loc16_18.2)
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: !or.rhs.loc16:
  134. // CHECK:STDOUT: %.loc16_21: bool = bool_literal false [template = constants.%.3]
  135. // CHECK:STDOUT: br !or.result.loc16(%.loc16_21)
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: !or.result.loc16:
  138. // CHECK:STDOUT: %.loc16_18.3: bool = block_arg !or.result.loc16 [template = constants.%.2]
  139. // CHECK:STDOUT: if %.loc16_18.3 br !if.expr.then.loc16 else br !if.expr.else.loc16
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: !if.expr.then.loc16:
  142. // CHECK:STDOUT: br !if.expr.result.loc16(bool)
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: !if.expr.else.loc16:
  145. // CHECK:STDOUT: %.loc16_43: () = tuple_literal ()
  146. // CHECK:STDOUT: %.loc16_37: type = converted %.loc16_43, constants.%.1 [template = constants.%.1]
  147. // CHECK:STDOUT: br !if.expr.result.loc16(%.loc16_37)
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: !if.expr.result.loc16:
  150. // CHECK:STDOUT: %.loc16_10: type = block_arg !if.expr.result.loc16 [template = bool]
  151. // CHECK:STDOUT: %b.var: ref bool = var b
  152. // CHECK:STDOUT: %b: ref bool = bind_name b, %b.var
  153. // CHECK:STDOUT: %.loc16_47: bool = bool_literal true [template = constants.%.2]
  154. // CHECK:STDOUT: assign %b.var, %.loc16_47
  155. // CHECK:STDOUT: %.loc17_13: bool = bool_literal false [template = constants.%.3]
  156. // CHECK:STDOUT: %.loc17_19.1: bool = not %.loc17_13 [template = constants.%.2]
  157. // CHECK:STDOUT: %.loc17_19.2: bool = bool_literal true [template = constants.%.2]
  158. // CHECK:STDOUT: if %.loc17_19.1 br !or.rhs.loc17 else br !or.result.loc17(%.loc17_19.2)
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: !or.rhs.loc17:
  161. // CHECK:STDOUT: %.loc17_22: bool = bool_literal true [template = constants.%.2]
  162. // CHECK:STDOUT: br !or.result.loc17(%.loc17_22)
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: !or.result.loc17:
  165. // CHECK:STDOUT: %.loc17_19.3: bool = block_arg !or.result.loc17 [template = constants.%.2]
  166. // CHECK:STDOUT: if %.loc17_19.3 br !if.expr.then.loc17 else br !if.expr.else.loc17
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: !if.expr.then.loc17:
  169. // CHECK:STDOUT: br !if.expr.result.loc17(bool)
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: !if.expr.else.loc17:
  172. // CHECK:STDOUT: %.loc17_43: () = tuple_literal ()
  173. // CHECK:STDOUT: %.loc17_37: type = converted %.loc17_43, constants.%.1 [template = constants.%.1]
  174. // CHECK:STDOUT: br !if.expr.result.loc17(%.loc17_37)
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: !if.expr.result.loc17:
  177. // CHECK:STDOUT: %.loc17_10: type = block_arg !if.expr.result.loc17 [template = bool]
  178. // CHECK:STDOUT: %c.var: ref bool = var c
  179. // CHECK:STDOUT: %c: ref bool = bind_name c, %c.var
  180. // CHECK:STDOUT: %.loc17_47: bool = bool_literal true [template = constants.%.2]
  181. // CHECK:STDOUT: assign %c.var, %.loc17_47
  182. // CHECK:STDOUT: %.loc18_13: bool = bool_literal false [template = constants.%.3]
  183. // CHECK:STDOUT: %.loc18_19.1: bool = not %.loc18_13 [template = constants.%.2]
  184. // CHECK:STDOUT: %.loc18_19.2: bool = bool_literal true [template = constants.%.2]
  185. // CHECK:STDOUT: if %.loc18_19.1 br !or.rhs.loc18 else br !or.result.loc18(%.loc18_19.2)
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: !or.rhs.loc18:
  188. // CHECK:STDOUT: %.loc18_22: bool = bool_literal false [template = constants.%.3]
  189. // CHECK:STDOUT: br !or.result.loc18(%.loc18_22)
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: !or.result.loc18:
  192. // CHECK:STDOUT: %.loc18_19.3: bool = block_arg !or.result.loc18 [template = constants.%.3]
  193. // CHECK:STDOUT: if %.loc18_19.3 br !if.expr.then.loc18 else br !if.expr.else.loc18
  194. // CHECK:STDOUT:
  195. // CHECK:STDOUT: !if.expr.then.loc18:
  196. // CHECK:STDOUT: br !if.expr.result.loc18(bool)
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: !if.expr.else.loc18:
  199. // CHECK:STDOUT: %.loc18_44: () = tuple_literal ()
  200. // CHECK:STDOUT: %.loc18_38: type = converted %.loc18_44, constants.%.1 [template = constants.%.1]
  201. // CHECK:STDOUT: br !if.expr.result.loc18(%.loc18_38)
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: !if.expr.result.loc18:
  204. // CHECK:STDOUT: %.loc18_10: type = block_arg !if.expr.result.loc18 [template = constants.%.1]
  205. // CHECK:STDOUT: %d.var: ref () = var d
  206. // CHECK:STDOUT: %d: ref () = bind_name d, %d.var
  207. // CHECK:STDOUT: %.loc18_49.1: () = tuple_literal ()
  208. // CHECK:STDOUT: %.loc18_49.2: init () = tuple_init () to %d.var [template = constants.%tuple]
  209. // CHECK:STDOUT: %.loc18_50: init () = converted %.loc18_49.1, %.loc18_49.2 [template = constants.%tuple]
  210. // CHECK:STDOUT: assign %d.var, %.loc18_50
  211. // CHECK:STDOUT: return
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: fn @PartialConstant(%x: bool) {
  215. // CHECK:STDOUT: !entry:
  216. // CHECK:STDOUT: %.loc22_13: bool = bool_literal true [template = constants.%.2]
  217. // CHECK:STDOUT: %.loc22_18.1: bool = not %.loc22_13 [template = constants.%.3]
  218. // CHECK:STDOUT: %.loc22_18.2: bool = bool_literal true [template = constants.%.2]
  219. // CHECK:STDOUT: if %.loc22_18.1 br !or.rhs else br !or.result(%.loc22_18.2)
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: !or.rhs:
  222. // CHECK:STDOUT: %x.ref: bool = name_ref x, %x
  223. // CHECK:STDOUT: br !or.result(%x.ref)
  224. // CHECK:STDOUT:
  225. // CHECK:STDOUT: !or.result:
  226. // CHECK:STDOUT: %.loc22_18.3: bool = block_arg !or.result [template = constants.%.2]
  227. // CHECK:STDOUT: if %.loc22_18.3 br !if.expr.then else br !if.expr.else
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: !if.expr.then:
  230. // CHECK:STDOUT: br !if.expr.result(bool)
  231. // CHECK:STDOUT:
  232. // CHECK:STDOUT: !if.expr.else:
  233. // CHECK:STDOUT: %.loc22_39: () = tuple_literal ()
  234. // CHECK:STDOUT: %.loc22_33: type = converted %.loc22_39, constants.%.1 [template = constants.%.1]
  235. // CHECK:STDOUT: br !if.expr.result(%.loc22_33)
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: !if.expr.result:
  238. // CHECK:STDOUT: %.loc22_10: type = block_arg !if.expr.result [template = bool]
  239. // CHECK:STDOUT: %a.var: ref bool = var a
  240. // CHECK:STDOUT: %a: ref bool = bind_name a, %a.var
  241. // CHECK:STDOUT: %.loc22_43: bool = bool_literal true [template = constants.%.2]
  242. // CHECK:STDOUT: assign %a.var, %.loc22_43
  243. // CHECK:STDOUT: return
  244. // CHECK:STDOUT: }
  245. // CHECK:STDOUT: