string_indexing.carbon 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/operators/string_indexing.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/operators/string_indexing.carbon
  12. fn F() -> char {
  13. let c: char = "Test"[0];
  14. return c;
  15. }
  16. fn F2(index: i64) -> char {
  17. let c: char = "Test"[index];
  18. return c;
  19. }
  20. // CHECK:STDOUT: ; ModuleID = 'string_indexing.carbon'
  21. // CHECK:STDOUT: source_filename = "string_indexing.carbon"
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: @0 = private unnamed_addr constant [5 x i8] c"Test\00", align 1
  24. // CHECK:STDOUT: @String.val.String.val = internal constant { ptr, i64 } { ptr @0, i64 4 }
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: ; Function Attrs: nounwind
  27. // CHECK:STDOUT: define i8 @_CF.Main() #0 !dbg !4 {
  28. // CHECK:STDOUT: entry:
  29. // CHECK:STDOUT: ret i8 84, !dbg !8
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: ; Function Attrs: nounwind
  33. // CHECK:STDOUT: define i8 @_CF2.Main(i64 %index) #0 !dbg !9 {
  34. // CHECK:STDOUT: entry:
  35. // CHECK:STDOUT: %str.as.IndexWith.impl.At.call.string.load = load { ptr, i64 }, ptr @String.val.String.val, align 8, !dbg !15
  36. // CHECK:STDOUT: %str.as.IndexWith.impl.At.call.string.ptr = extractvalue { ptr, i64 } %str.as.IndexWith.impl.At.call.string.load, 0, !dbg !15
  37. // CHECK:STDOUT: %str.as.IndexWith.impl.At.call.string.char_ptr = getelementptr inbounds i8, ptr %str.as.IndexWith.impl.At.call.string.ptr, i64 %index, !dbg !15
  38. // CHECK:STDOUT: %str.as.IndexWith.impl.At.call.string.char = load i8, ptr %str.as.IndexWith.impl.At.call.string.char_ptr, align 1, !dbg !15
  39. // CHECK:STDOUT: ret i8 %str.as.IndexWith.impl.At.call.string.char, !dbg !16
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: attributes #0 = { nounwind }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  45. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  48. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  49. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  50. // CHECK:STDOUT: !3 = !DIFile(filename: "string_indexing.carbon", directory: "")
  51. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  52. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  53. // CHECK:STDOUT: !6 = !{!7}
  54. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 8, encoding: DW_ATE_unsigned)
  55. // CHECK:STDOUT: !8 = !DILocation(line: 15, column: 5, scope: !4)
  56. // CHECK:STDOUT: !9 = distinct !DISubprogram(name: "F2", linkageName: "_CF2.Main", scope: null, file: !3, line: 18, type: !10, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !13)
  57. // CHECK:STDOUT: !10 = !DISubroutineType(types: !11)
  58. // CHECK:STDOUT: !11 = !{!7, !12}
  59. // CHECK:STDOUT: !12 = !DIBasicType(name: "int", size: 64, encoding: DW_ATE_signed)
  60. // CHECK:STDOUT: !13 = !{!14}
  61. // CHECK:STDOUT: !14 = !DILocalVariable(arg: 1, scope: !9, type: !12)
  62. // CHECK:STDOUT: !15 = !DILocation(line: 19, column: 19, scope: !9)
  63. // CHECK:STDOUT: !16 = !DILocation(line: 20, column: 5, scope: !9)