parameters.carbon 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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/primitives.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/parameters.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/parameters.carbon
  12. // ============================================================================
  13. // Parameter requires a thunk to be generated
  14. // ============================================================================
  15. // --- ints.h
  16. // TODO: Also test `long long` once it's supported.
  17. void pass_signed(signed char, short, int, long);
  18. void pass_unsigned(unsigned char, unsigned short, unsigned int, unsigned long);
  19. void pass_short(short);
  20. // --- import_ints.carbon
  21. library "[[@TEST_NAME]]";
  22. import Cpp library "ints.h";
  23. fn MyF() {
  24. Cpp.pass_signed(1, 2, 3, 4);
  25. Cpp.pass_unsigned(1, 2, 3, 4);
  26. }
  27. fn MakeShort() -> i16;
  28. var c: i16;
  29. fn PassShort(a: i16, b: i16*) {
  30. Cpp.pass_short(a);
  31. Cpp.pass_short(*b);
  32. Cpp.pass_short(c);
  33. Cpp.pass_short(MakeShort());
  34. }
  35. // --- struct.h
  36. struct X {
  37. int a;
  38. int b;
  39. int c;
  40. };
  41. void pass_struct(X);
  42. // --- import_struct.carbon
  43. library "[[@TEST_NAME]]";
  44. import Cpp library "struct.h";
  45. fn Test() {
  46. var x: Cpp.X;
  47. x.a = 1;
  48. x.b = 2;
  49. x.c = 3;
  50. Cpp.pass_struct(x);
  51. }
  52. // --- class_with_nontrivial_copy.h
  53. class Y {
  54. public:
  55. Y(const Y&);
  56. int a;
  57. int b;
  58. int c;
  59. };
  60. void pass_struct(Y);
  61. // --- import_class_with_nontrivial_copy.carbon
  62. library "[[@TEST_NAME]]";
  63. import Cpp library "class_with_nontrivial_copy.h";
  64. fn PassRefExpr() {
  65. var y: Cpp.Y;
  66. y.a = 1;
  67. y.b = 2;
  68. y.c = 3;
  69. Cpp.pass_struct(y);
  70. }
  71. fn Make() -> Cpp.Y;
  72. fn PassInitExpr() {
  73. Cpp.pass_struct(Make());
  74. }
  75. fn PassValueExpr(y: Cpp.Y) {
  76. Cpp.pass_struct(y);
  77. }
  78. // CHECK:STDOUT: ; ModuleID = 'import_ints.carbon'
  79. // CHECK:STDOUT: source_filename = "import_ints.carbon"
  80. // 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"
  81. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: @_Cc.Main = global i16 0
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: define void @_CMyF.Main() !dbg !7 {
  86. // CHECK:STDOUT: entry:
  87. // CHECK:STDOUT: %.loc7_19.3.temp = alloca i8, align 1, !dbg !10
  88. // CHECK:STDOUT: %.loc7_22.3.temp = alloca i16, align 2, !dbg !11
  89. // CHECK:STDOUT: %.loc9_21.3.temp = alloca i8, align 1, !dbg !12
  90. // CHECK:STDOUT: %.loc9_24.3.temp = alloca i16, align 2, !dbg !13
  91. // CHECK:STDOUT: %.loc9_27.3.temp = alloca i32, align 4, !dbg !14
  92. // CHECK:STDOUT: %.loc9_30.3.temp = alloca i64, align 8, !dbg !15
  93. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc7_19.3.temp), !dbg !10
  94. // CHECK:STDOUT: store i8 1, ptr %.loc7_19.3.temp, align 1, !dbg !10
  95. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc7_22.3.temp), !dbg !11
  96. // CHECK:STDOUT: store i16 2, ptr %.loc7_22.3.temp, align 2, !dbg !11
  97. // CHECK:STDOUT: call void @_Z11pass_signedasil.carbon_thunk(ptr %.loc7_19.3.temp, ptr %.loc7_22.3.temp, i32 3, i64 4), !dbg !16
  98. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc9_21.3.temp), !dbg !12
  99. // CHECK:STDOUT: store i8 1, ptr %.loc9_21.3.temp, align 1, !dbg !12
  100. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc9_24.3.temp), !dbg !13
  101. // CHECK:STDOUT: store i16 2, ptr %.loc9_24.3.temp, align 2, !dbg !13
  102. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc9_27.3.temp), !dbg !14
  103. // CHECK:STDOUT: store i32 3, ptr %.loc9_27.3.temp, align 4, !dbg !14
  104. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc9_30.3.temp), !dbg !15
  105. // CHECK:STDOUT: store i64 4, ptr %.loc9_30.3.temp, align 4, !dbg !15
  106. // CHECK:STDOUT: call void @_Z13pass_unsignedhtjm.carbon_thunk(ptr %.loc9_21.3.temp, ptr %.loc9_24.3.temp, ptr %.loc9_27.3.temp, ptr %.loc9_30.3.temp), !dbg !17
  107. // CHECK:STDOUT: ret void, !dbg !18
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: declare i16 @_CMakeShort.Main()
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: define void @_CPassShort.Main(i16 %a, ptr %b) !dbg !19 {
  113. // CHECK:STDOUT: entry:
  114. // CHECK:STDOUT: %.loc17_18.1.temp = alloca i16, align 2, !dbg !20
  115. // CHECK:STDOUT: %.loc18_18.3.temp = alloca i16, align 2, !dbg !21
  116. // CHECK:STDOUT: %.loc19_18.2.temp = alloca i16, align 2, !dbg !22
  117. // CHECK:STDOUT: %.loc20_28.3.temp = alloca i16, align 2, !dbg !23
  118. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc17_18.1.temp), !dbg !20
  119. // CHECK:STDOUT: store i16 %a, ptr %.loc17_18.1.temp, align 2, !dbg !20
  120. // CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk(ptr %.loc17_18.1.temp), !dbg !24
  121. // CHECK:STDOUT: %.loc18_18.2 = load i16, ptr %b, align 2, !dbg !21
  122. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_18.3.temp), !dbg !21
  123. // CHECK:STDOUT: store i16 %.loc18_18.2, ptr %.loc18_18.3.temp, align 2, !dbg !21
  124. // CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk(ptr %.loc18_18.3.temp), !dbg !25
  125. // CHECK:STDOUT: %.loc19_18.1 = load i16, ptr @_Cc.Main, align 2, !dbg !22
  126. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc19_18.2.temp), !dbg !22
  127. // CHECK:STDOUT: store i16 %.loc19_18.1, ptr %.loc19_18.2.temp, align 2, !dbg !22
  128. // CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk(ptr %.loc19_18.2.temp), !dbg !26
  129. // CHECK:STDOUT: %MakeShort.call = call i16 @_CMakeShort.Main(), !dbg !23
  130. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc20_28.3.temp), !dbg !23
  131. // CHECK:STDOUT: store i16 %MakeShort.call, ptr %.loc20_28.3.temp, align 2, !dbg !23
  132. // CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk(ptr %.loc20_28.3.temp), !dbg !27
  133. // CHECK:STDOUT: ret void, !dbg !28
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  137. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #0
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress
  140. // CHECK:STDOUT: define dso_local void @_Z11pass_signedasil.carbon_thunk(ptr %0, ptr %1, i32 %2, i64 %3) #1 {
  141. // CHECK:STDOUT: entry:
  142. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  143. // CHECK:STDOUT: %.addr1 = alloca ptr, align 8
  144. // CHECK:STDOUT: %.addr2 = alloca i32, align 4
  145. // CHECK:STDOUT: %.addr3 = alloca i64, align 8
  146. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8
  147. // CHECK:STDOUT: store ptr %1, ptr %.addr1, align 8
  148. // CHECK:STDOUT: store i32 %2, ptr %.addr2, align 4
  149. // CHECK:STDOUT: store i64 %3, ptr %.addr3, align 8
  150. // CHECK:STDOUT: %4 = load ptr, ptr %.addr, align 8
  151. // CHECK:STDOUT: %5 = load i8, ptr %4, align 1
  152. // CHECK:STDOUT: %6 = load ptr, ptr %.addr1, align 8
  153. // CHECK:STDOUT: %7 = load i16, ptr %6, align 2
  154. // CHECK:STDOUT: %8 = load i32, ptr %.addr2, align 4
  155. // CHECK:STDOUT: %9 = load i64, ptr %.addr3, align 8
  156. // CHECK:STDOUT: call void @_Z11pass_signedasil(i8 signext %5, i16 signext %7, i32 %8, i64 %9)
  157. // CHECK:STDOUT: ret void
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: declare void @_Z11pass_signedasil(i8 signext, i16 signext, i32, i64) #2
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress
  163. // CHECK:STDOUT: define dso_local void @_Z13pass_unsignedhtjm.carbon_thunk(ptr %0, ptr %1, ptr %2, ptr %3) #1 {
  164. // CHECK:STDOUT: entry:
  165. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  166. // CHECK:STDOUT: %.addr1 = alloca ptr, align 8
  167. // CHECK:STDOUT: %.addr2 = alloca ptr, align 8
  168. // CHECK:STDOUT: %.addr3 = alloca ptr, align 8
  169. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8
  170. // CHECK:STDOUT: store ptr %1, ptr %.addr1, align 8
  171. // CHECK:STDOUT: store ptr %2, ptr %.addr2, align 8
  172. // CHECK:STDOUT: store ptr %3, ptr %.addr3, align 8
  173. // CHECK:STDOUT: %4 = load ptr, ptr %.addr, align 8
  174. // CHECK:STDOUT: %5 = load i8, ptr %4, align 1
  175. // CHECK:STDOUT: %6 = load ptr, ptr %.addr1, align 8
  176. // CHECK:STDOUT: %7 = load i16, ptr %6, align 2
  177. // CHECK:STDOUT: %8 = load ptr, ptr %.addr2, align 8
  178. // CHECK:STDOUT: %9 = load i32, ptr %8, align 4
  179. // CHECK:STDOUT: %10 = load ptr, ptr %.addr3, align 8
  180. // CHECK:STDOUT: %11 = load i64, ptr %10, align 8
  181. // CHECK:STDOUT: call void @_Z13pass_unsignedhtjm(i8 zeroext %5, i16 zeroext %7, i32 %9, i64 %11)
  182. // CHECK:STDOUT: ret void
  183. // CHECK:STDOUT: }
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: declare void @_Z13pass_unsignedhtjm(i8 zeroext, i16 zeroext, i32, i64) #2
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress
  188. // CHECK:STDOUT: define dso_local void @_Z10pass_shorts.carbon_thunk(ptr %0) #1 {
  189. // CHECK:STDOUT: entry:
  190. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  191. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8
  192. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8
  193. // CHECK:STDOUT: %2 = load i16, ptr %1, align 2
  194. // CHECK:STDOUT: call void @_Z10pass_shorts(i16 signext %2)
  195. // CHECK:STDOUT: ret void
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: declare void @_Z10pass_shorts(i16 signext) #2
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: ; uselistorder directives
  201. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  204. // CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  205. // CHECK:STDOUT: attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  208. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  211. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  212. // CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
  213. // CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
  214. // CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
  215. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  216. // CHECK:STDOUT: !6 = !DIFile(filename: "import_ints.carbon", directory: "")
  217. // CHECK:STDOUT: !7 = distinct !DISubprogram(name: "MyF", linkageName: "_CMyF.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5)
  218. // CHECK:STDOUT: !8 = !DISubroutineType(types: !9)
  219. // CHECK:STDOUT: !9 = !{}
  220. // CHECK:STDOUT: !10 = !DILocation(line: 7, column: 19, scope: !7)
  221. // CHECK:STDOUT: !11 = !DILocation(line: 7, column: 22, scope: !7)
  222. // CHECK:STDOUT: !12 = !DILocation(line: 9, column: 21, scope: !7)
  223. // CHECK:STDOUT: !13 = !DILocation(line: 9, column: 24, scope: !7)
  224. // CHECK:STDOUT: !14 = !DILocation(line: 9, column: 27, scope: !7)
  225. // CHECK:STDOUT: !15 = !DILocation(line: 9, column: 30, scope: !7)
  226. // CHECK:STDOUT: !16 = !DILocation(line: 7, column: 3, scope: !7)
  227. // CHECK:STDOUT: !17 = !DILocation(line: 9, column: 3, scope: !7)
  228. // CHECK:STDOUT: !18 = !DILocation(line: 6, column: 1, scope: !7)
  229. // CHECK:STDOUT: !19 = distinct !DISubprogram(name: "PassShort", linkageName: "_CPassShort.Main", scope: null, file: !6, line: 16, type: !8, spFlags: DISPFlagDefinition, unit: !5)
  230. // CHECK:STDOUT: !20 = !DILocation(line: 17, column: 18, scope: !19)
  231. // CHECK:STDOUT: !21 = !DILocation(line: 18, column: 18, scope: !19)
  232. // CHECK:STDOUT: !22 = !DILocation(line: 19, column: 18, scope: !19)
  233. // CHECK:STDOUT: !23 = !DILocation(line: 20, column: 18, scope: !19)
  234. // CHECK:STDOUT: !24 = !DILocation(line: 17, column: 3, scope: !19)
  235. // CHECK:STDOUT: !25 = !DILocation(line: 18, column: 3, scope: !19)
  236. // CHECK:STDOUT: !26 = !DILocation(line: 19, column: 3, scope: !19)
  237. // CHECK:STDOUT: !27 = !DILocation(line: 20, column: 3, scope: !19)
  238. // CHECK:STDOUT: !28 = !DILocation(line: 16, column: 1, scope: !19)
  239. // CHECK:STDOUT: ; ModuleID = 'import_struct.carbon'
  240. // CHECK:STDOUT: source_filename = "import_struct.carbon"
  241. // 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"
  242. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  243. // CHECK:STDOUT:
  244. // CHECK:STDOUT: %struct.X = type { i32, i32, i32 }
  245. // CHECK:STDOUT:
  246. // CHECK:STDOUT: define void @_CTest.Main() !dbg !7 {
  247. // CHECK:STDOUT: entry:
  248. // CHECK:STDOUT: %x.var = alloca [12 x i8], align 1, !dbg !10
  249. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %x.var), !dbg !10
  250. // CHECK:STDOUT: %.loc8_4.a = getelementptr inbounds nuw [12 x i8], ptr %x.var, i32 0, i32 0, !dbg !11
  251. // CHECK:STDOUT: store i32 1, ptr %.loc8_4.a, align 4, !dbg !11
  252. // CHECK:STDOUT: %.loc9_4.b = getelementptr inbounds nuw [12 x i8], ptr %x.var, i32 0, i32 4, !dbg !12
  253. // CHECK:STDOUT: store i32 2, ptr %.loc9_4.b, align 4, !dbg !12
  254. // CHECK:STDOUT: %.loc10_4.c = getelementptr inbounds nuw [12 x i8], ptr %x.var, i32 0, i32 8, !dbg !13
  255. // CHECK:STDOUT: store i32 3, ptr %.loc10_4.c, align 4, !dbg !13
  256. // CHECK:STDOUT: call void @_Z11pass_struct1X.carbon_thunk(ptr %x.var), !dbg !14
  257. // CHECK:STDOUT: ret void, !dbg !15
  258. // CHECK:STDOUT: }
  259. // CHECK:STDOUT:
  260. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  261. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #0
  262. // CHECK:STDOUT:
  263. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress
  264. // CHECK:STDOUT: define dso_local void @_Z11pass_struct1X.carbon_thunk(ptr %0) #1 {
  265. // CHECK:STDOUT: entry:
  266. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  267. // CHECK:STDOUT: %agg.tmp = alloca %struct.X, align 4
  268. // CHECK:STDOUT: %agg.tmp.coerce = alloca { i64, i32 }, align 4
  269. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8
  270. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8
  271. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %agg.tmp, ptr align 4 %1, i64 12, i1 false)
  272. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %agg.tmp.coerce, ptr align 4 %agg.tmp, i64 12, i1 false)
  273. // CHECK:STDOUT: %2 = getelementptr inbounds nuw { i64, i32 }, ptr %agg.tmp.coerce, i32 0, i32 0
  274. // CHECK:STDOUT: %3 = load i64, ptr %2, align 4
  275. // CHECK:STDOUT: %4 = getelementptr inbounds nuw { i64, i32 }, ptr %agg.tmp.coerce, i32 0, i32 1
  276. // CHECK:STDOUT: %5 = load i32, ptr %4, align 4
  277. // CHECK:STDOUT: call void @_Z11pass_struct1X(i64 %3, i32 %5)
  278. // CHECK:STDOUT: ret void
  279. // CHECK:STDOUT: }
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  282. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
  283. // CHECK:STDOUT:
  284. // CHECK:STDOUT: declare void @_Z11pass_struct1X(i64, i32) #3
  285. // CHECK:STDOUT:
  286. // CHECK:STDOUT: ; uselistorder directives
  287. // CHECK:STDOUT: uselistorder ptr @llvm.memcpy.p0.p0.i64, { 1, 0 }
  288. // CHECK:STDOUT:
  289. // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  290. // CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  291. // CHECK:STDOUT: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  292. // CHECK:STDOUT: attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  293. // CHECK:STDOUT:
  294. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  295. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  296. // CHECK:STDOUT:
  297. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  298. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  299. // CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
  300. // CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
  301. // CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
  302. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  303. // CHECK:STDOUT: !6 = !DIFile(filename: "import_struct.carbon", directory: "")
  304. // CHECK:STDOUT: !7 = distinct !DISubprogram(name: "Test", linkageName: "_CTest.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5)
  305. // CHECK:STDOUT: !8 = !DISubroutineType(types: !9)
  306. // CHECK:STDOUT: !9 = !{}
  307. // CHECK:STDOUT: !10 = !DILocation(line: 7, column: 3, scope: !7)
  308. // CHECK:STDOUT: !11 = !DILocation(line: 8, column: 3, scope: !7)
  309. // CHECK:STDOUT: !12 = !DILocation(line: 9, column: 3, scope: !7)
  310. // CHECK:STDOUT: !13 = !DILocation(line: 10, column: 3, scope: !7)
  311. // CHECK:STDOUT: !14 = !DILocation(line: 11, column: 3, scope: !7)
  312. // CHECK:STDOUT: !15 = !DILocation(line: 6, column: 1, scope: !7)
  313. // CHECK:STDOUT: ; ModuleID = 'import_class_with_nontrivial_copy.carbon'
  314. // CHECK:STDOUT: source_filename = "import_class_with_nontrivial_copy.carbon"
  315. // 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"
  316. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  317. // CHECK:STDOUT:
  318. // CHECK:STDOUT: %class.Y = type { i32, i32, i32 }
  319. // CHECK:STDOUT:
  320. // CHECK:STDOUT: define void @_CPassRefExpr.Main() !dbg !7 {
  321. // CHECK:STDOUT: entry:
  322. // CHECK:STDOUT: %y.var = alloca [12 x i8], align 1, !dbg !10
  323. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %y.var), !dbg !10
  324. // CHECK:STDOUT: %.loc8_4.a = getelementptr inbounds nuw [12 x i8], ptr %y.var, i32 0, i32 0, !dbg !11
  325. // CHECK:STDOUT: store i32 1, ptr %.loc8_4.a, align 4, !dbg !11
  326. // CHECK:STDOUT: %.loc9_4.b = getelementptr inbounds nuw [12 x i8], ptr %y.var, i32 0, i32 4, !dbg !12
  327. // CHECK:STDOUT: store i32 2, ptr %.loc9_4.b, align 4, !dbg !12
  328. // CHECK:STDOUT: %.loc10_4.c = getelementptr inbounds nuw [12 x i8], ptr %y.var, i32 0, i32 8, !dbg !13
  329. // CHECK:STDOUT: store i32 3, ptr %.loc10_4.c, align 4, !dbg !13
  330. // CHECK:STDOUT: call void @_Z11pass_struct1Y.carbon_thunk(ptr %y.var), !dbg !14
  331. // CHECK:STDOUT: ret void, !dbg !15
  332. // CHECK:STDOUT: }
  333. // CHECK:STDOUT:
  334. // CHECK:STDOUT: declare void @_CMake.Main(ptr sret([12 x i8]))
  335. // CHECK:STDOUT:
  336. // CHECK:STDOUT: define void @_CPassInitExpr.Main() !dbg !16 {
  337. // CHECK:STDOUT: entry:
  338. // CHECK:STDOUT: %.loc17_24.1.temp = alloca [12 x i8], align 1, !dbg !17
  339. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc17_24.1.temp), !dbg !17
  340. // CHECK:STDOUT: call void @_CMake.Main(ptr %.loc17_24.1.temp), !dbg !17
  341. // CHECK:STDOUT: call void @_Z11pass_struct1Y.carbon_thunk(ptr %.loc17_24.1.temp), !dbg !18
  342. // CHECK:STDOUT: ret void, !dbg !19
  343. // CHECK:STDOUT: }
  344. // CHECK:STDOUT:
  345. // CHECK:STDOUT: define void @_CPassValueExpr.Main(ptr %y) !dbg !20 {
  346. // CHECK:STDOUT: entry:
  347. // CHECK:STDOUT: call void @_Z11pass_struct1Y.carbon_thunk(ptr %y), !dbg !21
  348. // CHECK:STDOUT: ret void, !dbg !22
  349. // CHECK:STDOUT: }
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  352. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #0
  353. // CHECK:STDOUT:
  354. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress
  355. // CHECK:STDOUT: define dso_local void @_Z11pass_struct1Y.carbon_thunk(ptr %0) #1 {
  356. // CHECK:STDOUT: entry:
  357. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  358. // CHECK:STDOUT: %agg.tmp = alloca %class.Y, align 4
  359. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8
  360. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8
  361. // CHECK:STDOUT: call void @_ZN1YC1ERKS_(ptr nonnull align 4 dereferenceable(12) %agg.tmp, ptr nonnull align 4 dereferenceable(12) %1)
  362. // CHECK:STDOUT: call void @_Z11pass_struct1Y(ptr dead_on_return %agg.tmp)
  363. // CHECK:STDOUT: ret void
  364. // CHECK:STDOUT: }
  365. // CHECK:STDOUT:
  366. // CHECK:STDOUT: declare void @_ZN1YC1ERKS_(ptr nonnull align 4 dereferenceable(12), ptr nonnull align 4 dereferenceable(12)) unnamed_addr #2
  367. // CHECK:STDOUT:
  368. // CHECK:STDOUT: declare void @_Z11pass_struct1Y(ptr dead_on_return) #2
  369. // CHECK:STDOUT:
  370. // CHECK:STDOUT: ; uselistorder directives
  371. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 1, 0 }
  372. // CHECK:STDOUT:
  373. // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  374. // CHECK:STDOUT: attributes #1 = { alwaysinline mustprogress "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  375. // CHECK:STDOUT: attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="0" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  376. // CHECK:STDOUT:
  377. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  378. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  379. // CHECK:STDOUT:
  380. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  381. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  382. // CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
  383. // CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
  384. // CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
  385. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  386. // CHECK:STDOUT: !6 = !DIFile(filename: "import_class_with_nontrivial_copy.carbon", directory: "")
  387. // CHECK:STDOUT: !7 = distinct !DISubprogram(name: "PassRefExpr", linkageName: "_CPassRefExpr.Main", scope: null, file: !6, line: 6, type: !8, spFlags: DISPFlagDefinition, unit: !5)
  388. // CHECK:STDOUT: !8 = !DISubroutineType(types: !9)
  389. // CHECK:STDOUT: !9 = !{}
  390. // CHECK:STDOUT: !10 = !DILocation(line: 7, column: 3, scope: !7)
  391. // CHECK:STDOUT: !11 = !DILocation(line: 8, column: 3, scope: !7)
  392. // CHECK:STDOUT: !12 = !DILocation(line: 9, column: 3, scope: !7)
  393. // CHECK:STDOUT: !13 = !DILocation(line: 10, column: 3, scope: !7)
  394. // CHECK:STDOUT: !14 = !DILocation(line: 11, column: 3, scope: !7)
  395. // CHECK:STDOUT: !15 = !DILocation(line: 6, column: 1, scope: !7)
  396. // CHECK:STDOUT: !16 = distinct !DISubprogram(name: "PassInitExpr", linkageName: "_CPassInitExpr.Main", scope: null, file: !6, line: 16, type: !8, spFlags: DISPFlagDefinition, unit: !5)
  397. // CHECK:STDOUT: !17 = !DILocation(line: 17, column: 19, scope: !16)
  398. // CHECK:STDOUT: !18 = !DILocation(line: 17, column: 3, scope: !16)
  399. // CHECK:STDOUT: !19 = !DILocation(line: 16, column: 1, scope: !16)
  400. // CHECK:STDOUT: !20 = distinct !DISubprogram(name: "PassValueExpr", linkageName: "_CPassValueExpr.Main", scope: null, file: !6, line: 20, type: !8, spFlags: DISPFlagDefinition, unit: !5)
  401. // CHECK:STDOUT: !21 = !DILocation(line: 21, column: 3, scope: !20)
  402. // CHECK:STDOUT: !22 = !DILocation(line: 20, column: 1, scope: !20)