export_name.carbon 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/alias/no_prelude/export_name.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/alias/no_prelude/export_name.carbon
  10. // ============================================================================
  11. // Setup files
  12. // ============================================================================
  13. // --- base.carbon
  14. library "base";
  15. class C {}
  16. alias D = C;
  17. // --- export.carbon
  18. library "export";
  19. import library "base";
  20. export D;
  21. // --- export_orig.carbon
  22. library "export_orig";
  23. import library "base";
  24. export C;
  25. // ============================================================================
  26. // Test files
  27. // ============================================================================
  28. // --- use_export.carbon
  29. library "use_export";
  30. import library "export";
  31. var d: D = {};
  32. // --- fail_orig_name_not_in_export.carbon
  33. library "fail_orig_name_not_in_export";
  34. import library "export";
  35. // CHECK:STDERR: fail_orig_name_not_in_export.carbon:[[@LINE+3]]:8: ERROR: Name `C` not found.
  36. // CHECK:STDERR: var c: C = {};
  37. // CHECK:STDERR: ^
  38. var c: C = {};
  39. // --- indirect_compat.carbon
  40. library "indirect_compat";
  41. import library "export";
  42. import library "export_orig";
  43. var c: C = {};
  44. var d: D* = &c;
  45. // CHECK:STDOUT: --- base.carbon
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: constants {
  48. // CHECK:STDOUT: %C: type = class_type @C [template]
  49. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: file {
  53. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  54. // CHECK:STDOUT: .C = %C.decl
  55. // CHECK:STDOUT: .D = %D
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  58. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  59. // CHECK:STDOUT: %D: type = bind_alias D, %C.decl [template = constants.%C]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: class @C {
  63. // CHECK:STDOUT: !members:
  64. // CHECK:STDOUT: .Self = constants.%C
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: --- export.carbon
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: constants {
  70. // CHECK:STDOUT: %C: type = class_type @C [template]
  71. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: file {
  75. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  76. // CHECK:STDOUT: .C = %import_ref.1
  77. // CHECK:STDOUT: .D = %D
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+1, unloaded
  80. // CHECK:STDOUT: %import_ref.2: type = import_ref ir1, inst+5, loaded [template = constants.%C]
  81. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+2, unloaded
  82. // CHECK:STDOUT: %D: type = export D, %import_ref.2 [template = constants.%C]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: class @C {
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .Self = file.%import_ref.3
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: --- export_orig.carbon
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: constants {
  93. // CHECK:STDOUT: %C: type = class_type @C [template]
  94. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: file {
  98. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  99. // CHECK:STDOUT: .C = %C
  100. // CHECK:STDOUT: .D = %import_ref.2
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, loaded [template = constants.%C]
  103. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+5, unloaded
  104. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+2, unloaded
  105. // CHECK:STDOUT: %C: type = export C, %import_ref.1 [template = constants.%C]
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: class @C {
  109. // CHECK:STDOUT: !members:
  110. // CHECK:STDOUT: .Self = file.%import_ref.3
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: --- use_export.carbon
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: constants {
  116. // CHECK:STDOUT: %C: type = class_type @C [template]
  117. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  118. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  119. // CHECK:STDOUT: %.3: type = ptr_type %.1 [template]
  120. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: file {
  124. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  125. // CHECK:STDOUT: .D = %import_ref.1
  126. // CHECK:STDOUT: .d = %d
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+7, loaded [template = constants.%C]
  129. // CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+6, unloaded
  130. // CHECK:STDOUT: %D.ref: type = name_ref D, %import_ref.1 [template = constants.%C]
  131. // CHECK:STDOUT: %d.var: ref %C = var d
  132. // CHECK:STDOUT: %d: ref %C = bind_name d, %d.var
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: class @C {
  136. // CHECK:STDOUT: !members:
  137. // CHECK:STDOUT: .Self = file.%import_ref.2
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: fn @__global_init() {
  141. // CHECK:STDOUT: !entry:
  142. // CHECK:STDOUT: %.loc6_13.1: %.1 = struct_literal ()
  143. // CHECK:STDOUT: %.loc6_13.2: init %C = class_init (), file.%d.var [template = constants.%struct]
  144. // CHECK:STDOUT: %.loc6_14: init %C = converted %.loc6_13.1, %.loc6_13.2 [template = constants.%struct]
  145. // CHECK:STDOUT: assign file.%d.var, %.loc6_14
  146. // CHECK:STDOUT: return
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: --- fail_orig_name_not_in_export.carbon
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: constants {
  152. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: file {
  156. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  157. // CHECK:STDOUT: .D = %import_ref
  158. // CHECK:STDOUT: .c = %c
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: %import_ref = import_ref ir1, inst+7, unloaded
  161. // CHECK:STDOUT: %C.ref: <error> = name_ref C, <error> [template = <error>]
  162. // CHECK:STDOUT: %c.var: ref <error> = var c
  163. // CHECK:STDOUT: %c: ref <error> = bind_name c, %c.var
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: fn @__global_init() {
  167. // CHECK:STDOUT: !entry:
  168. // CHECK:STDOUT: %.loc9: %.1 = struct_literal ()
  169. // CHECK:STDOUT: assign file.%c.var, <error>
  170. // CHECK:STDOUT: return
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: --- indirect_compat.carbon
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: constants {
  176. // CHECK:STDOUT: %C: type = class_type @C [template]
  177. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  178. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  179. // CHECK:STDOUT: %.3: type = ptr_type %.1 [template]
  180. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  181. // CHECK:STDOUT: %.4: type = ptr_type %C [template]
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT:
  184. // CHECK:STDOUT: file {
  185. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  186. // CHECK:STDOUT: .D = %import_ref.1
  187. // CHECK:STDOUT: .C = %import_ref.2
  188. // CHECK:STDOUT: .c = %c
  189. // CHECK:STDOUT: .d = %d
  190. // CHECK:STDOUT: }
  191. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+7, loaded [template = constants.%C]
  192. // CHECK:STDOUT: %import_ref.2: type = import_ref ir2, inst+7, loaded [template = constants.%C]
  193. // CHECK:STDOUT: %import_ref.3 = import_ref ir2, inst+6, unloaded
  194. // CHECK:STDOUT: %C.ref: type = name_ref C, %import_ref.2 [template = constants.%C]
  195. // CHECK:STDOUT: %c.var: ref %C = var c
  196. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  197. // CHECK:STDOUT: %D.ref: type = name_ref D, %import_ref.1 [template = constants.%C]
  198. // CHECK:STDOUT: %.loc8: type = ptr_type %C [template = constants.%.4]
  199. // CHECK:STDOUT: %d.var: ref %.4 = var d
  200. // CHECK:STDOUT: %d: ref %.4 = bind_name d, %d.var
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: class @C {
  204. // CHECK:STDOUT: !members:
  205. // CHECK:STDOUT: .Self = file.%import_ref.3
  206. // CHECK:STDOUT: }
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: fn @__global_init() {
  209. // CHECK:STDOUT: !entry:
  210. // CHECK:STDOUT: %.loc7_13.1: %.1 = struct_literal ()
  211. // CHECK:STDOUT: %.loc7_13.2: init %C = class_init (), file.%c.var [template = constants.%struct]
  212. // CHECK:STDOUT: %.loc7_14: init %C = converted %.loc7_13.1, %.loc7_13.2 [template = constants.%struct]
  213. // CHECK:STDOUT: assign file.%c.var, %.loc7_14
  214. // CHECK:STDOUT: %c.ref: ref %C = name_ref c, file.%c
  215. // CHECK:STDOUT: %.loc8: %.4 = addr_of %c.ref
  216. // CHECK:STDOUT: assign file.%d.var, %.loc8
  217. // CHECK:STDOUT: return
  218. // CHECK:STDOUT: }
  219. // CHECK:STDOUT: