pointer.carbon 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/bool.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/builtins/pointer.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/builtins/pointer.carbon
  12. fn MakeUnformed(t: type) -> type = "maybe_unformed.make_type";
  13. fn MakeNull(T:! type) -> MakeUnformed(T*) = "pointer.make_null";
  14. fn IsNull[T:! type](p: MakeUnformed(T*)) -> bool = "pointer.is_null";
  15. class C {}
  16. fn Null() -> MakeUnformed(C*) {
  17. return MakeNull(C);
  18. }
  19. fn Check(p: MakeUnformed(C*)) -> bool {
  20. return IsNull(p);
  21. }
  22. // CHECK:STDOUT: ; ModuleID = 'pointer.carbon'
  23. // CHECK:STDOUT: source_filename = "pointer.carbon"
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: ; Function Attrs: nounwind
  26. // CHECK:STDOUT: define ptr @_CNull.Main() #0 !dbg !4 {
  27. // CHECK:STDOUT: entry:
  28. // CHECK:STDOUT: ret ptr null, !dbg !7
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: ; Function Attrs: nounwind
  32. // CHECK:STDOUT: define i1 @_CCheck.Main(ptr %p) #0 !dbg !8 {
  33. // CHECK:STDOUT: entry:
  34. // CHECK:STDOUT: %IsNull.call = icmp eq ptr %p, null, !dbg !9
  35. // CHECK:STDOUT: ret i1 %IsNull.call, !dbg !10
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: attributes #0 = { nounwind }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  41. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  44. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  45. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  46. // CHECK:STDOUT: !3 = !DIFile(filename: "pointer.carbon", directory: "")
  47. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Null", linkageName: "_CNull.Main", scope: null, file: !3, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  48. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  49. // CHECK:STDOUT: !6 = !{}
  50. // CHECK:STDOUT: !7 = !DILocation(line: 20, column: 3, scope: !4)
  51. // CHECK:STDOUT: !8 = distinct !DISubprogram(name: "Check", linkageName: "_CCheck.Main", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  52. // CHECK:STDOUT: !9 = !DILocation(line: 24, column: 10, scope: !8)
  53. // CHECK:STDOUT: !10 = !DILocation(line: 24, column: 3, scope: !8)