copy_value_rep.carbon 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/int.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/let/copy_value_rep.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/let/copy_value_rep.carbon
  12. class X {
  13. var a: i32;
  14. }
  15. fn Run() -> i32 {
  16. var x: X = {.a = 1};
  17. let n: i32 = x.a;
  18. x.a = 2;
  19. // Should return 1, not 2.
  20. return n;
  21. }
  22. // CHECK:STDOUT: ; ModuleID = 'copy_value_rep.carbon'
  23. // CHECK:STDOUT: source_filename = "copy_value_rep.carbon"
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: @X.val.loc18_3 = internal constant { i32 } { i32 1 }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: ; Function Attrs: nounwind
  28. // CHECK:STDOUT: define i32 @main() #0 !dbg !4 {
  29. // CHECK:STDOUT: entry:
  30. // CHECK:STDOUT: %x.var = alloca { i32 }, align 8, !dbg !8
  31. // CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %x.var), !dbg !8
  32. // CHECK:STDOUT: %.loc18_21.3.a = getelementptr inbounds nuw { i32 }, ptr %x.var, i32 0, i32 0, !dbg !9
  33. // CHECK:STDOUT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %x.var, ptr align 4 @X.val.loc18_3, i64 4, i1 false), !dbg !8
  34. // CHECK:STDOUT: %.loc19_17.1.a = getelementptr inbounds nuw { i32 }, ptr %x.var, i32 0, i32 0, !dbg !10
  35. // CHECK:STDOUT: %.loc19_17.2 = load i32, ptr %.loc19_17.1.a, align 4, !dbg !10
  36. // CHECK:STDOUT: %.loc20_4.a = getelementptr inbounds nuw { i32 }, ptr %x.var, i32 0, i32 0, !dbg !11
  37. // CHECK:STDOUT: store i32 2, ptr %.loc20_4.a, align 4, !dbg !11
  38. // CHECK:STDOUT: ret i32 %.loc19_17.2, !dbg !12
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
  42. // CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #1
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
  45. // CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #2
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: attributes #0 = { nounwind }
  48. // CHECK:STDOUT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
  49. // CHECK:STDOUT: attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  52. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  55. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  56. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  57. // CHECK:STDOUT: !3 = !DIFile(filename: "copy_value_rep.carbon", directory: "")
  58. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !3, line: 17, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  59. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  60. // CHECK:STDOUT: !6 = !{!7}
  61. // CHECK:STDOUT: !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  62. // CHECK:STDOUT: !8 = !DILocation(line: 18, column: 3, scope: !4)
  63. // CHECK:STDOUT: !9 = !DILocation(line: 18, column: 14, scope: !4)
  64. // CHECK:STDOUT: !10 = !DILocation(line: 19, column: 16, scope: !4)
  65. // CHECK:STDOUT: !11 = !DILocation(line: 20, column: 3, scope: !4)
  66. // CHECK:STDOUT: !12 = !DILocation(line: 22, column: 3, scope: !4)