string.carbon 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // This is an integration test for the Core.String in the prelude, so use the
  6. // real prelude.
  7. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
  8. // EXTRA-ARGS: --target=x86_64-linux-gnu
  9. //
  10. // AUTOUPDATE
  11. // TIP: To test this file alone, run:
  12. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/primitives/string.carbon
  13. // TIP: To dump output, run:
  14. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/primitives/string.carbon
  15. fn F(s: str);
  16. fn G() {
  17. F("Hello");
  18. }
  19. fn H() {
  20. // This can reuse the same string literal object.
  21. let v: str = "Hello";
  22. F(v);
  23. }
  24. fn I() {
  25. // This can't.
  26. let v: str = "World";
  27. F(v);
  28. }
  29. // CHECK:STDOUT: ; ModuleID = 'string.carbon'
  30. // CHECK:STDOUT: source_filename = "string.carbon"
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: @0 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1
  33. // CHECK:STDOUT: @1 = private unnamed_addr constant [6 x i8] c"World\00", align 1
  34. // CHECK:STDOUT: @String.val.13d.String.val = internal constant { ptr, i64 } { ptr @0, i64 5 }
  35. // CHECK:STDOUT: @String.val.afc.String.val = internal constant { ptr, i64 } { ptr @1, i64 5 }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: declare void @_CF.Main(ptr)
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: define void @_CG.Main() !dbg !4 {
  40. // CHECK:STDOUT: entry:
  41. // CHECK:STDOUT: call void @_CF.Main(ptr @String.val.13d.String.val), !dbg !7
  42. // CHECK:STDOUT: ret void, !dbg !8
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: define void @_CH.Main() !dbg !9 {
  46. // CHECK:STDOUT: entry:
  47. // CHECK:STDOUT: call void @_CF.Main(ptr @String.val.13d.String.val), !dbg !10
  48. // CHECK:STDOUT: ret void, !dbg !11
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: define void @_CI.Main() !dbg !12 {
  52. // CHECK:STDOUT: entry:
  53. // CHECK:STDOUT: call void @_CF.Main(ptr @String.val.afc.String.val), !dbg !13
  54. // CHECK:STDOUT: ret void, !dbg !14
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  58. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  61. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  62. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  63. // CHECK:STDOUT: !3 = !DIFile(filename: "string.carbon", directory: "")
  64. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  65. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  66. // CHECK:STDOUT: !6 = !{}
  67. // CHECK:STDOUT: !7 = !DILocation(line: 19, column: 3, scope: !4)
  68. // CHECK:STDOUT: !8 = !DILocation(line: 18, column: 1, scope: !4)
  69. // CHECK:STDOUT: !9 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main", scope: null, file: !3, line: 22, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  70. // CHECK:STDOUT: !10 = !DILocation(line: 25, column: 3, scope: !9)
  71. // CHECK:STDOUT: !11 = !DILocation(line: 22, column: 1, scope: !9)
  72. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "I", linkageName: "_CI.Main", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  73. // CHECK:STDOUT: !13 = !DILocation(line: 31, column: 3, scope: !12)
  74. // CHECK:STDOUT: !14 = !DILocation(line: 28, column: 1, scope: !12)