parameters.carbon 26 KB

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