fixed.carbon 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/convert.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/check/testdata/interop/cpp/enum/fixed.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/enum/fixed.carbon
  12. // --- enum.h
  13. enum Enum : short { a, b, c };
  14. // --- import_enum.carbon
  15. library "[[@TEST_NAME]]";
  16. import Cpp library "enum.h";
  17. //@dump-sem-ir-begin
  18. fn F() {
  19. let a: Cpp.Enum = Cpp.Enum.a;
  20. let b: Cpp.Enum = Cpp.b;
  21. }
  22. //@dump-sem-ir-end
  23. // CHECK:STDOUT: --- import_enum.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  27. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  28. // CHECK:STDOUT: %Enum: type = class_type @Enum [concrete]
  29. // CHECK:STDOUT: %pattern_type: type = pattern_type %Enum [concrete]
  30. // CHECK:STDOUT: %int_0: %Enum = int_value 0 [concrete]
  31. // CHECK:STDOUT: %int_1: %Enum = int_value 1 [concrete]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  36. // CHECK:STDOUT: .Enum = %Enum.decl
  37. // CHECK:STDOUT: .b = %int_1
  38. // CHECK:STDOUT: import Cpp//...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Enum.decl: type = class_decl @Enum [concrete = constants.%Enum] {} {}
  41. // CHECK:STDOUT: %int_0: %Enum = int_value 0 [concrete = constants.%int_0]
  42. // CHECK:STDOUT: %int_1: %Enum = int_value 1 [concrete = constants.%int_1]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: fn @F() {
  50. // CHECK:STDOUT: !entry:
  51. // CHECK:STDOUT: name_binding_decl {
  52. // CHECK:STDOUT: %a.patt: %pattern_type = value_binding_pattern a [concrete]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Cpp.ref.loc8_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  55. // CHECK:STDOUT: %Enum.ref.loc8_24: type = name_ref Enum, imports.%Enum.decl [concrete = constants.%Enum]
  56. // CHECK:STDOUT: %a.ref: %Enum = name_ref a, imports.%int_0 [concrete = constants.%int_0]
  57. // CHECK:STDOUT: %.loc8: type = splice_block %Enum.ref.loc8_13 [concrete = constants.%Enum] {
  58. // CHECK:STDOUT: %Cpp.ref.loc8_10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  59. // CHECK:STDOUT: %Enum.ref.loc8_13: type = name_ref Enum, imports.%Enum.decl [concrete = constants.%Enum]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %a: %Enum = value_binding a, %a.ref
  62. // CHECK:STDOUT: name_binding_decl {
  63. // CHECK:STDOUT: %b.patt: %pattern_type = value_binding_pattern b [concrete]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %Cpp.ref.loc9_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  66. // CHECK:STDOUT: %b.ref: %Enum = name_ref b, imports.%int_1 [concrete = constants.%int_1]
  67. // CHECK:STDOUT: %.loc9: type = splice_block %Enum.ref.loc9 [concrete = constants.%Enum] {
  68. // CHECK:STDOUT: %Cpp.ref.loc9_10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  69. // CHECK:STDOUT: %Enum.ref.loc9: type = name_ref Enum, imports.%Enum.decl [concrete = constants.%Enum]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %b: %Enum = value_binding b, %b.ref
  72. // CHECK:STDOUT: return
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: