reference.carbon 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/interop/cpp/reference.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/reference.carbon
  12. // ============================================================================
  13. // Reference params
  14. // ============================================================================
  15. // --- pass_references.carbon
  16. library "[[@TEST_NAME]]";
  17. import Cpp inline '''
  18. class C {};
  19. auto TakeCRef(C&) -> void;
  20. auto TakeCRRef(C&&) -> void;
  21. auto TakeConstCRef(const C&) -> void;
  22. auto TakeIntRef(int&) -> void;
  23. auto TakeIntRRef(int&&) -> void;
  24. auto TakeConstIntRef(const int&) -> void;
  25. ''';
  26. fn PassRefs() {
  27. var c: Cpp.C;
  28. Cpp.TakeCRef(ref c);
  29. Cpp.TakeCRRef({} as Cpp.C);
  30. Cpp.TakeConstCRef(c);
  31. var n: i32;
  32. Cpp.TakeIntRef(ref n);
  33. Cpp.TakeIntRRef(42 as i32);
  34. Cpp.TakeConstIntRef(n);
  35. }
  36. // --- pass_references_via_thunk.carbon
  37. library "[[@TEST_NAME]]";
  38. import Cpp inline '''
  39. class C {};
  40. class ForceThunk {};
  41. auto TakeCRef(C&, ForceThunk = {}) -> void;
  42. auto TakeCRRef(const C&, ForceThunk = {}) -> void;
  43. auto TakeConstCRef(const C&, ForceThunk = {}) -> void;
  44. auto TakeIntRef(int&, ForceThunk = {}) -> void;
  45. auto TakeIntRRef(int&&, ForceThunk = {}) -> void;
  46. auto TakeConstIntRef(const int&, ForceThunk = {}) -> void;
  47. ''';
  48. fn PassRefs() {
  49. var c: Cpp.C;
  50. Cpp.TakeCRef(ref c);
  51. Cpp.TakeCRRef({} as Cpp.C);
  52. Cpp.TakeConstCRef(c);
  53. var n: i32;
  54. Cpp.TakeIntRef(ref n);
  55. Cpp.TakeIntRRef(42 as i32);
  56. Cpp.TakeConstIntRef(n);
  57. }
  58. // ============================================================================
  59. // Reference return values
  60. // ============================================================================
  61. // --- return_references.carbon
  62. library "[[@TEST_NAME]]";
  63. import Cpp inline '''
  64. class C {};
  65. auto ReturnCRef() -> C&;
  66. auto ReturnCRRef() -> C&&;
  67. auto ReturnConstCRef() -> const C&;
  68. auto ReturnIntRef() -> int&;
  69. auto ReturnIntRRef() -> int&&;
  70. auto ReturnConstIntRef() -> const int&;
  71. ''';
  72. fn GetRefs() {
  73. let ref _: Cpp.C = Cpp.ReturnCRef();
  74. let ref _: Cpp.C = Cpp.ReturnCRRef();
  75. let ref _: const Cpp.C = Cpp.ReturnConstCRef();
  76. let ref _: i32 = Cpp.ReturnIntRef();
  77. let ref _: i32 = Cpp.ReturnIntRRef();
  78. let ref _: const i32 = Cpp.ReturnConstIntRef();
  79. }
  80. // --- return_references_via_thunk.carbon
  81. library "[[@TEST_NAME]]";
  82. import Cpp inline '''
  83. class C {};
  84. class ForceThunk {};
  85. auto ReturnCRef(ForceThunk = {}) -> C&;
  86. auto ReturnCRRef(ForceThunk = {}) -> C&&;
  87. auto ReturnConstCRef(ForceThunk = {}) -> const C&;
  88. auto ReturnIntRef(ForceThunk = {}) -> int&;
  89. auto ReturnIntRRef(ForceThunk = {}) -> int&&;
  90. auto ReturnConstIntRef(ForceThunk = {}) -> const int&;
  91. ''';
  92. fn GetRefs() {
  93. let ref _: Cpp.C = Cpp.ReturnCRef();
  94. let ref _: Cpp.C = Cpp.ReturnCRRef();
  95. let ref _: const Cpp.C = Cpp.ReturnConstCRef();
  96. let ref _: i32 = Cpp.ReturnIntRef();
  97. let ref _: i32 = Cpp.ReturnIntRRef();
  98. let ref _: const i32 = Cpp.ReturnConstIntRef();
  99. }
  100. // CHECK:STDOUT: ; ModuleID = 'pass_references.carbon'
  101. // CHECK:STDOUT: source_filename = "pass_references.carbon"
  102. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  103. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: @C.val = internal constant {} zeroinitializer
  106. // CHECK:STDOUT: @int_42.c68 = internal constant i32 42
  107. // CHECK:STDOUT: @C.val.loc19_20.3 = internal constant {} zeroinitializer
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress nounwind uwtable
  110. // CHECK:STDOUT: define dso_local void @_ZN1CC1Ev.carbon_thunk(ptr noundef %return) #0 {
  111. // CHECK:STDOUT: entry:
  112. // CHECK:STDOUT: %return.addr = alloca ptr, align 8
  113. // CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !11
  114. // CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !11
  115. // CHECK:STDOUT: ret void
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  119. // CHECK:STDOUT: define dso_local void @_Z9TakeCRRefO1C.carbon_thunk(ptr noundef %0) #1 {
  120. // CHECK:STDOUT: entry:
  121. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  122. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !11
  123. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !11
  124. // CHECK:STDOUT: call void @_Z9TakeCRRefO1C(ptr noundef nonnull align 1 dereferenceable(1) %1)
  125. // CHECK:STDOUT: ret void
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: declare void @_Z9TakeCRRefO1C(ptr noundef nonnull align 1 dereferenceable(1)) #2
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  131. // CHECK:STDOUT: define dso_local void @_Z13TakeConstCRefRK1C.carbon_thunk(ptr noundef %0) #1 {
  132. // CHECK:STDOUT: entry:
  133. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  134. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !11
  135. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !11
  136. // CHECK:STDOUT: call void @_Z13TakeConstCRefRK1C(ptr noundef nonnull align 1 dereferenceable(1) %1)
  137. // CHECK:STDOUT: ret void
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: declare void @_Z13TakeConstCRefRK1C(ptr noundef nonnull align 1 dereferenceable(1)) #2
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  143. // CHECK:STDOUT: define dso_local void @_Z11TakeIntRRefOi.carbon_thunk(ptr noundef %0) #1 {
  144. // CHECK:STDOUT: entry:
  145. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  146. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !14
  147. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !14
  148. // CHECK:STDOUT: call void @_Z11TakeIntRRefOi(ptr noundef nonnull align 4 dereferenceable(4) %1)
  149. // CHECK:STDOUT: ret void
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: declare void @_Z11TakeIntRRefOi(ptr noundef nonnull align 4 dereferenceable(4)) #2
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  155. // CHECK:STDOUT: define dso_local void @_Z15TakeConstIntRefRKi.carbon_thunk(ptr noundef %0) #1 {
  156. // CHECK:STDOUT: entry:
  157. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  158. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !14
  159. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !14
  160. // CHECK:STDOUT: call void @_Z15TakeConstIntRefRKi(ptr noundef nonnull align 4 dereferenceable(4) %1)
  161. // CHECK:STDOUT: ret void
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: declare void @_Z15TakeConstIntRefRKi(ptr noundef nonnull align 4 dereferenceable(4)) #2
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: ; Function Attrs: nounwind
  167. // CHECK:STDOUT: define void @_CPassRefs.Main() #3 !dbg !16 {
  168. // CHECK:STDOUT: entry:
  169. // CHECK:STDOUT: %c.var = alloca {}, align 8, !dbg !19
  170. // CHECK:STDOUT: %.loc19_18.2.temp = alloca {}, align 8, !dbg !20
  171. // CHECK:STDOUT: %n.var = alloca i32, align 4, !dbg !21
  172. // CHECK:STDOUT: %.loc24_22.3.temp = alloca i32, align 4, !dbg !22
  173. // CHECK:STDOUT: %.loc25_23.2.temp = alloca i32, align 4, !dbg !23
  174. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !19
  175. // CHECK:STDOUT: call void @"_COp.9b0a46309e124f8a:DefaultOrUnformed.Core.93349b0fe912a29b"(ptr %c.var), !dbg !19
  176. // CHECK:STDOUT: call void @_Z8TakeCRefR1C(ptr %c.var), !dbg !24
  177. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc19_18.2.temp), !dbg !20
  178. // CHECK:STDOUT: call void @_Z9TakeCRRefO1C.carbon_thunk(ptr @C.val.loc19_20.3), !dbg !25
  179. // CHECK:STDOUT: call void @_Z13TakeConstCRefRK1C.carbon_thunk(ptr %c.var), !dbg !26
  180. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %n.var), !dbg !21
  181. // CHECK:STDOUT: store i32 poison, ptr %n.var, align 4, !dbg !21
  182. // CHECK:STDOUT: call void @_Z10TakeIntRefRi(ptr %n.var), !dbg !27
  183. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc24_22.3.temp), !dbg !22
  184. // CHECK:STDOUT: call void @_Z11TakeIntRRefOi.carbon_thunk(ptr @int_42.c68), !dbg !28
  185. // CHECK:STDOUT: %.loc25_23.1 = load i32, ptr %n.var, align 4, !dbg !23
  186. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc25_23.2.temp), !dbg !23
  187. // CHECK:STDOUT: store i32 %.loc25_23.1, ptr %.loc25_23.2.temp, align 4, !dbg !23
  188. // CHECK:STDOUT: call void @_Z15TakeConstIntRefRKi.carbon_thunk(ptr %.loc25_23.2.temp), !dbg !29
  189. // CHECK:STDOUT: ret void, !dbg !30
  190. // CHECK:STDOUT: }
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: ; Function Attrs: alwaysinline nounwind
  193. // CHECK:STDOUT: define void @"_COp:thunk.C.Cpp"(ptr sret({}) %return) #4 !dbg !31 {
  194. // CHECK:STDOUT: entry:
  195. // CHECK:STDOUT: call void @_ZN1CC1Ev.carbon_thunk(ptr %return), !dbg !35
  196. // CHECK:STDOUT: ret void, !dbg !35
  197. // CHECK:STDOUT: }
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: declare void @_Z8TakeCRefR1C(ptr noundef nonnull align 1 dereferenceable(1)) #2
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: declare void @_Z10TakeIntRefRi(ptr noundef nonnull align 4 dereferenceable(4)) #2
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  204. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #5
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: ; Function Attrs: nounwind
  207. // CHECK:STDOUT: define linkonce_odr void @"_COp.9b0a46309e124f8a:DefaultOrUnformed.Core.93349b0fe912a29b"(ptr sret({}) %return) #3 !dbg !36 {
  208. // CHECK:STDOUT: call void @"_COp:thunk.C.Cpp"(ptr %return), !dbg !38
  209. // CHECK:STDOUT: ret void, !dbg !39
  210. // CHECK:STDOUT: }
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: ; uselistorder directives
  213. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 4, 3, 2, 1, 0 }
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: attributes #0 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  216. // CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  217. // CHECK:STDOUT: attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  218. // CHECK:STDOUT: attributes #3 = { nounwind }
  219. // CHECK:STDOUT: attributes #4 = { alwaysinline nounwind }
  220. // CHECK:STDOUT: attributes #5 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  223. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  224. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  227. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  228. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  229. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  230. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  231. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  232. // CHECK:STDOUT: !6 = !DIFile(filename: "pass_references.carbon", directory: "")
  233. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  234. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  235. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  236. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  237. // CHECK:STDOUT: !11 = !{!12, !12, i64 0}
  238. // CHECK:STDOUT: !12 = !{!"p1 _ZTS1C", !13, i64 0}
  239. // CHECK:STDOUT: !13 = !{!"any pointer", !9, i64 0}
  240. // CHECK:STDOUT: !14 = !{!15, !15, i64 0}
  241. // CHECK:STDOUT: !15 = !{!"p1 int", !13, i64 0}
  242. // CHECK:STDOUT: !16 = distinct !DISubprogram(name: "PassRefs", linkageName: "_CPassRefs.Main", scope: null, file: !6, line: 16, type: !17, spFlags: DISPFlagDefinition, unit: !5)
  243. // CHECK:STDOUT: !17 = !DISubroutineType(types: !18)
  244. // CHECK:STDOUT: !18 = !{null}
  245. // CHECK:STDOUT: !19 = !DILocation(line: 17, column: 3, scope: !16)
  246. // CHECK:STDOUT: !20 = !DILocation(line: 19, column: 17, scope: !16)
  247. // CHECK:STDOUT: !21 = !DILocation(line: 22, column: 3, scope: !16)
  248. // CHECK:STDOUT: !22 = !DILocation(line: 24, column: 19, scope: !16)
  249. // CHECK:STDOUT: !23 = !DILocation(line: 25, column: 23, scope: !16)
  250. // CHECK:STDOUT: !24 = !DILocation(line: 18, column: 3, scope: !16)
  251. // CHECK:STDOUT: !25 = !DILocation(line: 19, column: 3, scope: !16)
  252. // CHECK:STDOUT: !26 = !DILocation(line: 20, column: 3, scope: !16)
  253. // CHECK:STDOUT: !27 = !DILocation(line: 23, column: 3, scope: !16)
  254. // CHECK:STDOUT: !28 = !DILocation(line: 24, column: 3, scope: !16)
  255. // CHECK:STDOUT: !29 = !DILocation(line: 25, column: 3, scope: !16)
  256. // CHECK:STDOUT: !30 = !DILocation(line: 16, column: 1, scope: !16)
  257. // CHECK:STDOUT: !31 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.C.Cpp", scope: null, file: !6, line: 5, type: !32, spFlags: DISPFlagDefinition, unit: !5)
  258. // CHECK:STDOUT: !32 = !DISubroutineType(types: !33)
  259. // CHECK:STDOUT: !33 = !{!34}
  260. // CHECK:STDOUT: !34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  261. // CHECK:STDOUT: !35 = !DILocation(line: 5, column: 7, scope: !31)
  262. // CHECK:STDOUT: !36 = distinct !DISubprogram(name: "Op", linkageName: "_COp.9b0a46309e124f8a:DefaultOrUnformed.Core.93349b0fe912a29b", scope: null, file: !37, line: 9, type: !32, spFlags: DISPFlagDefinition, unit: !5)
  263. // CHECK:STDOUT: !37 = !DIFile(filename: "min_prelude/parts/default.carbon", directory: "")
  264. // CHECK:STDOUT: !38 = !DILocation(line: 9, column: 28, scope: !36)
  265. // CHECK:STDOUT: !39 = !DILocation(line: 9, column: 21, scope: !36)
  266. // CHECK:STDOUT: ; ModuleID = 'pass_references_via_thunk.carbon'
  267. // CHECK:STDOUT: source_filename = "pass_references_via_thunk.carbon"
  268. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  269. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  270. // CHECK:STDOUT:
  271. // CHECK:STDOUT: %class.ForceThunk = type { i8 }
  272. // CHECK:STDOUT:
  273. // CHECK:STDOUT: @C.val = internal constant {} zeroinitializer
  274. // CHECK:STDOUT: @int_42.c68 = internal constant i32 42
  275. // CHECK:STDOUT: @C.val.loc20_20.3 = internal constant {} zeroinitializer
  276. // CHECK:STDOUT:
  277. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress nounwind uwtable
  278. // CHECK:STDOUT: define dso_local void @_ZN1CC1Ev.carbon_thunk(ptr noundef %return) #0 {
  279. // CHECK:STDOUT: entry:
  280. // CHECK:STDOUT: %return.addr = alloca ptr, align 8
  281. // CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !11
  282. // CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !11
  283. // CHECK:STDOUT: ret void
  284. // CHECK:STDOUT: }
  285. // CHECK:STDOUT:
  286. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  287. // CHECK:STDOUT: define dso_local void @_Z8TakeCRefR1C10ForceThunk.carbon_thunk1(ptr noundef nonnull align 1 dereferenceable(1) %0) #1 {
  288. // CHECK:STDOUT: entry:
  289. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  290. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  291. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !11
  292. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !11, !nonnull !14
  293. // CHECK:STDOUT: call void @_Z8TakeCRefR1C10ForceThunk(ptr noundef nonnull align 1 dereferenceable(1) %1)
  294. // CHECK:STDOUT: ret void
  295. // CHECK:STDOUT: }
  296. // CHECK:STDOUT:
  297. // CHECK:STDOUT: declare void @_Z8TakeCRefR1C10ForceThunk(ptr noundef nonnull align 1 dereferenceable(1)) #2
  298. // CHECK:STDOUT:
  299. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  300. // CHECK:STDOUT: define dso_local void @_Z9TakeCRRefRK1C10ForceThunk.carbon_thunk1(ptr noundef %0) #1 {
  301. // CHECK:STDOUT: entry:
  302. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  303. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  304. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !11
  305. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !11
  306. // CHECK:STDOUT: call void @_Z9TakeCRRefRK1C10ForceThunk(ptr noundef nonnull align 1 dereferenceable(1) %1)
  307. // CHECK:STDOUT: ret void
  308. // CHECK:STDOUT: }
  309. // CHECK:STDOUT:
  310. // CHECK:STDOUT: declare void @_Z9TakeCRRefRK1C10ForceThunk(ptr noundef nonnull align 1 dereferenceable(1)) #2
  311. // CHECK:STDOUT:
  312. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  313. // CHECK:STDOUT: define dso_local void @_Z13TakeConstCRefRK1C10ForceThunk.carbon_thunk1(ptr noundef %0) #1 {
  314. // CHECK:STDOUT: entry:
  315. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  316. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  317. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !11
  318. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !11
  319. // CHECK:STDOUT: call void @_Z13TakeConstCRefRK1C10ForceThunk(ptr noundef nonnull align 1 dereferenceable(1) %1)
  320. // CHECK:STDOUT: ret void
  321. // CHECK:STDOUT: }
  322. // CHECK:STDOUT:
  323. // CHECK:STDOUT: declare void @_Z13TakeConstCRefRK1C10ForceThunk(ptr noundef nonnull align 1 dereferenceable(1)) #2
  324. // CHECK:STDOUT:
  325. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  326. // CHECK:STDOUT: define dso_local void @_Z10TakeIntRefRi10ForceThunk.carbon_thunk1(ptr noundef nonnull align 4 dereferenceable(4) %0) #1 {
  327. // CHECK:STDOUT: entry:
  328. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  329. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  330. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !15
  331. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !15, !nonnull !14, !align !17
  332. // CHECK:STDOUT: call void @_Z10TakeIntRefRi10ForceThunk(ptr noundef nonnull align 4 dereferenceable(4) %1)
  333. // CHECK:STDOUT: ret void
  334. // CHECK:STDOUT: }
  335. // CHECK:STDOUT:
  336. // CHECK:STDOUT: declare void @_Z10TakeIntRefRi10ForceThunk(ptr noundef nonnull align 4 dereferenceable(4)) #2
  337. // CHECK:STDOUT:
  338. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  339. // CHECK:STDOUT: define dso_local void @_Z11TakeIntRRefOi10ForceThunk.carbon_thunk1(ptr noundef %0) #1 {
  340. // CHECK:STDOUT: entry:
  341. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  342. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  343. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !15
  344. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !15
  345. // CHECK:STDOUT: call void @_Z11TakeIntRRefOi10ForceThunk(ptr noundef nonnull align 4 dereferenceable(4) %1)
  346. // CHECK:STDOUT: ret void
  347. // CHECK:STDOUT: }
  348. // CHECK:STDOUT:
  349. // CHECK:STDOUT: declare void @_Z11TakeIntRRefOi10ForceThunk(ptr noundef nonnull align 4 dereferenceable(4)) #2
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  352. // CHECK:STDOUT: define dso_local void @_Z15TakeConstIntRefRKi10ForceThunk.carbon_thunk1(ptr noundef %0) #1 {
  353. // CHECK:STDOUT: entry:
  354. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  355. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  356. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !15
  357. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !15
  358. // CHECK:STDOUT: call void @_Z15TakeConstIntRefRKi10ForceThunk(ptr noundef nonnull align 4 dereferenceable(4) %1)
  359. // CHECK:STDOUT: ret void
  360. // CHECK:STDOUT: }
  361. // CHECK:STDOUT:
  362. // CHECK:STDOUT: declare void @_Z15TakeConstIntRefRKi10ForceThunk(ptr noundef nonnull align 4 dereferenceable(4)) #2
  363. // CHECK:STDOUT:
  364. // CHECK:STDOUT: ; Function Attrs: nounwind
  365. // CHECK:STDOUT: define void @_CPassRefs.Main() #3 !dbg !18 {
  366. // CHECK:STDOUT: entry:
  367. // CHECK:STDOUT: %c.var = alloca {}, align 8, !dbg !21
  368. // CHECK:STDOUT: %.loc20_18.2.temp = alloca {}, align 8, !dbg !22
  369. // CHECK:STDOUT: %n.var = alloca i32, align 4, !dbg !23
  370. // CHECK:STDOUT: %.loc25_22.3.temp = alloca i32, align 4, !dbg !24
  371. // CHECK:STDOUT: %.loc26_23.2.temp = alloca i32, align 4, !dbg !25
  372. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !21
  373. // CHECK:STDOUT: call void @"_COp.9b0a46309e124f8a:DefaultOrUnformed.Core.93349b0fe912a29b"(ptr %c.var), !dbg !21
  374. // CHECK:STDOUT: call void @_Z8TakeCRefR1C10ForceThunk.carbon_thunk1(ptr %c.var), !dbg !26
  375. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc20_18.2.temp), !dbg !22
  376. // CHECK:STDOUT: call void @_Z9TakeCRRefRK1C10ForceThunk.carbon_thunk1(ptr @C.val.loc20_20.3), !dbg !27
  377. // CHECK:STDOUT: call void @_Z13TakeConstCRefRK1C10ForceThunk.carbon_thunk1(ptr %c.var), !dbg !28
  378. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %n.var), !dbg !23
  379. // CHECK:STDOUT: store i32 poison, ptr %n.var, align 4, !dbg !23
  380. // CHECK:STDOUT: call void @_Z10TakeIntRefRi10ForceThunk.carbon_thunk1(ptr %n.var), !dbg !29
  381. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc25_22.3.temp), !dbg !24
  382. // CHECK:STDOUT: call void @_Z11TakeIntRRefOi10ForceThunk.carbon_thunk1(ptr @int_42.c68), !dbg !30
  383. // CHECK:STDOUT: %.loc26_23.1 = load i32, ptr %n.var, align 4, !dbg !25
  384. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc26_23.2.temp), !dbg !25
  385. // CHECK:STDOUT: store i32 %.loc26_23.1, ptr %.loc26_23.2.temp, align 4, !dbg !25
  386. // CHECK:STDOUT: call void @_Z15TakeConstIntRefRKi10ForceThunk.carbon_thunk1(ptr %.loc26_23.2.temp), !dbg !31
  387. // CHECK:STDOUT: ret void, !dbg !32
  388. // CHECK:STDOUT: }
  389. // CHECK:STDOUT:
  390. // CHECK:STDOUT: ; Function Attrs: alwaysinline nounwind
  391. // CHECK:STDOUT: define void @"_COp:thunk.C.Cpp"(ptr sret({}) %return) #4 !dbg !33 {
  392. // CHECK:STDOUT: entry:
  393. // CHECK:STDOUT: call void @_ZN1CC1Ev.carbon_thunk(ptr %return), !dbg !37
  394. // CHECK:STDOUT: ret void, !dbg !37
  395. // CHECK:STDOUT: }
  396. // CHECK:STDOUT:
  397. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  398. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #5
  399. // CHECK:STDOUT:
  400. // CHECK:STDOUT: ; Function Attrs: nounwind
  401. // CHECK:STDOUT: define linkonce_odr void @"_COp.9b0a46309e124f8a:DefaultOrUnformed.Core.93349b0fe912a29b"(ptr sret({}) %return) #3 !dbg !38 {
  402. // CHECK:STDOUT: call void @"_COp:thunk.C.Cpp"(ptr %return), !dbg !40
  403. // CHECK:STDOUT: ret void, !dbg !41
  404. // CHECK:STDOUT: }
  405. // CHECK:STDOUT:
  406. // CHECK:STDOUT: ; uselistorder directives
  407. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 4, 3, 2, 1, 0 }
  408. // CHECK:STDOUT:
  409. // CHECK:STDOUT: attributes #0 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  410. // CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  411. // CHECK:STDOUT: attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  412. // CHECK:STDOUT: attributes #3 = { nounwind }
  413. // CHECK:STDOUT: attributes #4 = { alwaysinline nounwind }
  414. // CHECK:STDOUT: attributes #5 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  415. // CHECK:STDOUT:
  416. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  417. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  418. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  419. // CHECK:STDOUT:
  420. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  421. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  422. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  423. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  424. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  425. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  426. // CHECK:STDOUT: !6 = !DIFile(filename: "pass_references_via_thunk.carbon", directory: "")
  427. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  428. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  429. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  430. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  431. // CHECK:STDOUT: !11 = !{!12, !12, i64 0}
  432. // CHECK:STDOUT: !12 = !{!"p1 _ZTS1C", !13, i64 0}
  433. // CHECK:STDOUT: !13 = !{!"any pointer", !9, i64 0}
  434. // CHECK:STDOUT: !14 = !{}
  435. // CHECK:STDOUT: !15 = !{!16, !16, i64 0}
  436. // CHECK:STDOUT: !16 = !{!"p1 int", !13, i64 0}
  437. // CHECK:STDOUT: !17 = !{i64 4}
  438. // CHECK:STDOUT: !18 = distinct !DISubprogram(name: "PassRefs", linkageName: "_CPassRefs.Main", scope: null, file: !6, line: 17, type: !19, spFlags: DISPFlagDefinition, unit: !5)
  439. // CHECK:STDOUT: !19 = !DISubroutineType(types: !20)
  440. // CHECK:STDOUT: !20 = !{null}
  441. // CHECK:STDOUT: !21 = !DILocation(line: 18, column: 3, scope: !18)
  442. // CHECK:STDOUT: !22 = !DILocation(line: 20, column: 17, scope: !18)
  443. // CHECK:STDOUT: !23 = !DILocation(line: 23, column: 3, scope: !18)
  444. // CHECK:STDOUT: !24 = !DILocation(line: 25, column: 19, scope: !18)
  445. // CHECK:STDOUT: !25 = !DILocation(line: 26, column: 23, scope: !18)
  446. // CHECK:STDOUT: !26 = !DILocation(line: 19, column: 3, scope: !18)
  447. // CHECK:STDOUT: !27 = !DILocation(line: 20, column: 3, scope: !18)
  448. // CHECK:STDOUT: !28 = !DILocation(line: 21, column: 3, scope: !18)
  449. // CHECK:STDOUT: !29 = !DILocation(line: 24, column: 3, scope: !18)
  450. // CHECK:STDOUT: !30 = !DILocation(line: 25, column: 3, scope: !18)
  451. // CHECK:STDOUT: !31 = !DILocation(line: 26, column: 3, scope: !18)
  452. // CHECK:STDOUT: !32 = !DILocation(line: 17, column: 1, scope: !18)
  453. // CHECK:STDOUT: !33 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.C.Cpp", scope: null, file: !6, line: 5, type: !34, spFlags: DISPFlagDefinition, unit: !5)
  454. // CHECK:STDOUT: !34 = !DISubroutineType(types: !35)
  455. // CHECK:STDOUT: !35 = !{!36}
  456. // CHECK:STDOUT: !36 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  457. // CHECK:STDOUT: !37 = !DILocation(line: 5, column: 7, scope: !33)
  458. // CHECK:STDOUT: !38 = distinct !DISubprogram(name: "Op", linkageName: "_COp.9b0a46309e124f8a:DefaultOrUnformed.Core.93349b0fe912a29b", scope: null, file: !39, line: 9, type: !34, spFlags: DISPFlagDefinition, unit: !5)
  459. // CHECK:STDOUT: !39 = !DIFile(filename: "min_prelude/parts/default.carbon", directory: "")
  460. // CHECK:STDOUT: !40 = !DILocation(line: 9, column: 28, scope: !38)
  461. // CHECK:STDOUT: !41 = !DILocation(line: 9, column: 21, scope: !38)
  462. // CHECK:STDOUT: ; ModuleID = 'return_references.carbon'
  463. // CHECK:STDOUT: source_filename = "return_references.carbon"
  464. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  465. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  466. // CHECK:STDOUT:
  467. // CHECK:STDOUT: ; Function Attrs: nounwind
  468. // CHECK:STDOUT: define void @_CGetRefs.Main() #0 !dbg !11 {
  469. // CHECK:STDOUT: entry:
  470. // CHECK:STDOUT: %ReturnCRef.call = call ptr @_Z10ReturnCRefv(), !dbg !14
  471. // CHECK:STDOUT: %ReturnCRRef.call = call ptr @_Z11ReturnCRRefv(), !dbg !15
  472. // CHECK:STDOUT: %ReturnConstCRef.call = call ptr @_Z15ReturnConstCRefv(), !dbg !16
  473. // CHECK:STDOUT: %ReturnIntRef.call = call ptr @_Z12ReturnIntRefv(), !dbg !17
  474. // CHECK:STDOUT: %ReturnIntRRef.call = call ptr @_Z13ReturnIntRRefv(), !dbg !18
  475. // CHECK:STDOUT: %ReturnConstIntRef.call = call ptr @_Z17ReturnConstIntRefv(), !dbg !19
  476. // CHECK:STDOUT: ret void, !dbg !20
  477. // CHECK:STDOUT: }
  478. // CHECK:STDOUT:
  479. // CHECK:STDOUT: declare noundef nonnull align 1 dereferenceable(1) ptr @_Z10ReturnCRefv() #1
  480. // CHECK:STDOUT:
  481. // CHECK:STDOUT: declare noundef nonnull align 1 dereferenceable(1) ptr @_Z11ReturnCRRefv() #1
  482. // CHECK:STDOUT:
  483. // CHECK:STDOUT: declare noundef nonnull align 1 dereferenceable(1) ptr @_Z15ReturnConstCRefv() #1
  484. // CHECK:STDOUT:
  485. // CHECK:STDOUT: declare noundef nonnull align 4 dereferenceable(4) ptr @_Z12ReturnIntRefv() #1
  486. // CHECK:STDOUT:
  487. // CHECK:STDOUT: declare noundef nonnull align 4 dereferenceable(4) ptr @_Z13ReturnIntRRefv() #1
  488. // CHECK:STDOUT:
  489. // CHECK:STDOUT: declare noundef nonnull align 4 dereferenceable(4) ptr @_Z17ReturnConstIntRefv() #1
  490. // CHECK:STDOUT:
  491. // CHECK:STDOUT: attributes #0 = { nounwind }
  492. // CHECK:STDOUT: attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  493. // CHECK:STDOUT:
  494. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  495. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  496. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  497. // CHECK:STDOUT:
  498. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  499. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  500. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  501. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  502. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  503. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  504. // CHECK:STDOUT: !6 = !DIFile(filename: "return_references.carbon", directory: "")
  505. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  506. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  507. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  508. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  509. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "GetRefs", linkageName: "_CGetRefs.Main", scope: null, file: !6, line: 16, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  510. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  511. // CHECK:STDOUT: !13 = !{null}
  512. // CHECK:STDOUT: !14 = !DILocation(line: 17, column: 22, scope: !11)
  513. // CHECK:STDOUT: !15 = !DILocation(line: 18, column: 22, scope: !11)
  514. // CHECK:STDOUT: !16 = !DILocation(line: 19, column: 28, scope: !11)
  515. // CHECK:STDOUT: !17 = !DILocation(line: 21, column: 20, scope: !11)
  516. // CHECK:STDOUT: !18 = !DILocation(line: 22, column: 20, scope: !11)
  517. // CHECK:STDOUT: !19 = !DILocation(line: 23, column: 26, scope: !11)
  518. // CHECK:STDOUT: !20 = !DILocation(line: 16, column: 1, scope: !11)
  519. // CHECK:STDOUT: ; ModuleID = 'return_references_via_thunk.carbon'
  520. // CHECK:STDOUT: source_filename = "return_references_via_thunk.carbon"
  521. // CHECK:STDOUT: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
  522. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  523. // CHECK:STDOUT:
  524. // CHECK:STDOUT: %class.ForceThunk = type { i8 }
  525. // CHECK:STDOUT:
  526. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  527. // CHECK:STDOUT: define dso_local noundef nonnull align 1 dereferenceable(1) ptr @_Z10ReturnCRef10ForceThunk.carbon_thunk0() #0 {
  528. // CHECK:STDOUT: entry:
  529. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  530. // CHECK:STDOUT: %call = call noundef nonnull align 1 dereferenceable(1) ptr @_Z10ReturnCRef10ForceThunk()
  531. // CHECK:STDOUT: ret ptr %call
  532. // CHECK:STDOUT: }
  533. // CHECK:STDOUT:
  534. // CHECK:STDOUT: declare noundef nonnull align 1 dereferenceable(1) ptr @_Z10ReturnCRef10ForceThunk() #1
  535. // CHECK:STDOUT:
  536. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  537. // CHECK:STDOUT: define dso_local noundef nonnull align 1 dereferenceable(1) ptr @_Z11ReturnCRRef10ForceThunk.carbon_thunk0() #0 {
  538. // CHECK:STDOUT: entry:
  539. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  540. // CHECK:STDOUT: %call = call noundef nonnull align 1 dereferenceable(1) ptr @_Z11ReturnCRRef10ForceThunk()
  541. // CHECK:STDOUT: ret ptr %call
  542. // CHECK:STDOUT: }
  543. // CHECK:STDOUT:
  544. // CHECK:STDOUT: declare noundef nonnull align 1 dereferenceable(1) ptr @_Z11ReturnCRRef10ForceThunk() #1
  545. // CHECK:STDOUT:
  546. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  547. // CHECK:STDOUT: define dso_local noundef nonnull align 1 dereferenceable(1) ptr @_Z15ReturnConstCRef10ForceThunk.carbon_thunk0() #0 {
  548. // CHECK:STDOUT: entry:
  549. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  550. // CHECK:STDOUT: %call = call noundef nonnull align 1 dereferenceable(1) ptr @_Z15ReturnConstCRef10ForceThunk()
  551. // CHECK:STDOUT: ret ptr %call
  552. // CHECK:STDOUT: }
  553. // CHECK:STDOUT:
  554. // CHECK:STDOUT: declare noundef nonnull align 1 dereferenceable(1) ptr @_Z15ReturnConstCRef10ForceThunk() #1
  555. // CHECK:STDOUT:
  556. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  557. // CHECK:STDOUT: define dso_local noundef nonnull align 4 dereferenceable(4) ptr @_Z12ReturnIntRef10ForceThunk.carbon_thunk0() #0 {
  558. // CHECK:STDOUT: entry:
  559. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  560. // CHECK:STDOUT: %call = call noundef nonnull align 4 dereferenceable(4) ptr @_Z12ReturnIntRef10ForceThunk()
  561. // CHECK:STDOUT: ret ptr %call
  562. // CHECK:STDOUT: }
  563. // CHECK:STDOUT:
  564. // CHECK:STDOUT: declare noundef nonnull align 4 dereferenceable(4) ptr @_Z12ReturnIntRef10ForceThunk() #1
  565. // CHECK:STDOUT:
  566. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  567. // CHECK:STDOUT: define dso_local noundef nonnull align 4 dereferenceable(4) ptr @_Z13ReturnIntRRef10ForceThunk.carbon_thunk0() #0 {
  568. // CHECK:STDOUT: entry:
  569. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  570. // CHECK:STDOUT: %call = call noundef nonnull align 4 dereferenceable(4) ptr @_Z13ReturnIntRRef10ForceThunk()
  571. // CHECK:STDOUT: ret ptr %call
  572. // CHECK:STDOUT: }
  573. // CHECK:STDOUT:
  574. // CHECK:STDOUT: declare noundef nonnull align 4 dereferenceable(4) ptr @_Z13ReturnIntRRef10ForceThunk() #1
  575. // CHECK:STDOUT:
  576. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  577. // CHECK:STDOUT: define dso_local noundef nonnull align 4 dereferenceable(4) ptr @_Z17ReturnConstIntRef10ForceThunk.carbon_thunk0() #0 {
  578. // CHECK:STDOUT: entry:
  579. // CHECK:STDOUT: %agg.tmp = alloca %class.ForceThunk, align 1
  580. // CHECK:STDOUT: %call = call noundef nonnull align 4 dereferenceable(4) ptr @_Z17ReturnConstIntRef10ForceThunk()
  581. // CHECK:STDOUT: ret ptr %call
  582. // CHECK:STDOUT: }
  583. // CHECK:STDOUT:
  584. // CHECK:STDOUT: declare noundef nonnull align 4 dereferenceable(4) ptr @_Z17ReturnConstIntRef10ForceThunk() #1
  585. // CHECK:STDOUT:
  586. // CHECK:STDOUT: ; Function Attrs: nounwind
  587. // CHECK:STDOUT: define void @_CGetRefs.Main() #2 !dbg !11 {
  588. // CHECK:STDOUT: entry:
  589. // CHECK:STDOUT: %ReturnCRef__carbon_thunk.call = call ptr @_Z10ReturnCRef10ForceThunk.carbon_thunk0(), !dbg !14
  590. // CHECK:STDOUT: %ReturnCRRef__carbon_thunk.call = call ptr @_Z11ReturnCRRef10ForceThunk.carbon_thunk0(), !dbg !15
  591. // CHECK:STDOUT: %ReturnConstCRef__carbon_thunk.call = call ptr @_Z15ReturnConstCRef10ForceThunk.carbon_thunk0(), !dbg !16
  592. // CHECK:STDOUT: %ReturnIntRef__carbon_thunk.call = call ptr @_Z12ReturnIntRef10ForceThunk.carbon_thunk0(), !dbg !17
  593. // CHECK:STDOUT: %ReturnIntRRef__carbon_thunk.call = call ptr @_Z13ReturnIntRRef10ForceThunk.carbon_thunk0(), !dbg !18
  594. // CHECK:STDOUT: %ReturnConstIntRef__carbon_thunk.call = call ptr @_Z17ReturnConstIntRef10ForceThunk.carbon_thunk0(), !dbg !19
  595. // CHECK:STDOUT: ret void, !dbg !20
  596. // CHECK:STDOUT: }
  597. // CHECK:STDOUT:
  598. // CHECK:STDOUT: attributes #0 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  599. // CHECK:STDOUT: attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  600. // CHECK:STDOUT: attributes #2 = { nounwind }
  601. // CHECK:STDOUT:
  602. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  603. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  604. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  605. // CHECK:STDOUT:
  606. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  607. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  608. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  609. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  610. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  611. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  612. // CHECK:STDOUT: !6 = !DIFile(filename: "return_references_via_thunk.carbon", directory: "")
  613. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  614. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  615. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  616. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  617. // CHECK:STDOUT: !11 = distinct !DISubprogram(name: "GetRefs", linkageName: "_CGetRefs.Main", scope: null, file: !6, line: 17, type: !12, spFlags: DISPFlagDefinition, unit: !5)
  618. // CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
  619. // CHECK:STDOUT: !13 = !{null}
  620. // CHECK:STDOUT: !14 = !DILocation(line: 18, column: 22, scope: !11)
  621. // CHECK:STDOUT: !15 = !DILocation(line: 19, column: 22, scope: !11)
  622. // CHECK:STDOUT: !16 = !DILocation(line: 20, column: 28, scope: !11)
  623. // CHECK:STDOUT: !17 = !DILocation(line: 22, column: 20, scope: !11)
  624. // CHECK:STDOUT: !18 = !DILocation(line: 23, column: 20, scope: !11)
  625. // CHECK:STDOUT: !19 = !DILocation(line: 24, column: 26, scope: !11)
  626. // CHECK:STDOUT: !20 = !DILocation(line: 17, column: 1, scope: !11)