break_continue.carbon 14 KB

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