pointer.carbon 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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/full.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/pointer.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/interop/cpp/pointer.carbon
  12. // ============================================================================
  13. // Non-null pointers
  14. // ============================================================================
  15. // --- nonnull.carbon
  16. library "[[@TEST_NAME]]";
  17. import Cpp inline '''
  18. class C {};
  19. auto TakePtr(C* _Nonnull) -> void;
  20. auto ReturnPtr() -> C* _Nonnull;
  21. auto TakePtrWithThunk(C* _Nonnull, int = 0) -> void;
  22. auto ReturnPtrWithThunk(int = 0) -> C* _Nonnull;
  23. ''';
  24. fn PassPtr(p: Cpp.C*) {
  25. Cpp.TakePtr(p);
  26. }
  27. fn ReturnPtr() -> Cpp.C* {
  28. return Cpp.ReturnPtr();
  29. }
  30. fn PassPtrWithThunk(p: Cpp.C*) {
  31. Cpp.TakePtrWithThunk(p);
  32. }
  33. fn ReturnPtrWithThunk() -> Cpp.C* {
  34. return Cpp.ReturnPtrWithThunk();
  35. }
  36. // ============================================================================
  37. // Nullable pointers
  38. // ============================================================================
  39. // --- nullable.carbon
  40. library "[[@TEST_NAME]]";
  41. import Cpp inline '''
  42. class C {};
  43. auto TakePtr(C*) -> void;
  44. auto ReturnPtr() -> C*;
  45. auto TakePtrWithThunk(C*, int = 0) -> void;
  46. auto ReturnPtrWithThunk(int = 0) -> C*;
  47. ''';
  48. fn PassPtr(_: Core.Optional(Cpp.C*)) {
  49. // TODO: Add support for passing an optional here.
  50. // Cpp.TakePtr(p);
  51. }
  52. fn PassNonnullPtr(p: Cpp.C*) {
  53. // TODO: The `value_of_initializer` optimization doesn't get used here, so we
  54. // unnecessarily round-trip this value through memory.
  55. Cpp.TakePtr(p);
  56. }
  57. fn ReturnPtr() -> Core.Optional(Cpp.C*) {
  58. return Cpp.ReturnPtr();
  59. }
  60. fn PassPtrWithThunk(_: Core.Optional(Cpp.C*)) {
  61. // TODO: Add support for passing an optional here.
  62. // Cpp.TakePtrWithThunk(p);
  63. }
  64. fn PassNonnullPtrWithThunk(p: Cpp.C*) {
  65. Cpp.TakePtrWithThunk(p);
  66. }
  67. fn ReturnPtrWithThunk() -> Core.Optional(Cpp.C*) {
  68. return Cpp.ReturnPtrWithThunk();
  69. }
  70. // CHECK:STDOUT: ; ModuleID = 'nonnull.carbon'
  71. // CHECK:STDOUT: source_filename = "nonnull.carbon"
  72. // 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"
  73. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: ; Function Attrs: nounwind
  76. // CHECK:STDOUT: define void @_CPassPtr.Main(ptr %p) #0 !dbg !12 {
  77. // CHECK:STDOUT: entry:
  78. // CHECK:STDOUT: call void @_Z7TakePtrP1C(ptr %p), !dbg !18
  79. // CHECK:STDOUT: ret void, !dbg !19
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: declare void @_Z7TakePtrP1C(ptr)
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: ; Function Attrs: nounwind
  85. // CHECK:STDOUT: define ptr @_CReturnPtr.Main() #0 !dbg !20 {
  86. // CHECK:STDOUT: entry:
  87. // CHECK:STDOUT: %ReturnPtr.call = call ptr @_Z9ReturnPtrv(), !dbg !23
  88. // CHECK:STDOUT: ret ptr %ReturnPtr.call, !dbg !24
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: declare ptr @_Z9ReturnPtrv()
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: ; Function Attrs: nounwind
  94. // CHECK:STDOUT: define void @_CPassPtrWithThunk.Main(ptr %p) #0 !dbg !25 {
  95. // CHECK:STDOUT: entry:
  96. // CHECK:STDOUT: call void @_Z16TakePtrWithThunkP1Ci.carbon_thunk1(ptr %p), !dbg !28
  97. // CHECK:STDOUT: ret void, !dbg !29
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: ; Function Attrs: nounwind
  101. // CHECK:STDOUT: define ptr @_CReturnPtrWithThunk.Main() #0 !dbg !30 {
  102. // CHECK:STDOUT: entry:
  103. // CHECK:STDOUT: %ReturnPtrWithThunk__carbon_thunk.call = call ptr @_Z18ReturnPtrWithThunki.carbon_thunk0(), !dbg !31
  104. // CHECK:STDOUT: ret ptr %ReturnPtrWithThunk__carbon_thunk.call, !dbg !32
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  108. // CHECK:STDOUT: define dso_local void @_Z16TakePtrWithThunkP1Ci.carbon_thunk1(ptr noundef %0) #1 {
  109. // CHECK:STDOUT: entry:
  110. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  111. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !33
  112. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !33
  113. // CHECK:STDOUT: call void @_Z16TakePtrWithThunkP1Ci(ptr noundef %1, i32 noundef 0)
  114. // CHECK:STDOUT: ret void
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: declare void @_Z16TakePtrWithThunkP1Ci(ptr noundef, i32 noundef) #2
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  120. // CHECK:STDOUT: define dso_local noundef ptr @_Z18ReturnPtrWithThunki.carbon_thunk0() #1 {
  121. // CHECK:STDOUT: entry:
  122. // CHECK:STDOUT: %call = call noundef ptr @_Z18ReturnPtrWithThunki(i32 noundef 0)
  123. // CHECK:STDOUT: ret ptr %call
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: declare noundef ptr @_Z18ReturnPtrWithThunki(i32 noundef) #2
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: attributes #0 = { nounwind }
  129. // 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" }
  130. // 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" }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4, !5}
  133. // CHECK:STDOUT: !llvm.dbg.cu = !{!6}
  134. // CHECK:STDOUT: !llvm.errno.tbaa = !{!8}
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  137. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  138. // CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
  139. // CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
  140. // CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
  141. // CHECK:STDOUT: !5 = !{i32 7, !"uwtable", i32 2}
  142. // CHECK:STDOUT: !6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !7, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  143. // CHECK:STDOUT: !7 = !DIFile(filename: "nonnull.carbon", directory: "")
  144. // CHECK:STDOUT: !8 = !{!9, !9, i64 0}
  145. // CHECK:STDOUT: !9 = !{!"int", !10, i64 0}
  146. // CHECK:STDOUT: !10 = !{!"omnipotent char", !11, i64 0}
  147. // CHECK:STDOUT: !11 = !{!"Simple C++ TBAA"}
  148. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "PassPtr", linkageName: "_CPassPtr.Main", scope: null, file: !7, line: 14, type: !13, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !16)
  149. // CHECK:STDOUT: !13 = !DISubroutineType(types: !14)
  150. // CHECK:STDOUT: !14 = !{null, !15}
  151. // CHECK:STDOUT: !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  152. // CHECK:STDOUT: !16 = !{!17}
  153. // CHECK:STDOUT: !17 = !DILocalVariable(arg: 1, scope: !12, type: !15)
  154. // CHECK:STDOUT: !18 = !DILocation(line: 15, column: 3, scope: !12)
  155. // CHECK:STDOUT: !19 = !DILocation(line: 14, column: 1, scope: !12)
  156. // CHECK:STDOUT: !20 = distinct !DISubprogram(name: "ReturnPtr", linkageName: "_CReturnPtr.Main", scope: null, file: !7, line: 18, type: !21, spFlags: DISPFlagDefinition, unit: !6)
  157. // CHECK:STDOUT: !21 = !DISubroutineType(types: !22)
  158. // CHECK:STDOUT: !22 = !{!15}
  159. // CHECK:STDOUT: !23 = !DILocation(line: 19, column: 10, scope: !20)
  160. // CHECK:STDOUT: !24 = !DILocation(line: 19, column: 3, scope: !20)
  161. // CHECK:STDOUT: !25 = distinct !DISubprogram(name: "PassPtrWithThunk", linkageName: "_CPassPtrWithThunk.Main", scope: null, file: !7, line: 22, type: !13, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !26)
  162. // CHECK:STDOUT: !26 = !{!27}
  163. // CHECK:STDOUT: !27 = !DILocalVariable(arg: 1, scope: !25, type: !15)
  164. // CHECK:STDOUT: !28 = !DILocation(line: 23, column: 3, scope: !25)
  165. // CHECK:STDOUT: !29 = !DILocation(line: 22, column: 1, scope: !25)
  166. // CHECK:STDOUT: !30 = distinct !DISubprogram(name: "ReturnPtrWithThunk", linkageName: "_CReturnPtrWithThunk.Main", scope: null, file: !7, line: 26, type: !21, spFlags: DISPFlagDefinition, unit: !6)
  167. // CHECK:STDOUT: !31 = !DILocation(line: 27, column: 10, scope: !30)
  168. // CHECK:STDOUT: !32 = !DILocation(line: 27, column: 3, scope: !30)
  169. // CHECK:STDOUT: !33 = !{!34, !34, i64 0}
  170. // CHECK:STDOUT: !34 = !{!"p1 _ZTS1C", !35, i64 0}
  171. // CHECK:STDOUT: !35 = !{!"any pointer", !10, i64 0}
  172. // CHECK:STDOUT: ; ModuleID = 'nullable.carbon'
  173. // CHECK:STDOUT: source_filename = "nullable.carbon"
  174. // 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"
  175. // CHECK:STDOUT: target triple = "x86_64-unknown-linux-gnu"
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: ; Function Attrs: nounwind
  178. // CHECK:STDOUT: define void @_CPassPtr.Main(ptr %_) #0 !dbg !12 {
  179. // CHECK:STDOUT: entry:
  180. // CHECK:STDOUT: ret void, !dbg !18
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: ; Function Attrs: nounwind
  184. // CHECK:STDOUT: define void @_CPassNonnullPtr.Main(ptr %p) #0 !dbg !19 {
  185. // CHECK:STDOUT: entry:
  186. // CHECK:STDOUT: %.loc22_15.2.temp = alloca ptr, align 8, !dbg !22
  187. // CHECK:STDOUT: %U.binding.as_type.as.ImplicitAs.impl.Convert.call = call ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5b1b7c6bb83e5c41"(ptr %p), !dbg !22
  188. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc22_15.2.temp), !dbg !22
  189. // CHECK:STDOUT: store ptr %U.binding.as_type.as.ImplicitAs.impl.Convert.call, ptr %.loc22_15.2.temp, align 8, !dbg !22
  190. // CHECK:STDOUT: %.loc22_15.4 = load ptr, ptr %.loc22_15.2.temp, align 8, !dbg !22
  191. // CHECK:STDOUT: call void @_Z7TakePtrP1C(ptr %.loc22_15.4), !dbg !23
  192. // CHECK:STDOUT: ret void, !dbg !24
  193. // CHECK:STDOUT: }
  194. // CHECK:STDOUT:
  195. // CHECK:STDOUT: declare void @_Z7TakePtrP1C(ptr)
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: ; Function Attrs: nounwind
  198. // CHECK:STDOUT: define ptr @_CReturnPtr.Main() #0 !dbg !25 {
  199. // CHECK:STDOUT: entry:
  200. // CHECK:STDOUT: %ReturnPtr.call = call ptr @_Z9ReturnPtrv(), !dbg !28
  201. // CHECK:STDOUT: ret ptr %ReturnPtr.call, !dbg !29
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: declare ptr @_Z9ReturnPtrv()
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: ; Function Attrs: nounwind
  207. // CHECK:STDOUT: define void @_CPassPtrWithThunk.Main(ptr %_) #0 !dbg !30 {
  208. // CHECK:STDOUT: entry:
  209. // CHECK:STDOUT: ret void, !dbg !33
  210. // CHECK:STDOUT: }
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: ; Function Attrs: nounwind
  213. // CHECK:STDOUT: define void @_CPassNonnullPtrWithThunk.Main(ptr %p) #0 !dbg !34 {
  214. // CHECK:STDOUT: entry:
  215. // CHECK:STDOUT: %.loc35_24.2.temp = alloca ptr, align 8, !dbg !37
  216. // CHECK:STDOUT: %U.binding.as_type.as.ImplicitAs.impl.Convert.call = call ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5b1b7c6bb83e5c41"(ptr %p), !dbg !37
  217. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %.loc35_24.2.temp), !dbg !37
  218. // CHECK:STDOUT: store ptr %U.binding.as_type.as.ImplicitAs.impl.Convert.call, ptr %.loc35_24.2.temp, align 8, !dbg !37
  219. // CHECK:STDOUT: %.loc35_24.4 = load ptr, ptr %.loc35_24.2.temp, align 8, !dbg !37
  220. // CHECK:STDOUT: call void @_Z16TakePtrWithThunkP1Ci.carbon_thunk1(ptr %.loc35_24.4), !dbg !38
  221. // CHECK:STDOUT: ret void, !dbg !39
  222. // CHECK:STDOUT: }
  223. // CHECK:STDOUT:
  224. // CHECK:STDOUT: ; Function Attrs: nounwind
  225. // CHECK:STDOUT: define ptr @_CReturnPtrWithThunk.Main() #0 !dbg !40 {
  226. // CHECK:STDOUT: entry:
  227. // CHECK:STDOUT: %ReturnPtrWithThunk__carbon_thunk.call = call ptr @_Z18ReturnPtrWithThunki.carbon_thunk0(), !dbg !41
  228. // CHECK:STDOUT: ret ptr %ReturnPtrWithThunk__carbon_thunk.call, !dbg !42
  229. // CHECK:STDOUT: }
  230. // CHECK:STDOUT:
  231. // CHECK:STDOUT: ; Function Attrs: nounwind
  232. // CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5b1b7c6bb83e5c41"(ptr %self) #0 !dbg !43 {
  233. // CHECK:STDOUT: %1 = call ptr @"_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.ea71e3f17b6b4efb"(ptr %self), !dbg !49
  234. // CHECK:STDOUT: ret ptr %1, !dbg !50
  235. // CHECK:STDOUT: }
  236. // CHECK:STDOUT:
  237. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  238. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  239. // CHECK:STDOUT:
  240. // CHECK:STDOUT: ; Function Attrs: nounwind
  241. // CHECK:STDOUT: define linkonce_odr ptr @"_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.ea71e3f17b6b4efb"(ptr %self) #0 !dbg !51 {
  242. // CHECK:STDOUT: %1 = call ptr @_CSome.Optional.Core.ea71e3f17b6b4efb(ptr %self), !dbg !54
  243. // CHECK:STDOUT: ret ptr %1, !dbg !55
  244. // CHECK:STDOUT: }
  245. // CHECK:STDOUT:
  246. // CHECK:STDOUT: ; Function Attrs: nounwind
  247. // CHECK:STDOUT: define linkonce_odr ptr @_CSome.Optional.Core.ea71e3f17b6b4efb(ptr %value) #0 !dbg !56 {
  248. // CHECK:STDOUT: %1 = call ptr @"_CSome.e8f8f92d3d08d149:OptionalStorage.Core.f53db17714b9f655"(ptr %value), !dbg !59
  249. // CHECK:STDOUT: ret ptr %1, !dbg !60
  250. // CHECK:STDOUT: }
  251. // CHECK:STDOUT:
  252. // CHECK:STDOUT: ; Function Attrs: nounwind
  253. // CHECK:STDOUT: define linkonce_odr ptr @"_CSome.e8f8f92d3d08d149:OptionalStorage.Core.f53db17714b9f655"(ptr %self) #0 !dbg !61 {
  254. // CHECK:STDOUT: %1 = alloca ptr, align 8, !dbg !64
  255. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %1), !dbg !64
  256. // CHECK:STDOUT: store ptr %self, ptr %1, align 8, !dbg !65
  257. // CHECK:STDOUT: %2 = load ptr, ptr %1, align 8, !dbg !66
  258. // CHECK:STDOUT: ret ptr %2, !dbg !67
  259. // CHECK:STDOUT: }
  260. // CHECK:STDOUT:
  261. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  262. // CHECK:STDOUT: define dso_local void @_Z16TakePtrWithThunkP1Ci.carbon_thunk1(ptr noundef %0) #2 {
  263. // CHECK:STDOUT: entry:
  264. // CHECK:STDOUT: %.addr = alloca ptr, align 8
  265. // CHECK:STDOUT: store ptr %0, ptr %.addr, align 8, !tbaa !68
  266. // CHECK:STDOUT: %1 = load ptr, ptr %.addr, align 8, !tbaa !68
  267. // CHECK:STDOUT: call void @_Z16TakePtrWithThunkP1Ci(ptr noundef %1, i32 noundef 0)
  268. // CHECK:STDOUT: ret void
  269. // CHECK:STDOUT: }
  270. // CHECK:STDOUT:
  271. // CHECK:STDOUT: declare void @_Z16TakePtrWithThunkP1Ci(ptr noundef, i32 noundef) #3
  272. // CHECK:STDOUT:
  273. // CHECK:STDOUT: ; Function Attrs: alwaysinline mustprogress uwtable
  274. // CHECK:STDOUT: define dso_local noundef ptr @_Z18ReturnPtrWithThunki.carbon_thunk0() #2 {
  275. // CHECK:STDOUT: entry:
  276. // CHECK:STDOUT: %call = call noundef ptr @_Z18ReturnPtrWithThunki(i32 noundef 0)
  277. // CHECK:STDOUT: ret ptr %call
  278. // CHECK:STDOUT: }
  279. // CHECK:STDOUT:
  280. // CHECK:STDOUT: declare noundef ptr @_Z18ReturnPtrWithThunki(i32 noundef) #3
  281. // CHECK:STDOUT:
  282. // CHECK:STDOUT: ; uselistorder directives
  283. // CHECK:STDOUT: uselistorder ptr @"_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5b1b7c6bb83e5c41", { 1, 0 }
  284. // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 0, 2, 1 }
  285. // CHECK:STDOUT:
  286. // CHECK:STDOUT: attributes #0 = { nounwind }
  287. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  288. // CHECK:STDOUT: attributes #2 = { 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" }
  289. // CHECK:STDOUT: attributes #3 = { "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" }
  290. // CHECK:STDOUT:
  291. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1, !2, !3, !4, !5}
  292. // CHECK:STDOUT: !llvm.dbg.cu = !{!6}
  293. // CHECK:STDOUT: !llvm.errno.tbaa = !{!8}
  294. // CHECK:STDOUT:
  295. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  296. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  297. // CHECK:STDOUT: !2 = !{i32 1, !"wchar_size", i32 4}
  298. // CHECK:STDOUT: !3 = !{i32 8, !"PIC Level", i32 0}
  299. // CHECK:STDOUT: !4 = !{i32 7, !"PIE Level", i32 2}
  300. // CHECK:STDOUT: !5 = !{i32 7, !"uwtable", i32 2}
  301. // CHECK:STDOUT: !6 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !7, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  302. // CHECK:STDOUT: !7 = !DIFile(filename: "nullable.carbon", directory: "")
  303. // CHECK:STDOUT: !8 = !{!9, !9, i64 0}
  304. // CHECK:STDOUT: !9 = !{!"int", !10, i64 0}
  305. // CHECK:STDOUT: !10 = !{!"omnipotent char", !11, i64 0}
  306. // CHECK:STDOUT: !11 = !{!"Simple C++ TBAA"}
  307. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "PassPtr", linkageName: "_CPassPtr.Main", scope: null, file: !7, line: 14, type: !13, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !16)
  308. // CHECK:STDOUT: !13 = !DISubroutineType(types: !14)
  309. // CHECK:STDOUT: !14 = !{null, !15}
  310. // CHECK:STDOUT: !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 8)
  311. // CHECK:STDOUT: !16 = !{!17}
  312. // CHECK:STDOUT: !17 = !DILocalVariable(arg: 1, scope: !12, type: !15)
  313. // CHECK:STDOUT: !18 = !DILocation(line: 14, column: 1, scope: !12)
  314. // CHECK:STDOUT: !19 = distinct !DISubprogram(name: "PassNonnullPtr", linkageName: "_CPassNonnullPtr.Main", scope: null, file: !7, line: 19, type: !13, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !20)
  315. // CHECK:STDOUT: !20 = !{!21}
  316. // CHECK:STDOUT: !21 = !DILocalVariable(arg: 1, scope: !19, type: !15)
  317. // CHECK:STDOUT: !22 = !DILocation(line: 22, column: 15, scope: !19)
  318. // CHECK:STDOUT: !23 = !DILocation(line: 22, column: 3, scope: !19)
  319. // CHECK:STDOUT: !24 = !DILocation(line: 19, column: 1, scope: !19)
  320. // CHECK:STDOUT: !25 = distinct !DISubprogram(name: "ReturnPtr", linkageName: "_CReturnPtr.Main", scope: null, file: !7, line: 25, type: !26, spFlags: DISPFlagDefinition, unit: !6)
  321. // CHECK:STDOUT: !26 = !DISubroutineType(types: !27)
  322. // CHECK:STDOUT: !27 = !{!15}
  323. // CHECK:STDOUT: !28 = !DILocation(line: 26, column: 10, scope: !25)
  324. // CHECK:STDOUT: !29 = !DILocation(line: 26, column: 3, scope: !25)
  325. // CHECK:STDOUT: !30 = distinct !DISubprogram(name: "PassPtrWithThunk", linkageName: "_CPassPtrWithThunk.Main", scope: null, file: !7, line: 29, type: !13, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !31)
  326. // CHECK:STDOUT: !31 = !{!32}
  327. // CHECK:STDOUT: !32 = !DILocalVariable(arg: 1, scope: !30, type: !15)
  328. // CHECK:STDOUT: !33 = !DILocation(line: 29, column: 1, scope: !30)
  329. // CHECK:STDOUT: !34 = distinct !DISubprogram(name: "PassNonnullPtrWithThunk", linkageName: "_CPassNonnullPtrWithThunk.Main", scope: null, file: !7, line: 34, type: !13, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !35)
  330. // CHECK:STDOUT: !35 = !{!36}
  331. // CHECK:STDOUT: !36 = !DILocalVariable(arg: 1, scope: !34, type: !15)
  332. // CHECK:STDOUT: !37 = !DILocation(line: 35, column: 24, scope: !34)
  333. // CHECK:STDOUT: !38 = !DILocation(line: 35, column: 3, scope: !34)
  334. // CHECK:STDOUT: !39 = !DILocation(line: 34, column: 1, scope: !34)
  335. // CHECK:STDOUT: !40 = distinct !DISubprogram(name: "ReturnPtrWithThunk", linkageName: "_CReturnPtrWithThunk.Main", scope: null, file: !7, line: 38, type: !26, spFlags: DISPFlagDefinition, unit: !6)
  336. // CHECK:STDOUT: !41 = !DILocation(line: 39, column: 10, scope: !40)
  337. // CHECK:STDOUT: !42 = !DILocation(line: 39, column: 3, scope: !40)
  338. // CHECK:STDOUT: !43 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.e5cf8fcbb4feaae2:ImplicitAs.0f95c9e18c91e00a.Core.5b1b7c6bb83e5c41", scope: null, file: !44, line: 93, type: !45, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !47)
  339. // CHECK:STDOUT: !44 = !DIFile(filename: "{{.*}}/prelude/types/optional.carbon", directory: "")
  340. // CHECK:STDOUT: !45 = !DISubroutineType(types: !46)
  341. // CHECK:STDOUT: !46 = !{!15, !15}
  342. // CHECK:STDOUT: !47 = !{!48}
  343. // CHECK:STDOUT: !48 = !DILocalVariable(arg: 1, scope: !43, type: !15)
  344. // CHECK:STDOUT: !49 = !DILocation(line: 94, column: 12, scope: !43)
  345. // CHECK:STDOUT: !50 = !DILocation(line: 94, column: 5, scope: !43)
  346. // CHECK:STDOUT: !51 = distinct !DISubprogram(name: "Convert", linkageName: "_CConvert.90961d7b1ce4f089:OptionalAs.0e326e799dad0c64.Core.ea71e3f17b6b4efb", scope: null, file: !44, line: 68, type: !45, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !52)
  347. // CHECK:STDOUT: !52 = !{!53}
  348. // CHECK:STDOUT: !53 = !DILocalVariable(arg: 1, scope: !51, type: !15)
  349. // CHECK:STDOUT: !54 = !DILocation(line: 69, column: 12, scope: !51)
  350. // CHECK:STDOUT: !55 = !DILocation(line: 69, column: 5, scope: !51)
  351. // CHECK:STDOUT: !56 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.Optional.Core.ea71e3f17b6b4efb", scope: null, file: !44, line: 29, type: !45, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !57)
  352. // CHECK:STDOUT: !57 = !{!58}
  353. // CHECK:STDOUT: !58 = !DILocalVariable(arg: 1, scope: !56, type: !15)
  354. // CHECK:STDOUT: !59 = !DILocation(line: 30, column: 12, scope: !56)
  355. // CHECK:STDOUT: !60 = !DILocation(line: 30, column: 5, scope: !56)
  356. // CHECK:STDOUT: !61 = distinct !DISubprogram(name: "Some", linkageName: "_CSome.e8f8f92d3d08d149:OptionalStorage.Core.f53db17714b9f655", scope: null, file: !44, line: 138, type: !45, spFlags: DISPFlagDefinition, unit: !6, retainedNodes: !62)
  357. // CHECK:STDOUT: !62 = !{!63}
  358. // CHECK:STDOUT: !63 = !DILocalVariable(arg: 1, scope: !61, type: !15)
  359. // CHECK:STDOUT: !64 = !DILocation(line: 139, column: 14, scope: !61)
  360. // CHECK:STDOUT: !65 = !DILocation(line: 140, column: 5, scope: !61)
  361. // CHECK:STDOUT: !66 = !DILocation(line: 139, column: 18, scope: !61)
  362. // CHECK:STDOUT: !67 = !DILocation(line: 141, column: 5, scope: !61)
  363. // CHECK:STDOUT: !68 = !{!69, !69, i64 0}
  364. // CHECK:STDOUT: !69 = !{!"p1 _ZTS1C", !70, i64 0}
  365. // CHECK:STDOUT: !70 = !{!"any pointer", !10, i64 0}