break_continue.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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/while/break_continue.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/while/break_continue.carbon
  10. fn A() -> bool;
  11. fn B() -> bool;
  12. fn C() -> bool;
  13. fn D() -> bool;
  14. fn E() -> bool;
  15. fn F() -> bool;
  16. fn G() -> bool;
  17. fn H() -> bool;
  18. fn While() {
  19. while (A()) {
  20. if (B()) { continue; }
  21. if (C()) { break; }
  22. while (D()) {
  23. if (E()) { continue; }
  24. if (F()) { break; }
  25. }
  26. if (G()) { continue; }
  27. if (H()) { break; }
  28. }
  29. }
  30. // CHECK:STDOUT: --- break_continue.carbon
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: constants {
  33. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  34. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  35. // CHECK:STDOUT: %A.type: type = fn_type @A [template]
  36. // CHECK:STDOUT: %A: %A.type = struct_value () [template]
  37. // CHECK:STDOUT: %B.type: type = fn_type @B [template]
  38. // CHECK:STDOUT: %B: %B.type = struct_value () [template]
  39. // CHECK:STDOUT: %C.type: type = fn_type @C [template]
  40. // CHECK:STDOUT: %C: %C.type = struct_value () [template]
  41. // CHECK:STDOUT: %D.type: type = fn_type @D [template]
  42. // CHECK:STDOUT: %D: %D.type = struct_value () [template]
  43. // CHECK:STDOUT: %E.type: type = fn_type @E [template]
  44. // CHECK:STDOUT: %E: %E.type = struct_value () [template]
  45. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  46. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  47. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  48. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  49. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  50. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  51. // CHECK:STDOUT: %While.type: type = fn_type @While [template]
  52. // CHECK:STDOUT: %While: %While.type = struct_value () [template]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: imports {
  56. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  57. // CHECK:STDOUT: .Bool = %Core.Bool
  58. // CHECK:STDOUT: import Core//prelude
  59. // CHECK:STDOUT: import Core//prelude/...
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: file {
  64. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  65. // CHECK:STDOUT: .Core = imports.%Core
  66. // CHECK:STDOUT: .A = %A.decl
  67. // CHECK:STDOUT: .B = %B.decl
  68. // CHECK:STDOUT: .C = %C.decl
  69. // CHECK:STDOUT: .D = %D.decl
  70. // CHECK:STDOUT: .E = %E.decl
  71. // CHECK:STDOUT: .F = %F.decl
  72. // CHECK:STDOUT: .G = %G.decl
  73. // CHECK:STDOUT: .H = %H.decl
  74. // CHECK:STDOUT: .While = %While.decl
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %Core.import = import Core
  77. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [template = constants.%A] {
  78. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  79. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param0
  80. // CHECK:STDOUT: } {
  81. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  82. // CHECK:STDOUT: %.loc11_11.1: type = value_of_initializer %bool.make_type [template = bool]
  83. // CHECK:STDOUT: %.loc11_11.2: type = converted %bool.make_type, %.loc11_11.1 [template = bool]
  84. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param0
  85. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [template = constants.%B] {
  88. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  89. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param0
  90. // CHECK:STDOUT: } {
  91. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  92. // CHECK:STDOUT: %.loc12_11.1: type = value_of_initializer %bool.make_type [template = bool]
  93. // CHECK:STDOUT: %.loc12_11.2: type = converted %bool.make_type, %.loc12_11.1 [template = bool]
  94. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param0
  95. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {
  98. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  99. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param0
  100. // CHECK:STDOUT: } {
  101. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  102. // CHECK:STDOUT: %.loc13_11.1: type = value_of_initializer %bool.make_type [template = bool]
  103. // CHECK:STDOUT: %.loc13_11.2: type = converted %bool.make_type, %.loc13_11.1 [template = bool]
  104. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param0
  105. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: %D.decl: %D.type = fn_decl @D [template = constants.%D] {
  108. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  109. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param0
  110. // CHECK:STDOUT: } {
  111. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  112. // CHECK:STDOUT: %.loc14_11.1: type = value_of_initializer %bool.make_type [template = bool]
  113. // CHECK:STDOUT: %.loc14_11.2: type = converted %bool.make_type, %.loc14_11.1 [template = bool]
  114. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param0
  115. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: %E.decl: %E.type = fn_decl @E [template = constants.%E] {
  118. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  119. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param0
  120. // CHECK:STDOUT: } {
  121. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  122. // CHECK:STDOUT: %.loc15_11.1: type = value_of_initializer %bool.make_type [template = bool]
  123. // CHECK:STDOUT: %.loc15_11.2: type = converted %bool.make_type, %.loc15_11.1 [template = bool]
  124. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param0
  125. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  128. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  129. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param0
  130. // CHECK:STDOUT: } {
  131. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  132. // CHECK:STDOUT: %.loc16_11.1: type = value_of_initializer %bool.make_type [template = bool]
  133. // CHECK:STDOUT: %.loc16_11.2: type = converted %bool.make_type, %.loc16_11.1 [template = bool]
  134. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param0
  135. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  138. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  139. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param0
  140. // CHECK:STDOUT: } {
  141. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  142. // CHECK:STDOUT: %.loc17_11.1: type = value_of_initializer %bool.make_type [template = bool]
  143. // CHECK:STDOUT: %.loc17_11.2: type = converted %bool.make_type, %.loc17_11.1 [template = bool]
  144. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param0
  145. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {
  148. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  149. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param0
  150. // CHECK:STDOUT: } {
  151. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  152. // CHECK:STDOUT: %.loc18_11.1: type = value_of_initializer %bool.make_type [template = bool]
  153. // CHECK:STDOUT: %.loc18_11.2: type = converted %bool.make_type, %.loc18_11.1 [template = bool]
  154. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param0
  155. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT: %While.decl: %While.type = fn_decl @While [template = constants.%While] {} {}
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: fn @A() -> bool;
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: fn @B() -> bool;
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: fn @C() -> bool;
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: fn @D() -> bool;
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: fn @E() -> bool;
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: fn @F() -> bool;
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: fn @G() -> bool;
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: fn @H() -> bool;
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: fn @While() {
  177. // CHECK:STDOUT: !entry:
  178. // CHECK:STDOUT: br !while.cond.loc21
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: !while.cond.loc21:
  181. // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A]
  182. // CHECK:STDOUT: %A.call: init bool = call %A.ref()
  183. // CHECK:STDOUT: %.loc21_13.1: bool = value_of_initializer %A.call
  184. // CHECK:STDOUT: %.loc21_13.2: bool = converted %A.call, %.loc21_13.1
  185. // CHECK:STDOUT: if %.loc21_13.2 br !while.body.loc21 else br !while.done.loc21
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: !while.body.loc21:
  188. // CHECK:STDOUT: %B.ref: %B.type = name_ref B, file.%B.decl [template = constants.%B]
  189. // CHECK:STDOUT: %B.call: init bool = call %B.ref()
  190. // CHECK:STDOUT: %.loc22_12.1: bool = value_of_initializer %B.call
  191. // CHECK:STDOUT: %.loc22_12.2: bool = converted %B.call, %.loc22_12.1
  192. // CHECK:STDOUT: if %.loc22_12.2 br !if.then.loc22 else br !if.else.loc22
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: !if.then.loc22:
  195. // CHECK:STDOUT: br !while.cond.loc21
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: !if.else.loc22:
  198. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, file.%C.decl [template = constants.%C]
  199. // CHECK:STDOUT: %C.call: init bool = call %C.ref()
  200. // CHECK:STDOUT: %.loc23_12.1: bool = value_of_initializer %C.call
  201. // CHECK:STDOUT: %.loc23_12.2: bool = converted %C.call, %.loc23_12.1
  202. // CHECK:STDOUT: if %.loc23_12.2 br !if.then.loc23 else br !if.else.loc23
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: !if.then.loc23:
  205. // CHECK:STDOUT: br !while.done.loc21
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: !if.else.loc23:
  208. // CHECK:STDOUT: br !while.cond.loc24
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: !while.cond.loc24:
  211. // CHECK:STDOUT: %D.ref: %D.type = name_ref D, file.%D.decl [template = constants.%D]
  212. // CHECK:STDOUT: %D.call: init bool = call %D.ref()
  213. // CHECK:STDOUT: %.loc24_15.1: bool = value_of_initializer %D.call
  214. // CHECK:STDOUT: %.loc24_15.2: bool = converted %D.call, %.loc24_15.1
  215. // CHECK:STDOUT: if %.loc24_15.2 br !while.body.loc24 else br !while.done.loc24
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: !while.body.loc24:
  218. // CHECK:STDOUT: %E.ref: %E.type = name_ref E, file.%E.decl [template = constants.%E]
  219. // CHECK:STDOUT: %E.call: init bool = call %E.ref()
  220. // CHECK:STDOUT: %.loc25_14.1: bool = value_of_initializer %E.call
  221. // CHECK:STDOUT: %.loc25_14.2: bool = converted %E.call, %.loc25_14.1
  222. // CHECK:STDOUT: if %.loc25_14.2 br !if.then.loc25 else br !if.else.loc25
  223. // CHECK:STDOUT:
  224. // CHECK:STDOUT: !if.then.loc25:
  225. // CHECK:STDOUT: br !while.cond.loc24
  226. // CHECK:STDOUT:
  227. // CHECK:STDOUT: !if.else.loc25:
  228. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  229. // CHECK:STDOUT: %F.call: init bool = call %F.ref()
  230. // CHECK:STDOUT: %.loc26_14.1: bool = value_of_initializer %F.call
  231. // CHECK:STDOUT: %.loc26_14.2: bool = converted %F.call, %.loc26_14.1
  232. // CHECK:STDOUT: if %.loc26_14.2 br !if.then.loc26 else br !if.else.loc26
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: !if.then.loc26:
  235. // CHECK:STDOUT: br !while.done.loc24
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: !if.else.loc26:
  238. // CHECK:STDOUT: br !while.cond.loc24
  239. // CHECK:STDOUT:
  240. // CHECK:STDOUT: !while.done.loc24:
  241. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [template = constants.%G]
  242. // CHECK:STDOUT: %G.call: init bool = call %G.ref()
  243. // CHECK:STDOUT: %.loc28_12.1: bool = value_of_initializer %G.call
  244. // CHECK:STDOUT: %.loc28_12.2: bool = converted %G.call, %.loc28_12.1
  245. // CHECK:STDOUT: if %.loc28_12.2 br !if.then.loc28 else br !if.else.loc28
  246. // CHECK:STDOUT:
  247. // CHECK:STDOUT: !if.then.loc28:
  248. // CHECK:STDOUT: br !while.cond.loc21
  249. // CHECK:STDOUT:
  250. // CHECK:STDOUT: !if.else.loc28:
  251. // CHECK:STDOUT: %H.ref: %H.type = name_ref H, file.%H.decl [template = constants.%H]
  252. // CHECK:STDOUT: %H.call: init bool = call %H.ref()
  253. // CHECK:STDOUT: %.loc29_12.1: bool = value_of_initializer %H.call
  254. // CHECK:STDOUT: %.loc29_12.2: bool = converted %H.call, %.loc29_12.1
  255. // CHECK:STDOUT: if %.loc29_12.2 br !if.then.loc29 else br !if.else.loc29
  256. // CHECK:STDOUT:
  257. // CHECK:STDOUT: !if.then.loc29:
  258. // CHECK:STDOUT: br !while.done.loc21
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: !if.else.loc29:
  261. // CHECK:STDOUT: br !while.cond.loc21
  262. // CHECK:STDOUT:
  263. // CHECK:STDOUT: !while.done.loc21:
  264. // CHECK:STDOUT: return
  265. // CHECK:STDOUT: }
  266. // CHECK:STDOUT: