parameters.carbon 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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: @int_1.30e = internal constant i8 1
  84. // CHECK:STDOUT: @int_2.305 = internal constant i16 2
  85. // CHECK:STDOUT: @int_1.e80 = internal constant i8 1
  86. // CHECK:STDOUT: @int_2.fb2 = internal constant i16 2
  87. // CHECK:STDOUT: @_Cc.Main = global i16 0
  88. // CHECK:STDOUT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @_C__global_init.Main, ptr null }]
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  91. // CHECK:STDOUT: define dso_local void @_Z11pass_signedasil.carbon_thunk(ptr noundef %0, ptr noundef %1, i32 noundef %2, i64 noundef %3) #0 {
  92. // CHECK:STDOUT: entry:
  93. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  94. // CHECK:STDOUT: %.addr1 = alloca ptr, align 8
  95. // CHECK:STDOUT: %.addr2 = alloca i32, align 4
  96. // CHECK:STDOUT: %.addr3 = alloca i64, align 8
  97. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !11
  98. // CHECK:STDOUT: store ptr %1, ptr %.addr1, align 8, !tbaa !14
  99. // CHECK:STDOUT: store i32 %2, ptr %.addr2, align 4, !tbaa !7
  100. // CHECK:STDOUT: store i64 %3, ptr %.addr3, align 8, !tbaa !16
  101. // CHECK:STDOUT: %4 = load ptr, ptr %.addr, align 8, !tbaa !11
  102. // CHECK:STDOUT: %5 = load i8, ptr %4, align 1, !tbaa !18
  103. // CHECK:STDOUT: %6 = load ptr, ptr %.addr1, align 8, !tbaa !14
  104. // CHECK:STDOUT: %7 = load i16, ptr %6, align 2, !tbaa !19
  105. // CHECK:STDOUT: %8 = load i32, ptr %.addr2, align 4, !tbaa !7
  106. // CHECK:STDOUT: %9 = load i64, ptr %.addr3, align 8, !tbaa !16
  107. // CHECK:STDOUT: call void @_Z11pass_signedasil(i8 noundef signext %5, i16 noundef signext %7, i32 noundef %8, i64 noundef %9)
  108. // CHECK:STDOUT: ret void
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: declare void @_Z11pass_signedasil(i8 noundef signext, i16 noundef signext, i32 noundef, i64 noundef) #1
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  114. // CHECK:STDOUT: define dso_local void @_Z13pass_unsignedhtjm.carbon_thunk(ptr noundef %0, ptr noundef %1, i32 noundef %2, i64 noundef %3) #0 {
  115. // CHECK:STDOUT: entry:
  116. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  117. // CHECK:STDOUT: %.addr1 = alloca ptr, align 8
  118. // CHECK:STDOUT: %.addr2 = alloca i32, align 4
  119. // CHECK:STDOUT: %.addr3 = alloca i64, align 8
  120. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !11
  121. // CHECK:STDOUT: store ptr %1, ptr %.addr1, align 8, !tbaa !14
  122. // CHECK:STDOUT: store i32 %2, ptr %.addr2, align 4, !tbaa !7
  123. // CHECK:STDOUT: store i64 %3, ptr %.addr3, align 8, !tbaa !16
  124. // CHECK:STDOUT: %4 = load ptr, ptr %.addr, align 8, !tbaa !11
  125. // CHECK:STDOUT: %5 = load i8, ptr %4, align 1, !tbaa !18
  126. // CHECK:STDOUT: %6 = load ptr, ptr %.addr1, align 8, !tbaa !14
  127. // CHECK:STDOUT: %7 = load i16, ptr %6, align 2, !tbaa !19
  128. // CHECK:STDOUT: %8 = load i32, ptr %.addr2, align 4, !tbaa !7
  129. // CHECK:STDOUT: %9 = load i64, ptr %.addr3, align 8, !tbaa !16
  130. // CHECK:STDOUT: call void @_Z13pass_unsignedhtjm(i8 noundef zeroext %5, i16 noundef zeroext %7, i32 noundef %8, i64 noundef %9)
  131. // CHECK:STDOUT: ret void
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: declare void @_Z13pass_unsignedhtjm(i8 noundef zeroext, i16 noundef zeroext, i32 noundef, i64 noundef) #1
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  137. // CHECK:STDOUT: define dso_local void @_Z10pass_shorts.carbon_thunk(ptr noundef %0) #0 {
  138. // CHECK:STDOUT: entry:
  139. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  140. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !14
  141. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !14
  142. // CHECK:STDOUT: %2 = load i16, ptr %1, align 2, !tbaa !19
  143. // CHECK:STDOUT: call void @_Z10pass_shorts(i16 noundef signext %2)
  144. // CHECK:STDOUT: ret void
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: declare void @_Z10pass_shorts(i16 noundef signext) #1
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: ; Function Attrs: nounwind
  150. // CHECK:STDOUT: define void @_CMyF.Main() #2 !dbg !21 {
  151. // CHECK:STDOUT: entry:
  152. // CHECK:STDOUT: %.loc7_19.3.temp = alloca i8, align 1, !dbg !24
  153. // CHECK:STDOUT: %.loc7_22.3.temp = alloca i16, align 2, !dbg !25
  154. // CHECK:STDOUT: %.loc9_21.3.temp = alloca i8, align 1, !dbg !26
  155. // CHECK:STDOUT: %.loc9_24.3.temp = alloca i16, align 2, !dbg !27
  156. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc7_19.3.temp), !dbg !24
  157. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc7_22.3.temp), !dbg !25
  158. // CHECK:STDOUT: call void @_Z11pass_signedasil.carbon_thunk(ptr @int_1.30e, ptr @int_2.305, i32 3, i64 4), !dbg !28
  159. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc9_21.3.temp), !dbg !26
  160. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc9_24.3.temp), !dbg !27
  161. // CHECK:STDOUT: call void @_Z13pass_unsignedhtjm.carbon_thunk(ptr @int_1.e80, ptr @int_2.fb2, i32 3, i64 4), !dbg !29
  162. // CHECK:STDOUT: ret void, !dbg !30
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: declare i16 @_CMakeShort.Main()
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: ; Function Attrs: nounwind
  168. // CHECK:STDOUT: define void @_CPassShort.Main(i16 %a, ptr %b) #2 !dbg !31 {
  169. // CHECK:STDOUT: entry:
  170. // CHECK:STDOUT: %.loc17_18.1.temp = alloca i16, align 2, !dbg !39
  171. // CHECK:STDOUT: %.loc18_18.3.temp = alloca i16, align 2, !dbg !40
  172. // CHECK:STDOUT: %.loc19_18.2.temp = alloca i16, align 2, !dbg !41
  173. // CHECK:STDOUT: %.loc20_28.3.temp = alloca i16, align 2, !dbg !42
  174. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc17_18.1.temp), !dbg !39
  175. // CHECK:STDOUT: store i16 %a, ptr %.loc17_18.1.temp, align 2, !dbg !39
  176. // CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk(ptr %.loc17_18.1.temp), !dbg !43
  177. // CHECK:STDOUT: %.loc18_18.2 = load i16, ptr %b, align 2, !dbg !40
  178. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc18_18.3.temp), !dbg !40
  179. // CHECK:STDOUT: store i16 %.loc18_18.2, ptr %.loc18_18.3.temp, align 2, !dbg !40
  180. // CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk(ptr %.loc18_18.3.temp), !dbg !44
  181. // CHECK:STDOUT: %.loc19_18.1 = load i16, ptr @_Cc.Main, align 2, !dbg !41
  182. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc19_18.2.temp), !dbg !41
  183. // CHECK:STDOUT: store i16 %.loc19_18.1, ptr %.loc19_18.2.temp, align 2, !dbg !41
  184. // CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk(ptr %.loc19_18.2.temp), !dbg !45
  185. // CHECK:STDOUT: %MakeShort.call = call i16 @_CMakeShort.Main(), !dbg !42
  186. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc20_28.3.temp), !dbg !42
  187. // CHECK:STDOUT: store i16 %MakeShort.call, ptr %.loc20_28.3.temp, align 2, !dbg !42
  188. // CHECK:STDOUT: call void @_Z10pass_shorts.carbon_thunk(ptr %.loc20_28.3.temp), !dbg !46
  189. // CHECK:STDOUT: ret void, !dbg !47
  190. // CHECK:STDOUT: }
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  193. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #3
  194. // CHECK:STDOUT:
  195. // CHECK:STDOUT: ; Function Attrs: nounwind
  196. // CHECK:STDOUT: define internal void @_C__global_init.Main() #2 !dbg !48 {
  197. // CHECK:STDOUT: entry:
  198. // CHECK:STDOUT: store i16 poison, ptr @_Cc.Main, align 2, !dbg !49
  199. // CHECK:STDOUT: ret void, !dbg !50
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: ; uselistorder directives
  203. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 7, 6, 5, 4, 3, 2, 1, 0 }
  204. // CHECK:STDOUT:
  205. // 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" }
  206. // 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" }
  207. // CHECK:STDOUT: attributes #2 = { nounwind }
  208. // CHECK:STDOUT: attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  211. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  212. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  215. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  216. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  217. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  218. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  219. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  220. // CHECK:STDOUT: !6 = !DIFile(filename: "import_ints.carbon", directory: "")
  221. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  222. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  223. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  224. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  225. // CHECK:STDOUT: !11 = !{!12, !12, i64 0}
  226. // CHECK:STDOUT: !12 = !{!"p1 omnipotent char", !13, i64 0}
  227. // CHECK:STDOUT: !13 = !{!"any pointer", !9, i64 0}
  228. // CHECK:STDOUT: !14 = !{!15, !15, i64 0}
  229. // CHECK:STDOUT: !15 = !{!"p1 short", !13, i64 0}
  230. // CHECK:STDOUT: !16 = !{!17, !17, i64 0}
  231. // CHECK:STDOUT: !17 = !{!"long", !9, i64 0}
  232. // CHECK:STDOUT: !18 = !{!9, !9, i64 0}
  233. // CHECK:STDOUT: !19 = !{!20, !20, i64 0}
  234. // CHECK:STDOUT: !20 = !{!"short", !9, i64 0}
  235. // CHECK:STDOUT: !21 = distinct !DISubprogram(name: "MyF", linkageName: "_CMyF.Main", scope: null, file: !6, line: 6, type: !22, spFlags: DISPFlagDefinition, unit: !5)
  236. // CHECK:STDOUT: !22 = !DISubroutineType(types: !23)
  237. // CHECK:STDOUT: !23 = !{null}
  238. // CHECK:STDOUT: !24 = !DILocation(line: 7, column: 19, scope: !21)
  239. // CHECK:STDOUT: !25 = !DILocation(line: 7, column: 22, scope: !21)
  240. // CHECK:STDOUT: !26 = !DILocation(line: 9, column: 21, scope: !21)
  241. // CHECK:STDOUT: !27 = !DILocation(line: 9, column: 24, scope: !21)
  242. // CHECK:STDOUT: !28 = !DILocation(line: 7, column: 3, scope: !21)
  243. // CHECK:STDOUT: !29 = !DILocation(line: 9, column: 3, scope: !21)
  244. // CHECK:STDOUT: !30 = !DILocation(line: 6, column: 1, scope: !21)
  245. // CHECK:STDOUT: !31 = distinct !DISubprogram(name: "PassShort", linkageName: "_CPassShort.Main", scope: null, file: !6, line: 16, type: !32, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !36)
  246. // CHECK:STDOUT: !32 = !DISubroutineType(types: !33)
  247. // CHECK:STDOUT: !33 = !{null, !34, !35}
  248. // CHECK:STDOUT: !34 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
  249. // CHECK:STDOUT: !35 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  250. // CHECK:STDOUT: !36 = !{!37, !38}
  251. // CHECK:STDOUT: !37 = !DILocalVariable(arg: 1, scope: !31, type: !34)
  252. // CHECK:STDOUT: !38 = !DILocalVariable(arg: 2, scope: !31, type: !35)
  253. // CHECK:STDOUT: !39 = !DILocation(line: 17, column: 18, scope: !31)
  254. // CHECK:STDOUT: !40 = !DILocation(line: 18, column: 18, scope: !31)
  255. // CHECK:STDOUT: !41 = !DILocation(line: 19, column: 18, scope: !31)
  256. // CHECK:STDOUT: !42 = !DILocation(line: 20, column: 18, scope: !31)
  257. // CHECK:STDOUT: !43 = !DILocation(line: 17, column: 3, scope: !31)
  258. // CHECK:STDOUT: !44 = !DILocation(line: 18, column: 3, scope: !31)
  259. // CHECK:STDOUT: !45 = !DILocation(line: 19, column: 3, scope: !31)
  260. // CHECK:STDOUT: !46 = !DILocation(line: 20, column: 3, scope: !31)
  261. // CHECK:STDOUT: !47 = !DILocation(line: 16, column: 1, scope: !31)
  262. // CHECK:STDOUT: !48 = distinct !DISubprogram(name: "__global_init", linkageName: "_C__global_init.Main", scope: null, file: !6, type: !22, spFlags: DISPFlagDefinition, unit: !5)
  263. // CHECK:STDOUT: !49 = !DILocation(line: 14, column: 1, scope: !48)
  264. // CHECK:STDOUT: !50 = !DILocation(line: 0, scope: !48)
  265. // CHECK:STDOUT: ; ModuleID = 'import_struct.carbon'
  266. // CHECK:STDOUT: source_filename = "import_struct.carbon"
  267. // 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"
  268. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  269. // CHECK:STDOUT:
  270. // CHECK:STDOUT: %struct.X = type { i32, i32, i32 }
  271. // CHECK:STDOUT:
  272. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress nounwind uwtable
  273. // CHECK:STDOUT: define dso_local void @_ZN1XC1Ev.carbon_thunk(ptr noundef %return) #0 {
  274. // CHECK:STDOUT: entry:
  275. // CHECK:STDOUT: %return.addr = alloca ptr, align 8
  276. // CHECK:STDOUT: store ptr %return, ptr %return.addr, align 8, !tbaa !11
  277. // CHECK:STDOUT: %0 = load ptr, ptr %return.addr, align 8, !tbaa !11
  278. // CHECK:STDOUT: ret void
  279. // CHECK:STDOUT: }
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  282. // CHECK:STDOUT: define dso_local void @_Z11pass_struct1X.carbon_thunk(ptr noundef %0) #1 {
  283. // CHECK:STDOUT: entry:
  284. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  285. // CHECK:STDOUT: %agg.tmp = alloca %struct.X, align 4
  286. // CHECK:STDOUT: %agg.tmp.coerce = alloca { i64, i32 }, align 4
  287. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !11
  288. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !11
  289. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %agg.tmp, ptr align 4 %1, i64 12, i1 false), !tbaa.struct !14
  290. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %agg.tmp.coerce, ptr align 4 %agg.tmp, i64 12, i1 false)
  291. // CHECK:STDOUT: %2 = getelementptr inbounds nuw { i64, i32 }, ptr %agg.tmp.coerce, i32 0, i32 0
  292. // CHECK:STDOUT: %3 = load i64, ptr %2, align 4
  293. // CHECK:STDOUT: %4 = getelementptr inbounds nuw { i64, i32 }, ptr %agg.tmp.coerce, i32 0, i32 1
  294. // CHECK:STDOUT: %5 = load i32, ptr %4, align 4
  295. // CHECK:STDOUT: call void @_Z11pass_struct1X(i64 %3, i32 %5)
  296. // CHECK:STDOUT: ret void
  297. // CHECK:STDOUT: }
  298. // CHECK:STDOUT:
  299. // CHECK:STDOUT: declare void @_Z11pass_struct1X(i64, i32) #2
  300. // CHECK:STDOUT:
  301. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  302. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #3
  303. // CHECK:STDOUT:
  304. // CHECK:STDOUT: ; Function Attrs: nounwind
  305. // CHECK:STDOUT: define void @_CTest.Main() #4 !dbg !15 {
  306. // CHECK:STDOUT: entry:
  307. // CHECK:STDOUT: %x.var = alloca [12 x i8], align 1, !dbg !18
  308. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %x.var), !dbg !18
  309. // CHECK:STDOUT: call void @"_COp.9b0a46309e124f8a:DefaultOrUnformed.Core.64f6b96556a8f2d4"(ptr %x.var), !dbg !18
  310. // CHECK:STDOUT: %.loc8_4.a = getelementptr inbounds nuw [12 x i8], ptr %x.var, i32 0, i32 0, !dbg !19
  311. // CHECK:STDOUT: store i32 1, ptr %.loc8_4.a, align 4, !dbg !19
  312. // CHECK:STDOUT: %.loc9_4.b = getelementptr inbounds nuw [12 x i8], ptr %x.var, i32 0, i32 4, !dbg !20
  313. // CHECK:STDOUT: store i32 2, ptr %.loc9_4.b, align 4, !dbg !20
  314. // CHECK:STDOUT: %.loc10_4.c = getelementptr inbounds nuw [12 x i8], ptr %x.var, i32 0, i32 8, !dbg !21
  315. // CHECK:STDOUT: store i32 3, ptr %.loc10_4.c, align 4, !dbg !21
  316. // CHECK:STDOUT: call void @_Z11pass_struct1X.carbon_thunk(ptr %x.var), !dbg !22
  317. // CHECK:STDOUT: ret void, !dbg !23
  318. // CHECK:STDOUT: }
  319. // CHECK:STDOUT:
  320. // CHECK:STDOUT: ; Function Attrs: alwaysinline nounwind
  321. // CHECK:STDOUT: define void @"_COp:thunk.X.Cpp"(ptr sret([12 x i8]) %return) #5 !dbg !24 {
  322. // CHECK:STDOUT: entry:
  323. // CHECK:STDOUT: call void @_ZN1XC1Ev.carbon_thunk(ptr %return), !dbg !29
  324. // CHECK:STDOUT: ret void, !dbg !29
  325. // CHECK:STDOUT: }
  326. // CHECK:STDOUT:
  327. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  328. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #6
  329. // CHECK:STDOUT:
  330. // CHECK:STDOUT: ; Function Attrs: nounwind
  331. // CHECK:STDOUT: define linkonce_odr void @"_COp.9b0a46309e124f8a:DefaultOrUnformed.Core.64f6b96556a8f2d4"(ptr sret([12 x i8]) %return) #4 !dbg !30 {
  332. // CHECK:STDOUT: call void @"_COp:thunk.X.Cpp"(ptr %return), !dbg !32
  333. // CHECK:STDOUT: ret void, !dbg !33
  334. // CHECK:STDOUT: }
  335. // CHECK:STDOUT:
  336. // CHECK:STDOUT: ; uselistorder directives
  337. // CHECK:STDOUT: uselistorder ptr @llvm.memcpy.p0.p0.i64, { 1, 0 }
  338. // CHECK:STDOUT:
  339. // 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" }
  340. // 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" }
  341. // 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" }
  342. // CHECK:STDOUT: attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  343. // CHECK:STDOUT: attributes #4 = { nounwind }
  344. // CHECK:STDOUT: attributes #5 = { alwaysinline nounwind }
  345. // CHECK:STDOUT: attributes #6 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  346. // CHECK:STDOUT:
  347. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  348. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  349. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  350. // CHECK:STDOUT:
  351. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  352. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  353. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  354. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  355. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  356. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  357. // CHECK:STDOUT: !6 = !DIFile(filename: "import_struct.carbon", directory: "")
  358. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  359. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  360. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  361. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  362. // CHECK:STDOUT: !11 = !{!12, !12, i64 0}
  363. // CHECK:STDOUT: !12 = !{!"p1 _ZTS1X", !13, i64 0}
  364. // CHECK:STDOUT: !13 = !{!"any pointer", !9, i64 0}
  365. // CHECK:STDOUT: !14 = !{i64 0, i64 4, !7, i64 4, i64 4, !7, i64 8, i64 4, !7}
  366. // CHECK:STDOUT: !15 = distinct !DISubprogram(name: "Test", linkageName: "_CTest.Main", scope: null, file: !6, line: 6, type: !16, spFlags: DISPFlagDefinition, unit: !5)
  367. // CHECK:STDOUT: !16 = !DISubroutineType(types: !17)
  368. // CHECK:STDOUT: !17 = !{null}
  369. // CHECK:STDOUT: !18 = !DILocation(line: 7, column: 3, scope: !15)
  370. // CHECK:STDOUT: !19 = !DILocation(line: 8, column: 3, scope: !15)
  371. // CHECK:STDOUT: !20 = !DILocation(line: 9, column: 3, scope: !15)
  372. // CHECK:STDOUT: !21 = !DILocation(line: 10, column: 3, scope: !15)
  373. // CHECK:STDOUT: !22 = !DILocation(line: 11, column: 3, scope: !15)
  374. // CHECK:STDOUT: !23 = !DILocation(line: 6, column: 1, scope: !15)
  375. // CHECK:STDOUT: !24 = distinct !DISubprogram(name: "Op", linkageName: "_COp:thunk.X.Cpp", scope: null, file: !25, line: 2, type: !26, spFlags: DISPFlagDefinition, unit: !5)
  376. // CHECK:STDOUT: !25 = !DIFile(filename: "./struct.h", directory: "")
  377. // CHECK:STDOUT: !26 = !DISubroutineType(types: !27)
  378. // CHECK:STDOUT: !27 = !{!28}
  379. // CHECK:STDOUT: !28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  380. // CHECK:STDOUT: !29 = !DILocation(line: 2, column: 8, scope: !24)
  381. // CHECK:STDOUT: !30 = distinct !DISubprogram(name: "Op", linkageName: "_COp.9b0a46309e124f8a:DefaultOrUnformed.Core.64f6b96556a8f2d4", scope: null, file: !31, line: 9, type: !26, spFlags: DISPFlagDefinition, unit: !5)
  382. // CHECK:STDOUT: !31 = !DIFile(filename: "min_prelude/parts/default.carbon", directory: "")
  383. // CHECK:STDOUT: !32 = !DILocation(line: 9, column: 28, scope: !30)
  384. // CHECK:STDOUT: !33 = !DILocation(line: 9, column: 21, scope: !30)
  385. // CHECK:STDOUT: ; ModuleID = 'import_class_with_nontrivial_copy.carbon'
  386. // CHECK:STDOUT: source_filename = "import_class_with_nontrivial_copy.carbon"
  387. // 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"
  388. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  389. // CHECK:STDOUT:
  390. // CHECK:STDOUT: %class.Y = type { i32, i32, i32 }
  391. // CHECK:STDOUT:
  392. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  393. // CHECK:STDOUT: define dso_local void @_Z11pass_struct1Y.carbon_thunk(ptr noundef %0) #0 {
  394. // CHECK:STDOUT: entry:
  395. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  396. // CHECK:STDOUT: %agg.tmp = alloca %class.Y, align 4
  397. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !11
  398. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !11
  399. // CHECK:STDOUT: call void @_ZN1YC1ERKS_(ptr noundef nonnull align 4 dereferenceable(12) %agg.tmp, ptr noundef nonnull align 4 dereferenceable(12) %1)
  400. // CHECK:STDOUT: call void @_Z11pass_struct1Y(ptr noundef dead_on_return %agg.tmp)
  401. // CHECK:STDOUT: ret void
  402. // CHECK:STDOUT: }
  403. // CHECK:STDOUT:
  404. // CHECK:STDOUT: declare void @_Z11pass_struct1Y(ptr noundef dead_on_return) #1
  405. // CHECK:STDOUT:
  406. // CHECK:STDOUT: declare void @_ZN1YC1ERKS_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #1
  407. // CHECK:STDOUT:
  408. // CHECK:STDOUT: ; Function Attrs: nounwind
  409. // CHECK:STDOUT: define void @_CPassRefExpr.Main() #2 !dbg !14 {
  410. // CHECK:STDOUT: entry:
  411. // CHECK:STDOUT: %y.var = alloca [12 x i8], align 1, !dbg !17
  412. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %y.var), !dbg !17
  413. // CHECK:STDOUT: %.loc8_4.a = getelementptr inbounds nuw [12 x i8], ptr %y.var, i32 0, i32 0, !dbg !18
  414. // CHECK:STDOUT: store i32 1, ptr %.loc8_4.a, align 4, !dbg !18
  415. // CHECK:STDOUT: %.loc9_4.b = getelementptr inbounds nuw [12 x i8], ptr %y.var, i32 0, i32 4, !dbg !19
  416. // CHECK:STDOUT: store i32 2, ptr %.loc9_4.b, align 4, !dbg !19
  417. // CHECK:STDOUT: %.loc10_4.c = getelementptr inbounds nuw [12 x i8], ptr %y.var, i32 0, i32 8, !dbg !20
  418. // CHECK:STDOUT: store i32 3, ptr %.loc10_4.c, align 4, !dbg !20
  419. // CHECK:STDOUT: call void @_Z11pass_struct1Y.carbon_thunk(ptr %y.var), !dbg !21
  420. // CHECK:STDOUT: ret void, !dbg !22
  421. // CHECK:STDOUT: }
  422. // CHECK:STDOUT:
  423. // CHECK:STDOUT: declare void @_CMake.Main(ptr sret([12 x i8]))
  424. // CHECK:STDOUT:
  425. // CHECK:STDOUT: ; Function Attrs: nounwind
  426. // CHECK:STDOUT: define void @_CPassInitExpr.Main() #2 !dbg !23 {
  427. // CHECK:STDOUT: entry:
  428. // CHECK:STDOUT: %.loc17_24.1.temp = alloca [12 x i8], align 1, !dbg !24
  429. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc17_24.1.temp), !dbg !24
  430. // CHECK:STDOUT: call void @_CMake.Main(ptr %.loc17_24.1.temp), !dbg !24
  431. // CHECK:STDOUT: call void @_Z11pass_struct1Y.carbon_thunk(ptr %.loc17_24.1.temp), !dbg !25
  432. // CHECK:STDOUT: ret void, !dbg !26
  433. // CHECK:STDOUT: }
  434. // CHECK:STDOUT:
  435. // CHECK:STDOUT: ; Function Attrs: nounwind
  436. // CHECK:STDOUT: define void @_CPassValueExpr.Main(ptr %y) #2 !dbg !27 {
  437. // CHECK:STDOUT: entry:
  438. // CHECK:STDOUT: call void @_Z11pass_struct1Y.carbon_thunk(ptr %y), !dbg !33
  439. // CHECK:STDOUT: ret void, !dbg !34
  440. // CHECK:STDOUT: }
  441. // CHECK:STDOUT:
  442. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  443. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #3
  444. // CHECK:STDOUT:
  445. // CHECK:STDOUT: ; uselistorder directives
  446. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 1, 0 }
  447. // CHECK:STDOUT:
  448. // 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" }
  449. // 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" }
  450. // CHECK:STDOUT: attributes #2 = { nounwind }
  451. // CHECK:STDOUT: attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  452. // CHECK:STDOUT:
  453. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4}
  454. // CHECK:STDOUT: !llvm.dbg.cu = !{!5}
  455. // CHECK:STDOUT: !llvm.errno.tbaa = !{!7}
  456. // CHECK:STDOUT:
  457. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  458. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  459. // CHECK:STDOUT: !2 = !{i32 8, !"PIC Level", i32 2}
  460. // CHECK:STDOUT: !3 = !{i32 7, !"PIE Level", i32 2}
  461. // CHECK:STDOUT: !4 = !{i32 7, !"uwtable", i32 2}
  462. // CHECK:STDOUT: !5 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !6, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  463. // CHECK:STDOUT: !6 = !DIFile(filename: "import_class_with_nontrivial_copy.carbon", directory: "")
  464. // CHECK:STDOUT: !7 = !{!8, !8, i64 0}
  465. // CHECK:STDOUT: !8 = !{!"int", !9, i64 0}
  466. // CHECK:STDOUT: !9 = !{!"omnipotent char", !10, i64 0}
  467. // CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
  468. // CHECK:STDOUT: !11 = !{!12, !12, i64 0}
  469. // CHECK:STDOUT: !12 = !{!"p1 _ZTS1Y", !13, i64 0}
  470. // CHECK:STDOUT: !13 = !{!"any pointer", !9, i64 0}
  471. // CHECK:STDOUT: !14 = distinct !DISubprogram(name: "PassRefExpr", linkageName: "_CPassRefExpr.Main", scope: null, file: !6, line: 6, type: !15, spFlags: DISPFlagDefinition, unit: !5)
  472. // CHECK:STDOUT: !15 = !DISubroutineType(types: !16)
  473. // CHECK:STDOUT: !16 = !{null}
  474. // CHECK:STDOUT: !17 = !DILocation(line: 7, column: 3, scope: !14)
  475. // CHECK:STDOUT: !18 = !DILocation(line: 8, column: 3, scope: !14)
  476. // CHECK:STDOUT: !19 = !DILocation(line: 9, column: 3, scope: !14)
  477. // CHECK:STDOUT: !20 = !DILocation(line: 10, column: 3, scope: !14)
  478. // CHECK:STDOUT: !21 = !DILocation(line: 11, column: 3, scope: !14)
  479. // CHECK:STDOUT: !22 = !DILocation(line: 6, column: 1, scope: !14)
  480. // CHECK:STDOUT: !23 = distinct !DISubprogram(name: "PassInitExpr", linkageName: "_CPassInitExpr.Main", scope: null, file: !6, line: 16, type: !15, spFlags: DISPFlagDefinition, unit: !5)
  481. // CHECK:STDOUT: !24 = !DILocation(line: 17, column: 19, scope: !23)
  482. // CHECK:STDOUT: !25 = !DILocation(line: 17, column: 3, scope: !23)
  483. // CHECK:STDOUT: !26 = !DILocation(line: 16, column: 1, scope: !23)
  484. // CHECK:STDOUT: !27 = distinct !DISubprogram(name: "PassValueExpr", linkageName: "_CPassValueExpr.Main", scope: null, file: !6, line: 20, type: !28, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !31)
  485. // CHECK:STDOUT: !28 = !DISubroutineType(types: !29)
  486. // CHECK:STDOUT: !29 = !{null, !30}
  487. // CHECK:STDOUT: !30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  488. // CHECK:STDOUT: !31 = !{!32}
  489. // CHECK:STDOUT: !32 = !DILocalVariable(arg: 1, scope: !27, type: !30)
  490. // CHECK:STDOUT: !33 = !DILocation(line: 21, column: 3, scope: !27)
  491. // CHECK:STDOUT: !34 = !DILocation(line: 20, column: 1, scope: !27)