macros.carbon 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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/check/testdata/interop/cpp/macros.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/macros.carbon
  12. // ============================================================================
  13. // object-like macros
  14. // ============================================================================
  15. // --- integer_literal_replacement_token.h
  16. #define CONFIG_VALUE 42
  17. #define CONFIG_VALUE_LONG 42l
  18. #define CONFIG_VALUE_UNSIGNED 42u
  19. #define CONFIG_VALUE_HEXA 0xFF
  20. #define CONFIG_VALUE_OCTAL 010
  21. #define CONFIG_VALUE_BINARY 0b101
  22. // --- import_integer_literal_replacement_token.carbon
  23. library "[[@TEST_NAME]]";
  24. import Cpp library "integer_literal_replacement_token.h";
  25. fn F() {
  26. //@dump-sem-ir-begin
  27. let a: i32 = Cpp.CONFIG_VALUE;
  28. let b: i64 = Cpp.CONFIG_VALUE_LONG;
  29. let c: u32 = Cpp.CONFIG_VALUE_UNSIGNED;
  30. let d: i32 = Cpp.CONFIG_VALUE_HEXA;
  31. let e: i32 = Cpp.CONFIG_VALUE_OCTAL;
  32. let f: i32 = Cpp.CONFIG_VALUE_BINARY;
  33. //@dump-sem-ir-end
  34. }
  35. // --- bad_suffix.h
  36. #define CONFIG_VALUE 42f
  37. // --- fail_import_bad_suffix.carbon
  38. library "[[@TEST_NAME]]";
  39. // CHECK:STDERR: fail_import_bad_suffix.carbon:[[@LINE+4]]:10: in file included here [InCppInclude]
  40. // CHECK:STDERR: ./bad_suffix.h:1:24: error: invalid digit 'f' in decimal constant [CppInteropParseError]
  41. // CHECK:STDERR: 1 | #define CONFIG_VALUE 42f
  42. // CHECK:STDERR: | ^
  43. import Cpp library "bad_suffix.h";
  44. fn F() {
  45. // CHECK:STDERR: fail_import_bad_suffix.carbon:[[@LINE+15]]:3: note: in `Cpp` name lookup for `CONFIG_VALUE` [InCppNameLookup]
  46. // CHECK:STDERR: Cpp.CONFIG_VALUE;
  47. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  48. // CHECK:STDERR:
  49. // CHECK:STDERR: fail_import_bad_suffix.carbon:[[@LINE+11]]:3: error: failed to parse macro Cpp.CONFIG_VALUE to a valid constant expression [InCppMacroEvaluation]
  50. // CHECK:STDERR: Cpp.CONFIG_VALUE;
  51. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  52. // CHECK:STDERR: fail_import_bad_suffix.carbon:[[@LINE+8]]:3: note: in `Cpp` name lookup for `CONFIG_VALUE` [InCppNameLookup]
  53. // CHECK:STDERR: Cpp.CONFIG_VALUE;
  54. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  55. // CHECK:STDERR:
  56. // CHECK:STDERR: fail_import_bad_suffix.carbon:[[@LINE+4]]:3: error: member name `CONFIG_VALUE` not found in `Cpp` [MemberNameNotFoundInInstScope]
  57. // CHECK:STDERR: Cpp.CONFIG_VALUE;
  58. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  59. // CHECK:STDERR:
  60. Cpp.CONFIG_VALUE;
  61. }
  62. // --- integer_literal_too_big.h
  63. #define CONFIG_VALUE 18446744073709551616
  64. // --- fail_import_integer_literal_too_big.carbon
  65. library "[[@TEST_NAME]]";
  66. // CHECK:STDERR: fail_import_integer_literal_too_big.carbon:[[@LINE+4]]:10: in file included here [InCppInclude]
  67. // CHECK:STDERR: ./integer_literal_too_big.h:1:22: error: integer literal is too large to be represented in any integer type [CppInteropParseError]
  68. // CHECK:STDERR: 1 | #define CONFIG_VALUE 18446744073709551616
  69. // CHECK:STDERR: | ^
  70. import Cpp library "integer_literal_too_big.h";
  71. fn F() {
  72. // CHECK:STDERR: fail_import_integer_literal_too_big.carbon:[[@LINE+15]]:3: note: in `Cpp` name lookup for `CONFIG_VALUE` [InCppNameLookup]
  73. // CHECK:STDERR: Cpp.CONFIG_VALUE;
  74. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  75. // CHECK:STDERR:
  76. // CHECK:STDERR: fail_import_integer_literal_too_big.carbon:[[@LINE+11]]:3: error: semantics TODO: `Unsupported: C++ literal's type `unsigned long long` could not be mapped to a Carbon type` [SemanticsTodo]
  77. // CHECK:STDERR: Cpp.CONFIG_VALUE;
  78. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  79. // CHECK:STDERR: fail_import_integer_literal_too_big.carbon:[[@LINE+8]]:3: note: in `Cpp` name lookup for `CONFIG_VALUE` [InCppNameLookup]
  80. // CHECK:STDERR: Cpp.CONFIG_VALUE;
  81. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  82. // CHECK:STDERR:
  83. // CHECK:STDERR: fail_import_integer_literal_too_big.carbon:[[@LINE+4]]:3: error: member name `CONFIG_VALUE` not found in `Cpp` [MemberNameNotFoundInInstScope]
  84. // CHECK:STDERR: Cpp.CONFIG_VALUE;
  85. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  86. // CHECK:STDERR:
  87. Cpp.CONFIG_VALUE;
  88. }
  89. // --- fail_assign_to_object_like_macro.carbon
  90. library "[[@TEST_NAME]]";
  91. import Cpp library "integer_literal_replacement_token.h";
  92. fn F() {
  93. // CHECK:STDERR: fail_assign_to_object_like_macro.carbon:[[@LINE+4]]:3: error: expression is not assignable [AssignmentToNonAssignable]
  94. // CHECK:STDERR: Cpp.CONFIG_VALUE = 3;
  95. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  96. // CHECK:STDERR:
  97. Cpp.CONFIG_VALUE = 3;
  98. }
  99. // --- macro_in_nested_scope.h
  100. namespace N {
  101. #define CONFIG_VALUE 42
  102. }
  103. // --- fail_import_macro_in_nested_scope.carbon
  104. library "[[@TEST_NAME]]";
  105. import Cpp library "macro_in_nested_scope.h";
  106. fn F() {
  107. let a: i32 = Cpp.CONFIG_VALUE;
  108. // CHECK:STDERR: fail_import_macro_in_nested_scope.carbon:[[@LINE+4]]:16: error: member name `CONFIG_VALUE` not found in `Cpp.N` [MemberNameNotFoundInInstScope]
  109. // CHECK:STDERR: let b: i32 = Cpp.N.CONFIG_VALUE;
  110. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  111. // CHECK:STDERR:
  112. let b: i32 = Cpp.N.CONFIG_VALUE;
  113. }
  114. // --- macro_and_non_macro_same_name.h
  115. namespace X {
  116. float n;
  117. }
  118. float n;
  119. #define n 1
  120. // --- import_macro_and_non_macro_same_name.carbon
  121. library "[[@TEST_NAME]]";
  122. import Cpp library "macro_and_non_macro_same_name.h";
  123. fn F() {
  124. // When the same macro name and non-macro name exist in the global C++ scope, the macro name is selected.
  125. // Cpp.n is treated as an integer constant with value 1.
  126. var a: array(f32, Cpp.n) = (1.0,);
  127. let b: f32 = Cpp.X.n;
  128. }
  129. // --- no_replacement_token.h
  130. #define MACRO_NAME
  131. // --- fail_import_no_replacement_token.carbon
  132. library "[[@TEST_NAME]]";
  133. import Cpp library "no_replacement_token.h";
  134. fn F() {
  135. // TODO: Get rid of the second error.
  136. // CHECK:STDERR: fail_import_no_replacement_token.carbon:[[@LINE+11]]:3: error: semantics TODO: `Unsupported: macro with 0 replacement tokens` [SemanticsTodo]
  137. // CHECK:STDERR: Cpp.MACRO_NAME;
  138. // CHECK:STDERR: ^~~~~~~~~~~~~~
  139. // CHECK:STDERR: fail_import_no_replacement_token.carbon:[[@LINE+8]]:3: note: in `Cpp` name lookup for `MACRO_NAME` [InCppNameLookup]
  140. // CHECK:STDERR: Cpp.MACRO_NAME;
  141. // CHECK:STDERR: ^~~~~~~~~~~~~~
  142. // CHECK:STDERR:
  143. // CHECK:STDERR: fail_import_no_replacement_token.carbon:[[@LINE+4]]:3: error: member name `MACRO_NAME` not found in `Cpp` [MemberNameNotFoundInInstScope]
  144. // CHECK:STDERR: Cpp.MACRO_NAME;
  145. // CHECK:STDERR: ^~~~~~~~~~~~~~
  146. // CHECK:STDERR:
  147. Cpp.MACRO_NAME;
  148. }
  149. // --- unary_operator.h
  150. #define NEGATIVE -1
  151. // --- import_unary_operator.carbon
  152. library "[[@TEST_NAME]]";
  153. import Cpp library "unary_operator.h";
  154. fn F() {
  155. //@dump-sem-ir-begin
  156. let a: i32 = Cpp.NEGATIVE;
  157. //@dump-sem-ir-end
  158. }
  159. // --- binary_operator.h
  160. #define ADDITION 1+2
  161. // --- import_binary_operator.carbon
  162. library "[[@TEST_NAME]]";
  163. import Cpp library "binary_operator.h";
  164. fn F() {
  165. //@dump-sem-ir-begin
  166. let a: i32 = Cpp.ADDITION;
  167. //@dump-sem-ir-end
  168. }
  169. // --- casting.h
  170. #define CAST_UNSIGNED (unsigned int)1
  171. #define CAST_STATIC static_cast<int>(100.5)
  172. #define CAST_FUNCTIONAL int(99.9)
  173. #define CAST_BOOL_TO_INT (int)true
  174. // --- import_casting.carbon
  175. library "[[@TEST_NAME]]";
  176. import Cpp library "casting.h";
  177. fn F() {
  178. //@dump-sem-ir-begin
  179. let a: u32 = Cpp.CAST_UNSIGNED;
  180. let b: i32 = Cpp.CAST_STATIC;
  181. let c: i32 = Cpp.CAST_FUNCTIONAL;
  182. let d: i32 = Cpp.CAST_BOOL_TO_INT;
  183. //@dump-sem-ir-end
  184. }
  185. // --- nested_macros.h
  186. #define ONE 1
  187. #define INDIRECT_ONE ONE
  188. // --- import_nested_macros.carbon
  189. library "[[@TEST_NAME]]";
  190. import Cpp library "nested_macros.h";
  191. fn F() {
  192. //@dump-sem-ir-begin
  193. let a: i32 = Cpp.INDIRECT_ONE;
  194. //@dump-sem-ir-end
  195. }
  196. // --- string_literal_object_like_macro.h
  197. #define SimpleString "abc"
  198. #define EmptyString ""
  199. #define EscapeCharacter " \t "
  200. #define Concatenated "a" "b"
  201. #define RawString R"a( foo: "bar" { 123 } )a"
  202. #define Utf8String u8"абв"
  203. #define CONCAT_STR(A, B) #A #B
  204. #define Indirect CONCAT_STR(x, y)
  205. // --- import_string_literal_object_like_macro.carbon
  206. library "[[@TEST_NAME]]";
  207. import Cpp library "string_literal_object_like_macro.h";
  208. fn F() {
  209. let a: str = Cpp.SimpleString;
  210. let b: str = Cpp.EmptyString;
  211. let c: str = Cpp.EscapeCharacter;
  212. let d: str = Cpp.Concatenated;
  213. let e: str = Cpp.RawString;
  214. let f: str = Cpp.Utf8String;
  215. let g: str = Cpp.Indirect;
  216. }
  217. // --- unsupported_string_literal_types.h
  218. #define Utf16Greeting u"Hello"
  219. #define Utf32Greeting U"Hello"
  220. #define WideGreeting L"Hello"
  221. // --- fail_import_unsupported_string_literal_types.carbon
  222. library "[[@TEST_NAME]]";
  223. import Cpp library "unsupported_string_literal_types.h";
  224. fn F() {
  225. // CHECK:STDERR: fail_import_unsupported_string_literal_types.carbon:[[@LINE+11]]:2: error: semantics TODO: `Unsupported: string literal type: const char16_t[6]` [SemanticsTodo]
  226. // CHECK:STDERR: Cpp.Utf16Greeting;
  227. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  228. // CHECK:STDERR: fail_import_unsupported_string_literal_types.carbon:[[@LINE+8]]:2: note: in `Cpp` name lookup for `Utf16Greeting` [InCppNameLookup]
  229. // CHECK:STDERR: Cpp.Utf16Greeting;
  230. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  231. // CHECK:STDERR:
  232. // CHECK:STDERR: fail_import_unsupported_string_literal_types.carbon:[[@LINE+4]]:2: error: member name `Utf16Greeting` not found in `Cpp` [MemberNameNotFoundInInstScope]
  233. // CHECK:STDERR: Cpp.Utf16Greeting;
  234. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  235. // CHECK:STDERR:
  236. Cpp.Utf16Greeting;
  237. // CHECK:STDERR: fail_import_unsupported_string_literal_types.carbon:[[@LINE+11]]:2: error: semantics TODO: `Unsupported: string literal type: const char32_t[6]` [SemanticsTodo]
  238. // CHECK:STDERR: Cpp.Utf32Greeting;
  239. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  240. // CHECK:STDERR: fail_import_unsupported_string_literal_types.carbon:[[@LINE+8]]:2: note: in `Cpp` name lookup for `Utf32Greeting` [InCppNameLookup]
  241. // CHECK:STDERR: Cpp.Utf32Greeting;
  242. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  243. // CHECK:STDERR:
  244. // CHECK:STDERR: fail_import_unsupported_string_literal_types.carbon:[[@LINE+4]]:2: error: member name `Utf32Greeting` not found in `Cpp` [MemberNameNotFoundInInstScope]
  245. // CHECK:STDERR: Cpp.Utf32Greeting;
  246. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  247. // CHECK:STDERR:
  248. Cpp.Utf32Greeting;
  249. // CHECK:STDERR: fail_import_unsupported_string_literal_types.carbon:[[@LINE+11]]:2: error: semantics TODO: `Unsupported: string literal type: const wchar_t[6]` [SemanticsTodo]
  250. // CHECK:STDERR: Cpp.WideGreeting;
  251. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  252. // CHECK:STDERR: fail_import_unsupported_string_literal_types.carbon:[[@LINE+8]]:2: note: in `Cpp` name lookup for `WideGreeting` [InCppNameLookup]
  253. // CHECK:STDERR: Cpp.WideGreeting;
  254. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  255. // CHECK:STDERR:
  256. // CHECK:STDERR: fail_import_unsupported_string_literal_types.carbon:[[@LINE+4]]:2: error: member name `WideGreeting` not found in `Cpp` [MemberNameNotFoundInInstScope]
  257. // CHECK:STDERR: Cpp.WideGreeting;
  258. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  259. // CHECK:STDERR:
  260. Cpp.WideGreeting;
  261. }
  262. // --- fail_bad_string.carbon
  263. library "[[@TEST_NAME]]";
  264. import Cpp inline '''
  265. #define BadString "123" 456
  266. ''';
  267. fn F() {
  268. // CHECK:STDERR: fail_bad_string.carbon:[[@LINE+11]]:2: error: failed to parse macro Cpp.BadString to a valid constant expression [InCppMacroEvaluation]
  269. // CHECK:STDERR: Cpp.BadString;
  270. // CHECK:STDERR: ^~~~~~~~~~~~~
  271. // CHECK:STDERR: fail_bad_string.carbon:[[@LINE+8]]:2: note: in `Cpp` name lookup for `BadString` [InCppNameLookup]
  272. // CHECK:STDERR: Cpp.BadString;
  273. // CHECK:STDERR: ^~~~~~~~~~~~~
  274. // CHECK:STDERR:
  275. // CHECK:STDERR: fail_bad_string.carbon:[[@LINE+4]]:2: error: member name `BadString` not found in `Cpp` [MemberNameNotFoundInInstScope]
  276. // CHECK:STDERR: Cpp.BadString;
  277. // CHECK:STDERR: ^~~~~~~~~~~~~
  278. // CHECK:STDERR:
  279. Cpp.BadString;
  280. }
  281. // --- floating_point_literal_macro.h
  282. #define MyDouble 1.0
  283. #define MyDoubleE 1e2
  284. #define MyFloat 1.f
  285. // --- import_floating_point_literal_macro.carbon
  286. library "[[@TEST_NAME]]";
  287. import Cpp library "floating_point_literal_macro.h";
  288. fn F() {
  289. //@dump-sem-ir-begin
  290. let a: f64 = Cpp.MyDouble;
  291. let b: f64 = Cpp.MyDoubleE;
  292. let c: f32 = Cpp.MyFloat;
  293. //@dump-sem-ir-end
  294. }
  295. // --- unsupported_floating_point_literal_macro.h
  296. #define MyLongDouble 987.654l
  297. // --- fail_import_unsupported_floating_point_literal_macro.carbon
  298. library "[[@TEST_NAME]]";
  299. import Cpp library "unsupported_floating_point_literal_macro.h";
  300. fn F() {
  301. // CHECK:STDERR: fail_import_unsupported_floating_point_literal_macro.carbon:[[@LINE+11]]:3: error: semantics TODO: `Unsupported: C++ literal's type `long double` could not be mapped to a Carbon type` [SemanticsTodo]
  302. // CHECK:STDERR: Cpp.MyLongDouble;
  303. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  304. // CHECK:STDERR: fail_import_unsupported_floating_point_literal_macro.carbon:[[@LINE+8]]:3: note: in `Cpp` name lookup for `MyLongDouble` [InCppNameLookup]
  305. // CHECK:STDERR: Cpp.MyLongDouble;
  306. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  307. // CHECK:STDERR:
  308. // CHECK:STDERR: fail_import_unsupported_floating_point_literal_macro.carbon:[[@LINE+4]]:3: error: member name `MyLongDouble` not found in `Cpp` [MemberNameNotFoundInInstScope]
  309. // CHECK:STDERR: Cpp.MyLongDouble;
  310. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  311. // CHECK:STDERR:
  312. Cpp.MyLongDouble;
  313. }
  314. // --- fail_import_assign_to_float.carbon
  315. library "[[@TEST_NAME]]";
  316. import Cpp library "floating_point_literal_macro.h";
  317. fn F() {
  318. // CHECK:STDERR: fail_import_assign_to_float.carbon:[[@LINE+4]]:3: error: expression is not assignable [AssignmentToNonAssignable]
  319. // CHECK:STDERR: Cpp.MyDouble = 1.0;
  320. // CHECK:STDERR: ^~~~~~~~~~~~
  321. // CHECK:STDERR:
  322. Cpp.MyDouble = 1.0;
  323. }
  324. // --- character_literals.h
  325. #define M_LOWERCASE 'a'
  326. #define M_UPPRCASE 'A'
  327. #define M_DIGIT '1'
  328. #define M_SPACE ' '
  329. #define M_TAB '\t'
  330. #define M_UTF8_CHAR u8'X'
  331. // --- import_character_literals.carbon
  332. library "[[@TEST_NAME]]";
  333. import Cpp library "character_literals.h";
  334. fn F() {
  335. let a: char = Cpp.M_LOWERCASE;
  336. let b: char = Cpp.M_UPPRCASE;
  337. let c: char = Cpp.M_DIGIT;
  338. let d: char = Cpp.M_SPACE;
  339. let e: char = Cpp.M_TAB;
  340. let f: char = Cpp.M_UTF8_CHAR;
  341. }
  342. // --- character_literals_operators.h
  343. #define M_CONDITIONAL (1 < 2 ? 'a' : 'b')
  344. #define M_A_PLUS_ONE 'a' + 1
  345. #define M_A_EQUAL ('a' == 97)
  346. // --- import_character_literals_operators.carbon
  347. library "[[@TEST_NAME]]";
  348. import Cpp library "character_literals_operators.h";
  349. fn F() {
  350. let a: char = Cpp.M_CONDITIONAL;
  351. let b: i32 = Cpp.M_A_PLUS_ONE;
  352. let c: bool = Cpp.M_A_EQUAL;
  353. }
  354. // --- multiple_characters.h
  355. #define MULTIPLE_CHARS 'AB'
  356. // --- import_multiple_characters.carbon
  357. library "[[@TEST_NAME]]";
  358. // CHECK:STDERR: import_multiple_characters.carbon:[[@LINE+4]]:10: in file included here [InCppInclude]
  359. // CHECK:STDERR: ./multiple_characters.h:2:24: warning: multi-character character constant [CppInteropParseWarning]
  360. // CHECK:STDERR: 2 | #define MULTIPLE_CHARS 'AB'
  361. // CHECK:STDERR: | ^
  362. import Cpp library "multiple_characters.h";
  363. fn F() {
  364. // CHECK:STDERR: import_multiple_characters.carbon:[[@LINE+4]]:15: note: in `Cpp` name lookup for `MULTIPLE_CHARS` [InCppNameLookup]
  365. // CHECK:STDERR: let a: i32 = Cpp.MULTIPLE_CHARS;
  366. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
  367. // CHECK:STDERR:
  368. let a: i32 = Cpp.MULTIPLE_CHARS;
  369. }
  370. // --- unsupported_character_literal_types.h
  371. #define M_UTF16_CHAR u'a'
  372. #define M_UTF32_CHAR U'a'
  373. #define M_WIDE_CHAR L'a'
  374. // --- fail_unsupported_character_literal_types.carbon
  375. library "[[@TEST_NAME]]";
  376. import Cpp library "unsupported_character_literal_types.h";
  377. fn F() {
  378. // CHECK:STDERR: fail_unsupported_character_literal_types.carbon:[[@LINE+11]]:16: error: semantics TODO: `Unsupported: C++ literal's type `char16_t` could not be mapped to a Carbon type` [SemanticsTodo]
  379. // CHECK:STDERR: let a: char = Cpp.M_UTF16_CHAR;
  380. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  381. // CHECK:STDERR: fail_unsupported_character_literal_types.carbon:[[@LINE+8]]:16: note: in `Cpp` name lookup for `M_UTF16_CHAR` [InCppNameLookup]
  382. // CHECK:STDERR: let a: char = Cpp.M_UTF16_CHAR;
  383. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  384. // CHECK:STDERR:
  385. // CHECK:STDERR: fail_unsupported_character_literal_types.carbon:[[@LINE+4]]:16: error: member name `M_UTF16_CHAR` not found in `Cpp` [MemberNameNotFoundInInstScope]
  386. // CHECK:STDERR: let a: char = Cpp.M_UTF16_CHAR;
  387. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  388. // CHECK:STDERR:
  389. let a: char = Cpp.M_UTF16_CHAR;
  390. // CHECK:STDERR: fail_unsupported_character_literal_types.carbon:[[@LINE+11]]:16: error: semantics TODO: `Unsupported: C++ literal's type `char32_t` could not be mapped to a Carbon type` [SemanticsTodo]
  391. // CHECK:STDERR: let b: char = Cpp.M_UTF32_CHAR;
  392. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  393. // CHECK:STDERR: fail_unsupported_character_literal_types.carbon:[[@LINE+8]]:16: note: in `Cpp` name lookup for `M_UTF32_CHAR` [InCppNameLookup]
  394. // CHECK:STDERR: let b: char = Cpp.M_UTF32_CHAR;
  395. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  396. // CHECK:STDERR:
  397. // CHECK:STDERR: fail_unsupported_character_literal_types.carbon:[[@LINE+4]]:16: error: member name `M_UTF32_CHAR` not found in `Cpp` [MemberNameNotFoundInInstScope]
  398. // CHECK:STDERR: let b: char = Cpp.M_UTF32_CHAR;
  399. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  400. // CHECK:STDERR:
  401. let b: char = Cpp.M_UTF32_CHAR;
  402. // CHECK:STDERR: fail_unsupported_character_literal_types.carbon:[[@LINE+11]]:16: error: semantics TODO: `Unsupported: C++ literal's type `wchar_t` could not be mapped to a Carbon type` [SemanticsTodo]
  403. // CHECK:STDERR: let c: char = Cpp.M_WIDE_CHAR;
  404. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  405. // CHECK:STDERR: fail_unsupported_character_literal_types.carbon:[[@LINE+8]]:16: note: in `Cpp` name lookup for `M_WIDE_CHAR` [InCppNameLookup]
  406. // CHECK:STDERR: let c: char = Cpp.M_WIDE_CHAR;
  407. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  408. // CHECK:STDERR:
  409. // CHECK:STDERR: fail_unsupported_character_literal_types.carbon:[[@LINE+4]]:16: error: member name `M_WIDE_CHAR` not found in `Cpp` [MemberNameNotFoundInInstScope]
  410. // CHECK:STDERR: let c: char = Cpp.M_WIDE_CHAR;
  411. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  412. // CHECK:STDERR:
  413. let c: char = Cpp.M_WIDE_CHAR;
  414. }
  415. // --- fail_assign_to_character_literals.carbon
  416. library "[[@TEST_NAME]]";
  417. import Cpp library "character_literals.h";
  418. fn F() {
  419. // CHECK:STDERR: fail_assign_to_character_literals.carbon:[[@LINE+4]]:2: error: expression is not assignable [AssignmentToNonAssignable]
  420. // CHECK:STDERR: Cpp.M_LOWERCASE = 'b';
  421. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  422. // CHECK:STDERR:
  423. Cpp.M_LOWERCASE = 'b';
  424. }
  425. // --- boolean_literal_macro.h
  426. #define M_TRUE true
  427. #define M_FALSE false
  428. #define M_ONE 1
  429. #define M_ZERO 0
  430. #define M_NOT_TRUE !true
  431. #define M_NOT_ZERO (!0)
  432. #define M_ONE_EQ_ONE (1 == 1)
  433. #define M_ONE_NEQ_ONE (1 != 1)
  434. #define M_AND (true && true)
  435. #define M_OR (M_TRUE || M_FALSE)
  436. #define M_COMPLEX ((2 * 2 < 5) && !M_FALSE)
  437. // --- import_boolean_literal_macro.carbon
  438. library "[[@TEST_NAME]]";
  439. import Cpp library "boolean_literal_macro.h";
  440. fn F() {
  441. //@dump-sem-ir-begin
  442. let a: bool = Cpp.M_TRUE;
  443. let b: bool = Cpp.M_FALSE;
  444. let c: bool = Cpp.M_NOT_TRUE;
  445. let d: bool = Cpp.M_NOT_ZERO;
  446. let e: bool = Cpp.M_ONE_EQ_ONE;
  447. let f: bool = Cpp.M_ONE_NEQ_ONE;
  448. let g: bool = Cpp.M_AND;
  449. let h: bool = Cpp.M_OR;
  450. let i: bool = Cpp.M_COMPLEX;
  451. let j: i32 = Cpp.M_ONE;
  452. let k: i32 = Cpp.M_ZERO;
  453. //@dump-sem-ir-end
  454. }
  455. // --- fail_assign_to_boolean_literal_macro.carbon
  456. library "[[@TEST_NAME]]";
  457. import Cpp library "boolean_literal_macro.h";
  458. fn F() {
  459. // CHECK:STDERR: fail_assign_to_boolean_literal_macro.carbon:[[@LINE+4]]:2: error: expression is not assignable [AssignmentToNonAssignable]
  460. // CHECK:STDERR: Cpp.M_TRUE = false;
  461. // CHECK:STDERR: ^~~~~~~~~~
  462. // CHECK:STDERR:
  463. Cpp.M_TRUE = false;
  464. }
  465. // --- nullptr.carbon
  466. library "[[@TEST_NAME]]";
  467. import Cpp inline '''
  468. #define MyNullPtr nullptr
  469. void foo(int arr[2]);
  470. ''';
  471. fn F() {
  472. Cpp.foo(Cpp.MyNullPtr);
  473. }
  474. // --- enums.carbon
  475. library "[[@TEST_NAME]]";
  476. import Cpp inline '''
  477. enum A { a = 1, b = 2 };
  478. #define M_A ::a
  479. ''';
  480. fn F() {
  481. let a: Cpp.A = Cpp.M_A;
  482. }
  483. // --- fail_todo_enums_no_scope.carbon
  484. library "[[@TEST_NAME]]";
  485. import Cpp inline '''
  486. enum A { a = 1, b = 2 };
  487. // CHECK:STDERR: fail_todo_enums_no_scope.carbon:[[@LINE+7]]:24: error: use of undeclared identifier 'a'; did you mean '::a'? [CppInteropParseError]
  488. // CHECK:STDERR: 13 | #define M_A_NO_SCOPE a
  489. // CHECK:STDERR: | ^
  490. // CHECK:STDERR: | ::a
  491. // CHECK:STDERR: fail_todo_enums_no_scope.carbon:[[@LINE-5]]:12: note: '::a' declared here [CppInteropParseNote]
  492. // CHECK:STDERR: 5 | enum A { a = 1, b = 2 };
  493. // CHECK:STDERR: | ^
  494. #define M_A_NO_SCOPE a
  495. ''';
  496. fn F() {
  497. // CHECK:STDERR: fail_todo_enums_no_scope.carbon:[[@LINE+4]]:3: note: in `Cpp` name lookup for `M_A_NO_SCOPE` [InCppNameLookup]
  498. // CHECK:STDERR: Cpp.M_A_NO_SCOPE;
  499. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  500. // CHECK:STDERR:
  501. Cpp.M_A_NO_SCOPE;
  502. }
  503. // --- lambda.carbon
  504. library "[[@TEST_NAME]]";
  505. import Cpp inline '''
  506. #define MyIntLambda (([] { return 7; })())
  507. ''';
  508. fn F() {
  509. let i: i32 = Cpp.MyIntLambda;
  510. }
  511. // --- macro_undefined.h
  512. #define CONFIG_VALUE 1
  513. #undef CONFIG_VALUE
  514. // --- fail_macro_undefined.carbon
  515. library "[[@TEST_NAME]]";
  516. import Cpp library "macro_undefined.h";
  517. fn F() {
  518. // CHECK:STDERR: fail_macro_undefined.carbon:[[@LINE+4]]:16: error: member name `CONFIG_VALUE` not found in `Cpp` [MemberNameNotFoundInInstScope]
  519. // CHECK:STDERR: let a: i32 = Cpp.CONFIG_VALUE;
  520. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  521. // CHECK:STDERR:
  522. let a: i32 = Cpp.CONFIG_VALUE;
  523. }
  524. // --- macro_redefined.h
  525. #define REDEF_NAME 1
  526. #undef REDEF_NAME
  527. #define REDEF_NAME 2
  528. // --- import_macro_redefined.carbon
  529. library "[[@TEST_NAME]]";
  530. import Cpp library "macro_redefined.h";
  531. fn F() {
  532. //@dump-sem-ir-begin
  533. let a: i32 = Cpp.REDEF_NAME;
  534. //@dump-sem-ir-end
  535. }
  536. // --- macro_defined_twice.h
  537. #define TWICE_DEF 1
  538. #define TWICE_DEF 2
  539. // --- import_macro_defined_twice.carbon
  540. library "[[@TEST_NAME]]";
  541. // CHECK:STDERR: import_macro_defined_twice.carbon:[[@LINE+9]]:10: in file included here [InCppInclude]
  542. // CHECK:STDERR: ./macro_defined_twice.h:3:9: warning: 'TWICE_DEF' macro redefined [CppInteropParseWarning]
  543. // CHECK:STDERR: 3 | #define TWICE_DEF 2
  544. // CHECK:STDERR: | ^
  545. // CHECK:STDERR: import_macro_defined_twice.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
  546. // CHECK:STDERR: ./macro_defined_twice.h:2:9: note: previous definition is here [CppInteropParseNote]
  547. // CHECK:STDERR: 2 | #define TWICE_DEF 1
  548. // CHECK:STDERR: | ^
  549. // CHECK:STDERR:
  550. import Cpp library "macro_defined_twice.h";
  551. fn F() {
  552. //@dump-sem-ir-begin
  553. let a: i32 = Cpp.TWICE_DEF;
  554. //@dump-sem-ir-end
  555. }
  556. // ============================================================================
  557. // function-like macros
  558. // ============================================================================
  559. // --- function_like_macros.h
  560. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  561. // --- fail_todo_import_function_like_macros.carbon
  562. library "[[@TEST_NAME]]";
  563. import Cpp library "function_like_macros.h";
  564. fn F() {
  565. // CHECK:STDERR: fail_todo_import_function_like_macros.carbon:[[@LINE+4]]:16: error: member name `MAX` not found in `Cpp` [MemberNameNotFoundInInstScope]
  566. // CHECK:STDERR: let a: i32 = Cpp.MAX(1,2);
  567. // CHECK:STDERR: ^~~~~~~
  568. // CHECK:STDERR:
  569. let a: i32 = Cpp.MAX(1,2);
  570. }
  571. // ============================================================================
  572. // predefined macros
  573. // ============================================================================
  574. // --- predefined_macros.h
  575. auto foo() -> void;
  576. // --- fail_todo_import_predefined_macros.carbon
  577. library "[[@TEST_NAME]]";
  578. import Cpp library "predefined_macros.h";
  579. fn F() {
  580. // CHECK:STDERR: fail_todo_import_predefined_macros.carbon:[[@LINE+4]]:23: error: member name `__LINE__` not found in `Cpp` [MemberNameNotFoundInInstScope]
  581. // CHECK:STDERR: let line_num: i32 = Cpp.__LINE__;
  582. // CHECK:STDERR: ^~~~~~~~~~~~
  583. // CHECK:STDERR:
  584. let line_num: i32 = Cpp.__LINE__;
  585. }
  586. // ============================================================================
  587. // macros used as header guards
  588. // ============================================================================
  589. // --- header_guard_macros.h
  590. #ifndef HEADER_GUARD_MACRO_H_
  591. #define HEADER_GUARD_MACRO_H_
  592. void foo();
  593. #endif // HEADER_GUARD_MACRO_H_
  594. // --- fail_import_header_guard_macros.carbon
  595. library "[[@TEST_NAME]]";
  596. import Cpp library "header_guard_macros.h";
  597. fn F() {
  598. // CHECK:STDERR: fail_import_header_guard_macros.carbon:[[@LINE+4]]:3: error: member name `HEADER_GUARD_MACRO_H_` not found in `Cpp` [MemberNameNotFoundInInstScope]
  599. // CHECK:STDERR: Cpp.HEADER_GUARD_MACRO_H_;
  600. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  601. // CHECK:STDERR:
  602. Cpp.HEADER_GUARD_MACRO_H_;
  603. }
  604. // CHECK:STDOUT: --- import_integer_literal_replacement_token.carbon
  605. // CHECK:STDOUT:
  606. // CHECK:STDOUT: constants {
  607. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  608. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  609. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  610. // CHECK:STDOUT: %int_42.c68: %i32 = int_value 42 [concrete]
  611. // CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [concrete]
  612. // CHECK:STDOUT: %i64: type = class_type @Int, @Int(%int_64) [concrete]
  613. // CHECK:STDOUT: %pattern_type.95b: type = pattern_type %i64 [concrete]
  614. // CHECK:STDOUT: %int_42.434: %i64 = int_value 42 [concrete]
  615. // CHECK:STDOUT: %u32: type = class_type @UInt, @UInt(%int_32) [concrete]
  616. // CHECK:STDOUT: %pattern_type.4a9: type = pattern_type %u32 [concrete]
  617. // CHECK:STDOUT: %int_42.58b: %u32 = int_value 42 [concrete]
  618. // CHECK:STDOUT: %int_255: %i32 = int_value 255 [concrete]
  619. // CHECK:STDOUT: %int_8: %i32 = int_value 8 [concrete]
  620. // CHECK:STDOUT: %int_5: %i32 = int_value 5 [concrete]
  621. // CHECK:STDOUT: }
  622. // CHECK:STDOUT:
  623. // CHECK:STDOUT: imports {
  624. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  625. // CHECK:STDOUT: .CONFIG_VALUE = %int_42.c68
  626. // CHECK:STDOUT: .CONFIG_VALUE_LONG = %int_42.434
  627. // CHECK:STDOUT: .CONFIG_VALUE_UNSIGNED = %int_42.58b
  628. // CHECK:STDOUT: .CONFIG_VALUE_HEXA = %int_255
  629. // CHECK:STDOUT: .CONFIG_VALUE_OCTAL = %int_8
  630. // CHECK:STDOUT: .CONFIG_VALUE_BINARY = %int_5
  631. // CHECK:STDOUT: import Cpp//...
  632. // CHECK:STDOUT: }
  633. // CHECK:STDOUT: %int_42.c68: %i32 = int_value 42 [concrete = constants.%int_42.c68]
  634. // CHECK:STDOUT: %int_42.434: %i64 = int_value 42 [concrete = constants.%int_42.434]
  635. // CHECK:STDOUT: %int_42.58b: %u32 = int_value 42 [concrete = constants.%int_42.58b]
  636. // CHECK:STDOUT: %int_255: %i32 = int_value 255 [concrete = constants.%int_255]
  637. // CHECK:STDOUT: %int_8: %i32 = int_value 8 [concrete = constants.%int_8]
  638. // CHECK:STDOUT: %int_5: %i32 = int_value 5 [concrete = constants.%int_5]
  639. // CHECK:STDOUT: }
  640. // CHECK:STDOUT:
  641. // CHECK:STDOUT: fn @F() {
  642. // CHECK:STDOUT: !entry:
  643. // CHECK:STDOUT: name_binding_decl {
  644. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  645. // CHECK:STDOUT: }
  646. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  647. // CHECK:STDOUT: <elided>
  648. // CHECK:STDOUT: %CONFIG_VALUE.ref: %i32 = name_ref CONFIG_VALUE, imports.%int_42.c68 [concrete = constants.%int_42.c68]
  649. // CHECK:STDOUT: %.loc8: type = splice_block %i32.loc8 [concrete = constants.%i32] {
  650. // CHECK:STDOUT: %int_32.loc8: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  651. // CHECK:STDOUT: %i32.loc8: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  652. // CHECK:STDOUT: }
  653. // CHECK:STDOUT: %a: %i32 = value_binding a, %CONFIG_VALUE.ref
  654. // CHECK:STDOUT: name_binding_decl {
  655. // CHECK:STDOUT: %b.patt: %pattern_type.95b = value_binding_pattern b [concrete]
  656. // CHECK:STDOUT: }
  657. // CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  658. // CHECK:STDOUT: <elided>
  659. // CHECK:STDOUT: %CONFIG_VALUE_LONG.ref: %i64 = name_ref CONFIG_VALUE_LONG, imports.%int_42.434 [concrete = constants.%int_42.434]
  660. // CHECK:STDOUT: %.loc9: type = splice_block %i64.loc9 [concrete = constants.%i64] {
  661. // CHECK:STDOUT: %int_64.loc9: Core.IntLiteral = int_value 64 [concrete = constants.%int_64]
  662. // CHECK:STDOUT: %i64.loc9: type = class_type @Int, @Int(constants.%int_64) [concrete = constants.%i64]
  663. // CHECK:STDOUT: }
  664. // CHECK:STDOUT: %b: %i64 = value_binding b, %CONFIG_VALUE_LONG.ref
  665. // CHECK:STDOUT: name_binding_decl {
  666. // CHECK:STDOUT: %c.patt: %pattern_type.4a9 = value_binding_pattern c [concrete]
  667. // CHECK:STDOUT: }
  668. // CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  669. // CHECK:STDOUT: <elided>
  670. // CHECK:STDOUT: %CONFIG_VALUE_UNSIGNED.ref: %u32 = name_ref CONFIG_VALUE_UNSIGNED, imports.%int_42.58b [concrete = constants.%int_42.58b]
  671. // CHECK:STDOUT: %.loc10: type = splice_block %u32.loc10 [concrete = constants.%u32] {
  672. // CHECK:STDOUT: %int_32.loc10: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  673. // CHECK:STDOUT: %u32.loc10: type = class_type @UInt, @UInt(constants.%int_32) [concrete = constants.%u32]
  674. // CHECK:STDOUT: }
  675. // CHECK:STDOUT: %c: %u32 = value_binding c, %CONFIG_VALUE_UNSIGNED.ref
  676. // CHECK:STDOUT: name_binding_decl {
  677. // CHECK:STDOUT: %d.patt: %pattern_type.7ce = value_binding_pattern d [concrete]
  678. // CHECK:STDOUT: }
  679. // CHECK:STDOUT: %Cpp.ref.loc11: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  680. // CHECK:STDOUT: <elided>
  681. // CHECK:STDOUT: %CONFIG_VALUE_HEXA.ref: %i32 = name_ref CONFIG_VALUE_HEXA, imports.%int_255 [concrete = constants.%int_255]
  682. // CHECK:STDOUT: %.loc11: type = splice_block %i32.loc11 [concrete = constants.%i32] {
  683. // CHECK:STDOUT: %int_32.loc11: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  684. // CHECK:STDOUT: %i32.loc11: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  685. // CHECK:STDOUT: }
  686. // CHECK:STDOUT: %d: %i32 = value_binding d, %CONFIG_VALUE_HEXA.ref
  687. // CHECK:STDOUT: name_binding_decl {
  688. // CHECK:STDOUT: %e.patt: %pattern_type.7ce = value_binding_pattern e [concrete]
  689. // CHECK:STDOUT: }
  690. // CHECK:STDOUT: %Cpp.ref.loc12: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  691. // CHECK:STDOUT: <elided>
  692. // CHECK:STDOUT: %CONFIG_VALUE_OCTAL.ref: %i32 = name_ref CONFIG_VALUE_OCTAL, imports.%int_8 [concrete = constants.%int_8]
  693. // CHECK:STDOUT: %.loc12: type = splice_block %i32.loc12 [concrete = constants.%i32] {
  694. // CHECK:STDOUT: %int_32.loc12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  695. // CHECK:STDOUT: %i32.loc12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  696. // CHECK:STDOUT: }
  697. // CHECK:STDOUT: %e: %i32 = value_binding e, %CONFIG_VALUE_OCTAL.ref
  698. // CHECK:STDOUT: name_binding_decl {
  699. // CHECK:STDOUT: %f.patt: %pattern_type.7ce = value_binding_pattern f [concrete]
  700. // CHECK:STDOUT: }
  701. // CHECK:STDOUT: %Cpp.ref.loc13: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  702. // CHECK:STDOUT: <elided>
  703. // CHECK:STDOUT: %CONFIG_VALUE_BINARY.ref: %i32 = name_ref CONFIG_VALUE_BINARY, imports.%int_5 [concrete = constants.%int_5]
  704. // CHECK:STDOUT: %.loc13: type = splice_block %i32.loc13 [concrete = constants.%i32] {
  705. // CHECK:STDOUT: %int_32.loc13: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  706. // CHECK:STDOUT: %i32.loc13: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  707. // CHECK:STDOUT: }
  708. // CHECK:STDOUT: %f: %i32 = value_binding f, %CONFIG_VALUE_BINARY.ref
  709. // CHECK:STDOUT: <elided>
  710. // CHECK:STDOUT: }
  711. // CHECK:STDOUT:
  712. // CHECK:STDOUT: --- import_unary_operator.carbon
  713. // CHECK:STDOUT:
  714. // CHECK:STDOUT: constants {
  715. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  716. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  717. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  718. // CHECK:STDOUT: %int_-1: %i32 = int_value -1 [concrete]
  719. // CHECK:STDOUT: }
  720. // CHECK:STDOUT:
  721. // CHECK:STDOUT: imports {
  722. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  723. // CHECK:STDOUT: .NEGATIVE = %int_-1
  724. // CHECK:STDOUT: import Cpp//...
  725. // CHECK:STDOUT: }
  726. // CHECK:STDOUT: %int_-1: %i32 = int_value -1 [concrete = constants.%int_-1]
  727. // CHECK:STDOUT: }
  728. // CHECK:STDOUT:
  729. // CHECK:STDOUT: fn @F() {
  730. // CHECK:STDOUT: !entry:
  731. // CHECK:STDOUT: name_binding_decl {
  732. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  733. // CHECK:STDOUT: }
  734. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  735. // CHECK:STDOUT: <elided>
  736. // CHECK:STDOUT: %NEGATIVE.ref: %i32 = name_ref NEGATIVE, imports.%int_-1 [concrete = constants.%int_-1]
  737. // CHECK:STDOUT: %.loc8: type = splice_block %i32.loc8 [concrete = constants.%i32] {
  738. // CHECK:STDOUT: %int_32.loc8: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  739. // CHECK:STDOUT: %i32.loc8: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  740. // CHECK:STDOUT: }
  741. // CHECK:STDOUT: %a: %i32 = value_binding a, %NEGATIVE.ref
  742. // CHECK:STDOUT: <elided>
  743. // CHECK:STDOUT: }
  744. // CHECK:STDOUT:
  745. // CHECK:STDOUT: --- import_binary_operator.carbon
  746. // CHECK:STDOUT:
  747. // CHECK:STDOUT: constants {
  748. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  749. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  750. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  751. // CHECK:STDOUT: %int_3: %i32 = int_value 3 [concrete]
  752. // CHECK:STDOUT: }
  753. // CHECK:STDOUT:
  754. // CHECK:STDOUT: imports {
  755. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  756. // CHECK:STDOUT: .ADDITION = %int_3
  757. // CHECK:STDOUT: import Cpp//...
  758. // CHECK:STDOUT: }
  759. // CHECK:STDOUT: %int_3: %i32 = int_value 3 [concrete = constants.%int_3]
  760. // CHECK:STDOUT: }
  761. // CHECK:STDOUT:
  762. // CHECK:STDOUT: fn @F() {
  763. // CHECK:STDOUT: !entry:
  764. // CHECK:STDOUT: name_binding_decl {
  765. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  766. // CHECK:STDOUT: }
  767. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  768. // CHECK:STDOUT: <elided>
  769. // CHECK:STDOUT: %ADDITION.ref: %i32 = name_ref ADDITION, imports.%int_3 [concrete = constants.%int_3]
  770. // CHECK:STDOUT: %.loc8: type = splice_block %i32.loc8 [concrete = constants.%i32] {
  771. // CHECK:STDOUT: %int_32.loc8: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  772. // CHECK:STDOUT: %i32.loc8: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  773. // CHECK:STDOUT: }
  774. // CHECK:STDOUT: %a: %i32 = value_binding a, %ADDITION.ref
  775. // CHECK:STDOUT: <elided>
  776. // CHECK:STDOUT: }
  777. // CHECK:STDOUT:
  778. // CHECK:STDOUT: --- import_casting.carbon
  779. // CHECK:STDOUT:
  780. // CHECK:STDOUT: constants {
  781. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  782. // CHECK:STDOUT: %u32: type = class_type @UInt, @UInt(%int_32) [concrete]
  783. // CHECK:STDOUT: %pattern_type.4a9: type = pattern_type %u32 [concrete]
  784. // CHECK:STDOUT: %int_1.c1d: %u32 = int_value 1 [concrete]
  785. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  786. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  787. // CHECK:STDOUT: %int_100: %i32 = int_value 100 [concrete]
  788. // CHECK:STDOUT: %int_99: %i32 = int_value 99 [concrete]
  789. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete]
  790. // CHECK:STDOUT: }
  791. // CHECK:STDOUT:
  792. // CHECK:STDOUT: imports {
  793. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  794. // CHECK:STDOUT: .CAST_UNSIGNED = %int_1.c1d
  795. // CHECK:STDOUT: .CAST_STATIC = %int_100
  796. // CHECK:STDOUT: .CAST_FUNCTIONAL = %int_99
  797. // CHECK:STDOUT: .CAST_BOOL_TO_INT = %int_1.5d2
  798. // CHECK:STDOUT: import Cpp//...
  799. // CHECK:STDOUT: }
  800. // CHECK:STDOUT: %int_1.c1d: %u32 = int_value 1 [concrete = constants.%int_1.c1d]
  801. // CHECK:STDOUT: %int_100: %i32 = int_value 100 [concrete = constants.%int_100]
  802. // CHECK:STDOUT: %int_99: %i32 = int_value 99 [concrete = constants.%int_99]
  803. // CHECK:STDOUT: %int_1.5d2: %i32 = int_value 1 [concrete = constants.%int_1.5d2]
  804. // CHECK:STDOUT: }
  805. // CHECK:STDOUT:
  806. // CHECK:STDOUT: fn @F() {
  807. // CHECK:STDOUT: !entry:
  808. // CHECK:STDOUT: name_binding_decl {
  809. // CHECK:STDOUT: %a.patt: %pattern_type.4a9 = value_binding_pattern a [concrete]
  810. // CHECK:STDOUT: }
  811. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  812. // CHECK:STDOUT: <elided>
  813. // CHECK:STDOUT: %CAST_UNSIGNED.ref: %u32 = name_ref CAST_UNSIGNED, imports.%int_1.c1d [concrete = constants.%int_1.c1d]
  814. // CHECK:STDOUT: %.loc8: type = splice_block %u32.loc8 [concrete = constants.%u32] {
  815. // CHECK:STDOUT: %int_32.loc8: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  816. // CHECK:STDOUT: %u32.loc8: type = class_type @UInt, @UInt(constants.%int_32) [concrete = constants.%u32]
  817. // CHECK:STDOUT: }
  818. // CHECK:STDOUT: %a: %u32 = value_binding a, %CAST_UNSIGNED.ref
  819. // CHECK:STDOUT: name_binding_decl {
  820. // CHECK:STDOUT: %b.patt: %pattern_type.7ce = value_binding_pattern b [concrete]
  821. // CHECK:STDOUT: }
  822. // CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  823. // CHECK:STDOUT: <elided>
  824. // CHECK:STDOUT: %CAST_STATIC.ref: %i32 = name_ref CAST_STATIC, imports.%int_100 [concrete = constants.%int_100]
  825. // CHECK:STDOUT: %.loc9: type = splice_block %i32.loc9 [concrete = constants.%i32] {
  826. // CHECK:STDOUT: %int_32.loc9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  827. // CHECK:STDOUT: %i32.loc9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  828. // CHECK:STDOUT: }
  829. // CHECK:STDOUT: %b: %i32 = value_binding b, %CAST_STATIC.ref
  830. // CHECK:STDOUT: name_binding_decl {
  831. // CHECK:STDOUT: %c.patt: %pattern_type.7ce = value_binding_pattern c [concrete]
  832. // CHECK:STDOUT: }
  833. // CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  834. // CHECK:STDOUT: <elided>
  835. // CHECK:STDOUT: %CAST_FUNCTIONAL.ref: %i32 = name_ref CAST_FUNCTIONAL, imports.%int_99 [concrete = constants.%int_99]
  836. // CHECK:STDOUT: %.loc10: type = splice_block %i32.loc10 [concrete = constants.%i32] {
  837. // CHECK:STDOUT: %int_32.loc10: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  838. // CHECK:STDOUT: %i32.loc10: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  839. // CHECK:STDOUT: }
  840. // CHECK:STDOUT: %c: %i32 = value_binding c, %CAST_FUNCTIONAL.ref
  841. // CHECK:STDOUT: name_binding_decl {
  842. // CHECK:STDOUT: %d.patt: %pattern_type.7ce = value_binding_pattern d [concrete]
  843. // CHECK:STDOUT: }
  844. // CHECK:STDOUT: %Cpp.ref.loc11: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  845. // CHECK:STDOUT: <elided>
  846. // CHECK:STDOUT: %CAST_BOOL_TO_INT.ref: %i32 = name_ref CAST_BOOL_TO_INT, imports.%int_1.5d2 [concrete = constants.%int_1.5d2]
  847. // CHECK:STDOUT: %.loc11: type = splice_block %i32.loc11 [concrete = constants.%i32] {
  848. // CHECK:STDOUT: %int_32.loc11: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  849. // CHECK:STDOUT: %i32.loc11: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  850. // CHECK:STDOUT: }
  851. // CHECK:STDOUT: %d: %i32 = value_binding d, %CAST_BOOL_TO_INT.ref
  852. // CHECK:STDOUT: <elided>
  853. // CHECK:STDOUT: }
  854. // CHECK:STDOUT:
  855. // CHECK:STDOUT: --- import_nested_macros.carbon
  856. // CHECK:STDOUT:
  857. // CHECK:STDOUT: constants {
  858. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  859. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  860. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  861. // CHECK:STDOUT: %int_1: %i32 = int_value 1 [concrete]
  862. // CHECK:STDOUT: }
  863. // CHECK:STDOUT:
  864. // CHECK:STDOUT: imports {
  865. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  866. // CHECK:STDOUT: .INDIRECT_ONE = %int_1
  867. // CHECK:STDOUT: import Cpp//...
  868. // CHECK:STDOUT: }
  869. // CHECK:STDOUT: %int_1: %i32 = int_value 1 [concrete = constants.%int_1]
  870. // CHECK:STDOUT: }
  871. // CHECK:STDOUT:
  872. // CHECK:STDOUT: fn @F() {
  873. // CHECK:STDOUT: !entry:
  874. // CHECK:STDOUT: name_binding_decl {
  875. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  876. // CHECK:STDOUT: }
  877. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  878. // CHECK:STDOUT: <elided>
  879. // CHECK:STDOUT: %INDIRECT_ONE.ref: %i32 = name_ref INDIRECT_ONE, imports.%int_1 [concrete = constants.%int_1]
  880. // CHECK:STDOUT: %.loc8: type = splice_block %i32.loc8 [concrete = constants.%i32] {
  881. // CHECK:STDOUT: %int_32.loc8: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  882. // CHECK:STDOUT: %i32.loc8: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  883. // CHECK:STDOUT: }
  884. // CHECK:STDOUT: %a: %i32 = value_binding a, %INDIRECT_ONE.ref
  885. // CHECK:STDOUT: <elided>
  886. // CHECK:STDOUT: }
  887. // CHECK:STDOUT:
  888. // CHECK:STDOUT: --- import_floating_point_literal_macro.carbon
  889. // CHECK:STDOUT:
  890. // CHECK:STDOUT: constants {
  891. // CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [concrete]
  892. // CHECK:STDOUT: %f64.d77: type = class_type @Float, @Float(%int_64) [concrete]
  893. // CHECK:STDOUT: %pattern_type.0ae: type = pattern_type %f64.d77 [concrete]
  894. // CHECK:STDOUT: %float.d20: %f64.d77 = float_value 1 [concrete]
  895. // CHECK:STDOUT: %float.e0c: %f64.d77 = float_value 100 [concrete]
  896. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  897. // CHECK:STDOUT: %f32.97e: type = class_type @Float, @Float(%int_32) [concrete]
  898. // CHECK:STDOUT: %pattern_type.201: type = pattern_type %f32.97e [concrete]
  899. // CHECK:STDOUT: %float.e3b: %f32.97e = float_value 1 [concrete]
  900. // CHECK:STDOUT: }
  901. // CHECK:STDOUT:
  902. // CHECK:STDOUT: imports {
  903. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  904. // CHECK:STDOUT: .MyDouble = %float.d20
  905. // CHECK:STDOUT: .MyDoubleE = %float.e0c
  906. // CHECK:STDOUT: .MyFloat = %float.e3b
  907. // CHECK:STDOUT: import Cpp//...
  908. // CHECK:STDOUT: }
  909. // CHECK:STDOUT: %float.d20: %f64.d77 = float_value 1 [concrete = constants.%float.d20]
  910. // CHECK:STDOUT: %float.e0c: %f64.d77 = float_value 100 [concrete = constants.%float.e0c]
  911. // CHECK:STDOUT: %float.e3b: %f32.97e = float_value 1 [concrete = constants.%float.e3b]
  912. // CHECK:STDOUT: }
  913. // CHECK:STDOUT:
  914. // CHECK:STDOUT: fn @F() {
  915. // CHECK:STDOUT: !entry:
  916. // CHECK:STDOUT: name_binding_decl {
  917. // CHECK:STDOUT: %a.patt: %pattern_type.0ae = value_binding_pattern a [concrete]
  918. // CHECK:STDOUT: }
  919. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  920. // CHECK:STDOUT: <elided>
  921. // CHECK:STDOUT: %MyDouble.ref: %f64.d77 = name_ref MyDouble, imports.%float.d20 [concrete = constants.%float.d20]
  922. // CHECK:STDOUT: %.loc8: type = splice_block %f64.loc8 [concrete = constants.%f64.d77] {
  923. // CHECK:STDOUT: %int_64.loc8: Core.IntLiteral = int_value 64 [concrete = constants.%int_64]
  924. // CHECK:STDOUT: %f64.loc8: type = class_type @Float, @Float(constants.%int_64) [concrete = constants.%f64.d77]
  925. // CHECK:STDOUT: }
  926. // CHECK:STDOUT: %a: %f64.d77 = value_binding a, %MyDouble.ref
  927. // CHECK:STDOUT: name_binding_decl {
  928. // CHECK:STDOUT: %b.patt: %pattern_type.0ae = value_binding_pattern b [concrete]
  929. // CHECK:STDOUT: }
  930. // CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  931. // CHECK:STDOUT: <elided>
  932. // CHECK:STDOUT: %MyDoubleE.ref: %f64.d77 = name_ref MyDoubleE, imports.%float.e0c [concrete = constants.%float.e0c]
  933. // CHECK:STDOUT: %.loc9: type = splice_block %f64.loc9 [concrete = constants.%f64.d77] {
  934. // CHECK:STDOUT: %int_64.loc9: Core.IntLiteral = int_value 64 [concrete = constants.%int_64]
  935. // CHECK:STDOUT: %f64.loc9: type = class_type @Float, @Float(constants.%int_64) [concrete = constants.%f64.d77]
  936. // CHECK:STDOUT: }
  937. // CHECK:STDOUT: %b: %f64.d77 = value_binding b, %MyDoubleE.ref
  938. // CHECK:STDOUT: name_binding_decl {
  939. // CHECK:STDOUT: %c.patt: %pattern_type.201 = value_binding_pattern c [concrete]
  940. // CHECK:STDOUT: }
  941. // CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  942. // CHECK:STDOUT: <elided>
  943. // CHECK:STDOUT: %MyFloat.ref: %f32.97e = name_ref MyFloat, imports.%float.e3b [concrete = constants.%float.e3b]
  944. // CHECK:STDOUT: %.loc10: type = splice_block %f32.loc10 [concrete = constants.%f32.97e] {
  945. // CHECK:STDOUT: %int_32.loc10: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  946. // CHECK:STDOUT: %f32.loc10: type = class_type @Float, @Float(constants.%int_32) [concrete = constants.%f32.97e]
  947. // CHECK:STDOUT: }
  948. // CHECK:STDOUT: %c: %f32.97e = value_binding c, %MyFloat.ref
  949. // CHECK:STDOUT: <elided>
  950. // CHECK:STDOUT: }
  951. // CHECK:STDOUT:
  952. // CHECK:STDOUT: --- import_boolean_literal_macro.carbon
  953. // CHECK:STDOUT:
  954. // CHECK:STDOUT: constants {
  955. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  956. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  957. // CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
  958. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  959. // CHECK:STDOUT: %false: bool = bool_literal false [concrete]
  960. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  961. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  962. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  963. // CHECK:STDOUT: %int_1: %i32 = int_value 1 [concrete]
  964. // CHECK:STDOUT: %int_0: %i32 = int_value 0 [concrete]
  965. // CHECK:STDOUT: }
  966. // CHECK:STDOUT:
  967. // CHECK:STDOUT: imports {
  968. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  969. // CHECK:STDOUT: .M_TRUE = %true.d1048d.1
  970. // CHECK:STDOUT: .M_FALSE = %false.505718.1
  971. // CHECK:STDOUT: .M_NOT_TRUE = %false.505718.2
  972. // CHECK:STDOUT: .M_NOT_ZERO = %true.d1048d.2
  973. // CHECK:STDOUT: .M_ONE_EQ_ONE = %true.d1048d.3
  974. // CHECK:STDOUT: .M_ONE_NEQ_ONE = %false.505718.3
  975. // CHECK:STDOUT: .M_AND = %true.d1048d.4
  976. // CHECK:STDOUT: .M_OR = %true.d1048d.5
  977. // CHECK:STDOUT: .M_COMPLEX = %true.d1048d.6
  978. // CHECK:STDOUT: .M_ONE = %int_1
  979. // CHECK:STDOUT: .M_ZERO = %int_0
  980. // CHECK:STDOUT: import Cpp//...
  981. // CHECK:STDOUT: }
  982. // CHECK:STDOUT: %true.d1048d.1: bool = bool_literal true [concrete = constants.%true]
  983. // CHECK:STDOUT: %false.505718.1: bool = bool_literal false [concrete = constants.%false]
  984. // CHECK:STDOUT: %false.505718.2: bool = bool_literal false [concrete = constants.%false]
  985. // CHECK:STDOUT: %true.d1048d.2: bool = bool_literal true [concrete = constants.%true]
  986. // CHECK:STDOUT: %true.d1048d.3: bool = bool_literal true [concrete = constants.%true]
  987. // CHECK:STDOUT: %false.505718.3: bool = bool_literal false [concrete = constants.%false]
  988. // CHECK:STDOUT: %true.d1048d.4: bool = bool_literal true [concrete = constants.%true]
  989. // CHECK:STDOUT: %true.d1048d.5: bool = bool_literal true [concrete = constants.%true]
  990. // CHECK:STDOUT: %true.d1048d.6: bool = bool_literal true [concrete = constants.%true]
  991. // CHECK:STDOUT: %int_1: %i32 = int_value 1 [concrete = constants.%int_1]
  992. // CHECK:STDOUT: %int_0: %i32 = int_value 0 [concrete = constants.%int_0]
  993. // CHECK:STDOUT: }
  994. // CHECK:STDOUT:
  995. // CHECK:STDOUT: fn @F() {
  996. // CHECK:STDOUT: !entry:
  997. // CHECK:STDOUT: name_binding_decl {
  998. // CHECK:STDOUT: %a.patt: %pattern_type.831 = value_binding_pattern a [concrete]
  999. // CHECK:STDOUT: }
  1000. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1001. // CHECK:STDOUT: %M_TRUE.ref: bool = name_ref M_TRUE, imports.%true.d1048d.1 [concrete = constants.%true]
  1002. // CHECK:STDOUT: %.loc8_10.1: type = splice_block %.loc8_10.3 [concrete = bool] {
  1003. // CHECK:STDOUT: %Bool.call.loc8: init type = call constants.%Bool() [concrete = bool]
  1004. // CHECK:STDOUT: %.loc8_10.2: type = value_of_initializer %Bool.call.loc8 [concrete = bool]
  1005. // CHECK:STDOUT: %.loc8_10.3: type = converted %Bool.call.loc8, %.loc8_10.2 [concrete = bool]
  1006. // CHECK:STDOUT: }
  1007. // CHECK:STDOUT: %a: bool = value_binding a, %M_TRUE.ref
  1008. // CHECK:STDOUT: name_binding_decl {
  1009. // CHECK:STDOUT: %b.patt: %pattern_type.831 = value_binding_pattern b [concrete]
  1010. // CHECK:STDOUT: }
  1011. // CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1012. // CHECK:STDOUT: %M_FALSE.ref: bool = name_ref M_FALSE, imports.%false.505718.1 [concrete = constants.%false]
  1013. // CHECK:STDOUT: %.loc9_10.1: type = splice_block %.loc9_10.3 [concrete = bool] {
  1014. // CHECK:STDOUT: %Bool.call.loc9: init type = call constants.%Bool() [concrete = bool]
  1015. // CHECK:STDOUT: %.loc9_10.2: type = value_of_initializer %Bool.call.loc9 [concrete = bool]
  1016. // CHECK:STDOUT: %.loc9_10.3: type = converted %Bool.call.loc9, %.loc9_10.2 [concrete = bool]
  1017. // CHECK:STDOUT: }
  1018. // CHECK:STDOUT: %b: bool = value_binding b, %M_FALSE.ref
  1019. // CHECK:STDOUT: name_binding_decl {
  1020. // CHECK:STDOUT: %c.patt: %pattern_type.831 = value_binding_pattern c [concrete]
  1021. // CHECK:STDOUT: }
  1022. // CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1023. // CHECK:STDOUT: %M_NOT_TRUE.ref: bool = name_ref M_NOT_TRUE, imports.%false.505718.2 [concrete = constants.%false]
  1024. // CHECK:STDOUT: %.loc10_10.1: type = splice_block %.loc10_10.3 [concrete = bool] {
  1025. // CHECK:STDOUT: %Bool.call.loc10: init type = call constants.%Bool() [concrete = bool]
  1026. // CHECK:STDOUT: %.loc10_10.2: type = value_of_initializer %Bool.call.loc10 [concrete = bool]
  1027. // CHECK:STDOUT: %.loc10_10.3: type = converted %Bool.call.loc10, %.loc10_10.2 [concrete = bool]
  1028. // CHECK:STDOUT: }
  1029. // CHECK:STDOUT: %c: bool = value_binding c, %M_NOT_TRUE.ref
  1030. // CHECK:STDOUT: name_binding_decl {
  1031. // CHECK:STDOUT: %d.patt: %pattern_type.831 = value_binding_pattern d [concrete]
  1032. // CHECK:STDOUT: }
  1033. // CHECK:STDOUT: %Cpp.ref.loc11: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1034. // CHECK:STDOUT: %M_NOT_ZERO.ref: bool = name_ref M_NOT_ZERO, imports.%true.d1048d.2 [concrete = constants.%true]
  1035. // CHECK:STDOUT: %.loc11_10.1: type = splice_block %.loc11_10.3 [concrete = bool] {
  1036. // CHECK:STDOUT: %Bool.call.loc11: init type = call constants.%Bool() [concrete = bool]
  1037. // CHECK:STDOUT: %.loc11_10.2: type = value_of_initializer %Bool.call.loc11 [concrete = bool]
  1038. // CHECK:STDOUT: %.loc11_10.3: type = converted %Bool.call.loc11, %.loc11_10.2 [concrete = bool]
  1039. // CHECK:STDOUT: }
  1040. // CHECK:STDOUT: %d: bool = value_binding d, %M_NOT_ZERO.ref
  1041. // CHECK:STDOUT: name_binding_decl {
  1042. // CHECK:STDOUT: %e.patt: %pattern_type.831 = value_binding_pattern e [concrete]
  1043. // CHECK:STDOUT: }
  1044. // CHECK:STDOUT: %Cpp.ref.loc12: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1045. // CHECK:STDOUT: %M_ONE_EQ_ONE.ref: bool = name_ref M_ONE_EQ_ONE, imports.%true.d1048d.3 [concrete = constants.%true]
  1046. // CHECK:STDOUT: %.loc12_10.1: type = splice_block %.loc12_10.3 [concrete = bool] {
  1047. // CHECK:STDOUT: %Bool.call.loc12: init type = call constants.%Bool() [concrete = bool]
  1048. // CHECK:STDOUT: %.loc12_10.2: type = value_of_initializer %Bool.call.loc12 [concrete = bool]
  1049. // CHECK:STDOUT: %.loc12_10.3: type = converted %Bool.call.loc12, %.loc12_10.2 [concrete = bool]
  1050. // CHECK:STDOUT: }
  1051. // CHECK:STDOUT: %e: bool = value_binding e, %M_ONE_EQ_ONE.ref
  1052. // CHECK:STDOUT: name_binding_decl {
  1053. // CHECK:STDOUT: %f.patt: %pattern_type.831 = value_binding_pattern f [concrete]
  1054. // CHECK:STDOUT: }
  1055. // CHECK:STDOUT: %Cpp.ref.loc13: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1056. // CHECK:STDOUT: %M_ONE_NEQ_ONE.ref: bool = name_ref M_ONE_NEQ_ONE, imports.%false.505718.3 [concrete = constants.%false]
  1057. // CHECK:STDOUT: %.loc13_10.1: type = splice_block %.loc13_10.3 [concrete = bool] {
  1058. // CHECK:STDOUT: %Bool.call.loc13: init type = call constants.%Bool() [concrete = bool]
  1059. // CHECK:STDOUT: %.loc13_10.2: type = value_of_initializer %Bool.call.loc13 [concrete = bool]
  1060. // CHECK:STDOUT: %.loc13_10.3: type = converted %Bool.call.loc13, %.loc13_10.2 [concrete = bool]
  1061. // CHECK:STDOUT: }
  1062. // CHECK:STDOUT: %f: bool = value_binding f, %M_ONE_NEQ_ONE.ref
  1063. // CHECK:STDOUT: name_binding_decl {
  1064. // CHECK:STDOUT: %g.patt: %pattern_type.831 = value_binding_pattern g [concrete]
  1065. // CHECK:STDOUT: }
  1066. // CHECK:STDOUT: %Cpp.ref.loc14: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1067. // CHECK:STDOUT: %M_AND.ref: bool = name_ref M_AND, imports.%true.d1048d.4 [concrete = constants.%true]
  1068. // CHECK:STDOUT: %.loc14_10.1: type = splice_block %.loc14_10.3 [concrete = bool] {
  1069. // CHECK:STDOUT: %Bool.call.loc14: init type = call constants.%Bool() [concrete = bool]
  1070. // CHECK:STDOUT: %.loc14_10.2: type = value_of_initializer %Bool.call.loc14 [concrete = bool]
  1071. // CHECK:STDOUT: %.loc14_10.3: type = converted %Bool.call.loc14, %.loc14_10.2 [concrete = bool]
  1072. // CHECK:STDOUT: }
  1073. // CHECK:STDOUT: %g: bool = value_binding g, %M_AND.ref
  1074. // CHECK:STDOUT: name_binding_decl {
  1075. // CHECK:STDOUT: %h.patt: %pattern_type.831 = value_binding_pattern h [concrete]
  1076. // CHECK:STDOUT: }
  1077. // CHECK:STDOUT: %Cpp.ref.loc15: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1078. // CHECK:STDOUT: %M_OR.ref: bool = name_ref M_OR, imports.%true.d1048d.5 [concrete = constants.%true]
  1079. // CHECK:STDOUT: %.loc15_10.1: type = splice_block %.loc15_10.3 [concrete = bool] {
  1080. // CHECK:STDOUT: %Bool.call.loc15: init type = call constants.%Bool() [concrete = bool]
  1081. // CHECK:STDOUT: %.loc15_10.2: type = value_of_initializer %Bool.call.loc15 [concrete = bool]
  1082. // CHECK:STDOUT: %.loc15_10.3: type = converted %Bool.call.loc15, %.loc15_10.2 [concrete = bool]
  1083. // CHECK:STDOUT: }
  1084. // CHECK:STDOUT: %h: bool = value_binding h, %M_OR.ref
  1085. // CHECK:STDOUT: name_binding_decl {
  1086. // CHECK:STDOUT: %i.patt: %pattern_type.831 = value_binding_pattern i [concrete]
  1087. // CHECK:STDOUT: }
  1088. // CHECK:STDOUT: %Cpp.ref.loc16: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1089. // CHECK:STDOUT: %M_COMPLEX.ref: bool = name_ref M_COMPLEX, imports.%true.d1048d.6 [concrete = constants.%true]
  1090. // CHECK:STDOUT: %.loc16_10.1: type = splice_block %.loc16_10.3 [concrete = bool] {
  1091. // CHECK:STDOUT: %Bool.call.loc16: init type = call constants.%Bool() [concrete = bool]
  1092. // CHECK:STDOUT: %.loc16_10.2: type = value_of_initializer %Bool.call.loc16 [concrete = bool]
  1093. // CHECK:STDOUT: %.loc16_10.3: type = converted %Bool.call.loc16, %.loc16_10.2 [concrete = bool]
  1094. // CHECK:STDOUT: }
  1095. // CHECK:STDOUT: %i: bool = value_binding i, %M_COMPLEX.ref
  1096. // CHECK:STDOUT: name_binding_decl {
  1097. // CHECK:STDOUT: %j.patt: %pattern_type.7ce = value_binding_pattern j [concrete]
  1098. // CHECK:STDOUT: }
  1099. // CHECK:STDOUT: %Cpp.ref.loc18: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1100. // CHECK:STDOUT: <elided>
  1101. // CHECK:STDOUT: %M_ONE.ref: %i32 = name_ref M_ONE, imports.%int_1 [concrete = constants.%int_1]
  1102. // CHECK:STDOUT: %.loc18: type = splice_block %i32.loc18 [concrete = constants.%i32] {
  1103. // CHECK:STDOUT: %int_32.loc18: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  1104. // CHECK:STDOUT: %i32.loc18: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  1105. // CHECK:STDOUT: }
  1106. // CHECK:STDOUT: %j: %i32 = value_binding j, %M_ONE.ref
  1107. // CHECK:STDOUT: name_binding_decl {
  1108. // CHECK:STDOUT: %k.patt: %pattern_type.7ce = value_binding_pattern k [concrete]
  1109. // CHECK:STDOUT: }
  1110. // CHECK:STDOUT: %Cpp.ref.loc19: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1111. // CHECK:STDOUT: <elided>
  1112. // CHECK:STDOUT: %M_ZERO.ref: %i32 = name_ref M_ZERO, imports.%int_0 [concrete = constants.%int_0]
  1113. // CHECK:STDOUT: %.loc19: type = splice_block %i32.loc19 [concrete = constants.%i32] {
  1114. // CHECK:STDOUT: %int_32.loc19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  1115. // CHECK:STDOUT: %i32.loc19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  1116. // CHECK:STDOUT: }
  1117. // CHECK:STDOUT: %k: %i32 = value_binding k, %M_ZERO.ref
  1118. // CHECK:STDOUT: <elided>
  1119. // CHECK:STDOUT: }
  1120. // CHECK:STDOUT:
  1121. // CHECK:STDOUT: --- import_macro_redefined.carbon
  1122. // CHECK:STDOUT:
  1123. // CHECK:STDOUT: constants {
  1124. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  1125. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  1126. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  1127. // CHECK:STDOUT: %int_2: %i32 = int_value 2 [concrete]
  1128. // CHECK:STDOUT: }
  1129. // CHECK:STDOUT:
  1130. // CHECK:STDOUT: imports {
  1131. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  1132. // CHECK:STDOUT: .REDEF_NAME = %int_2
  1133. // CHECK:STDOUT: import Cpp//...
  1134. // CHECK:STDOUT: }
  1135. // CHECK:STDOUT: %int_2: %i32 = int_value 2 [concrete = constants.%int_2]
  1136. // CHECK:STDOUT: }
  1137. // CHECK:STDOUT:
  1138. // CHECK:STDOUT: fn @F() {
  1139. // CHECK:STDOUT: !entry:
  1140. // CHECK:STDOUT: name_binding_decl {
  1141. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  1142. // CHECK:STDOUT: }
  1143. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1144. // CHECK:STDOUT: <elided>
  1145. // CHECK:STDOUT: %REDEF_NAME.ref: %i32 = name_ref REDEF_NAME, imports.%int_2 [concrete = constants.%int_2]
  1146. // CHECK:STDOUT: %.loc8: type = splice_block %i32.loc8 [concrete = constants.%i32] {
  1147. // CHECK:STDOUT: %int_32.loc8: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  1148. // CHECK:STDOUT: %i32.loc8: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  1149. // CHECK:STDOUT: }
  1150. // CHECK:STDOUT: %a: %i32 = value_binding a, %REDEF_NAME.ref
  1151. // CHECK:STDOUT: <elided>
  1152. // CHECK:STDOUT: }
  1153. // CHECK:STDOUT:
  1154. // CHECK:STDOUT: --- import_macro_defined_twice.carbon
  1155. // CHECK:STDOUT:
  1156. // CHECK:STDOUT: constants {
  1157. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  1158. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  1159. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  1160. // CHECK:STDOUT: %int_2: %i32 = int_value 2 [concrete]
  1161. // CHECK:STDOUT: }
  1162. // CHECK:STDOUT:
  1163. // CHECK:STDOUT: imports {
  1164. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  1165. // CHECK:STDOUT: .TWICE_DEF = %int_2
  1166. // CHECK:STDOUT: import Cpp//...
  1167. // CHECK:STDOUT: }
  1168. // CHECK:STDOUT: %int_2: %i32 = int_value 2 [concrete = constants.%int_2]
  1169. // CHECK:STDOUT: }
  1170. // CHECK:STDOUT:
  1171. // CHECK:STDOUT: fn @F() {
  1172. // CHECK:STDOUT: !entry:
  1173. // CHECK:STDOUT: name_binding_decl {
  1174. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  1175. // CHECK:STDOUT: }
  1176. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  1177. // CHECK:STDOUT: <elided>
  1178. // CHECK:STDOUT: %TWICE_DEF.ref: %i32 = name_ref TWICE_DEF, imports.%int_2 [concrete = constants.%int_2]
  1179. // CHECK:STDOUT: %.loc17: type = splice_block %i32.loc17 [concrete = constants.%i32] {
  1180. // CHECK:STDOUT: %int_32.loc17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  1181. // CHECK:STDOUT: %i32.loc17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  1182. // CHECK:STDOUT: }
  1183. // CHECK:STDOUT: %a: %i32 = value_binding a, %TWICE_DEF.ref
  1184. // CHECK:STDOUT: <elided>
  1185. // CHECK:STDOUT: }
  1186. // CHECK:STDOUT: