uint.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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/lower/testdata/builtins/uint.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/builtins/uint.carbon
  10. fn Negate(a: u64) -> u64 = "int.unegate";
  11. fn TestNegate(a: u64) -> u64 { return Negate(a); }
  12. fn Add(a: u64, b: u64) -> u64 = "int.uadd";
  13. fn TestAdd(a: u64, b: u64) -> u64 { return Add(a, b); }
  14. fn Sub(a: u64, b: u64) -> u64 = "int.usub";
  15. fn TestSub(a: u64, b: u64) -> u64 { return Sub(a, b); }
  16. fn Mul(a: u64, b: u64) -> u64 = "int.umul";
  17. fn TestMul(a: u64, b: u64) -> u64 { return Mul(a, b); }
  18. fn Div(a: u64, b: u64) -> u64 = "int.udiv";
  19. fn TestDiv(a: u64, b: u64) -> u64 { return Div(a, b); }
  20. fn Mod(a: u64, b: u64) -> u64 = "int.umod";
  21. fn TestMod(a: u64, b: u64) -> u64 { return Mod(a, b); }
  22. fn Complement(a: u64) -> u64 = "int.complement";
  23. fn TestComplement(a: u64) -> u64 { return Complement(a); }
  24. fn And(a: u64, b: u64) -> u64 = "int.and";
  25. fn TestAnd(a: u64, b: u64) -> u64 { return And(a, b); }
  26. fn Or(a: u64, b: u64) -> u64 = "int.or";
  27. fn TestOr(a: u64, b: u64) -> u64 { return Or(a, b); }
  28. fn Xor(a: u64, b: u64) -> u64 = "int.xor";
  29. fn TestXor(a: u64, b: u64) -> u64 { return Xor(a, b); }
  30. fn LeftShift(a: u64, b: u64) -> u64 = "int.left_shift";
  31. fn TestLeftShift(a: u64, b: u64) -> u64 { return LeftShift(a, b); }
  32. fn RightShift(a: u64, b: u64) -> u64 = "int.right_shift";
  33. fn TestRightShift(a: u64, b: u64) -> u64 { return RightShift(a, b); }
  34. fn Eq(a: u64, b: u64) -> bool = "int.eq";
  35. fn TestEq(a: u64, b: u64) -> bool { return Eq(a, b); }
  36. fn Neq(a: u64, b: u64) -> bool = "int.neq";
  37. fn TestNeq(a: u64, b: u64) -> bool { return Neq(a, b); }
  38. fn Less(a: u64, b: u64) -> bool = "int.less";
  39. fn TestLess(a: u64, b: u64) -> bool { return Less(a, b); }
  40. fn LessEq(a: u64, b: u64) -> bool = "int.less_eq";
  41. fn TestLessEq(a: u64, b: u64) -> bool { return LessEq(a, b); }
  42. fn Greater(a: u64, b: u64) -> bool = "int.greater";
  43. fn TestGreater(a: u64, b: u64) -> bool { return Greater(a, b); }
  44. fn GreaterEq(a: u64, b: u64) -> bool = "int.greater_eq";
  45. fn TestGreaterEq(a: u64, b: u64) -> bool { return GreaterEq(a, b); }
  46. // CHECK:STDOUT: ; ModuleID = 'uint.carbon'
  47. // CHECK:STDOUT: source_filename = "uint.carbon"
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: define i64 @_CTestNegate.Main(i64 %a) !dbg !4 {
  50. // CHECK:STDOUT: entry:
  51. // CHECK:STDOUT: %int.unegate = sub i64 0, %a, !dbg !7
  52. // CHECK:STDOUT: ret i64 %int.unegate, !dbg !8
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: define i64 @_CTestAdd.Main(i64 %a, i64 %b) !dbg !9 {
  56. // CHECK:STDOUT: entry:
  57. // CHECK:STDOUT: %int.uadd = add i64 %a, %b, !dbg !10
  58. // CHECK:STDOUT: ret i64 %int.uadd, !dbg !11
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: define i64 @_CTestSub.Main(i64 %a, i64 %b) !dbg !12 {
  62. // CHECK:STDOUT: entry:
  63. // CHECK:STDOUT: %int.usub = sub i64 %a, %b, !dbg !13
  64. // CHECK:STDOUT: ret i64 %int.usub, !dbg !14
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: define i64 @_CTestMul.Main(i64 %a, i64 %b) !dbg !15 {
  68. // CHECK:STDOUT: entry:
  69. // CHECK:STDOUT: %int.umul = mul i64 %a, %b, !dbg !16
  70. // CHECK:STDOUT: ret i64 %int.umul, !dbg !17
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: define i64 @_CTestDiv.Main(i64 %a, i64 %b) !dbg !18 {
  74. // CHECK:STDOUT: entry:
  75. // CHECK:STDOUT: %int.udiv = udiv i64 %a, %b, !dbg !19
  76. // CHECK:STDOUT: ret i64 %int.udiv, !dbg !20
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: define i64 @_CTestMod.Main(i64 %a, i64 %b) !dbg !21 {
  80. // CHECK:STDOUT: entry:
  81. // CHECK:STDOUT: %int.umod = urem i64 %a, %b, !dbg !22
  82. // CHECK:STDOUT: ret i64 %int.umod, !dbg !23
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: define i64 @_CTestComplement.Main(i64 %a) !dbg !24 {
  86. // CHECK:STDOUT: entry:
  87. // CHECK:STDOUT: %int.complement = xor i64 -1, %a, !dbg !25
  88. // CHECK:STDOUT: ret i64 %int.complement, !dbg !26
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: define i64 @_CTestAnd.Main(i64 %a, i64 %b) !dbg !27 {
  92. // CHECK:STDOUT: entry:
  93. // CHECK:STDOUT: %int.and = and i64 %a, %b, !dbg !28
  94. // CHECK:STDOUT: ret i64 %int.and, !dbg !29
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: define i64 @_CTestOr.Main(i64 %a, i64 %b) !dbg !30 {
  98. // CHECK:STDOUT: entry:
  99. // CHECK:STDOUT: %int.or = or i64 %a, %b, !dbg !31
  100. // CHECK:STDOUT: ret i64 %int.or, !dbg !32
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: define i64 @_CTestXor.Main(i64 %a, i64 %b) !dbg !33 {
  104. // CHECK:STDOUT: entry:
  105. // CHECK:STDOUT: %int.xor = xor i64 %a, %b, !dbg !34
  106. // CHECK:STDOUT: ret i64 %int.xor, !dbg !35
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: define i64 @_CTestLeftShift.Main(i64 %a, i64 %b) !dbg !36 {
  110. // CHECK:STDOUT: entry:
  111. // CHECK:STDOUT: %int.left_shift = shl i64 %a, %b, !dbg !37
  112. // CHECK:STDOUT: ret i64 %int.left_shift, !dbg !38
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: define i64 @_CTestRightShift.Main(i64 %a, i64 %b) !dbg !39 {
  116. // CHECK:STDOUT: entry:
  117. // CHECK:STDOUT: %int.right_shift = lshr i64 %a, %b, !dbg !40
  118. // CHECK:STDOUT: ret i64 %int.right_shift, !dbg !41
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: define i1 @_CTestEq.Main(i64 %a, i64 %b) !dbg !42 {
  122. // CHECK:STDOUT: entry:
  123. // CHECK:STDOUT: %int.eq = icmp eq i64 %a, %b, !dbg !43
  124. // CHECK:STDOUT: ret i1 %int.eq, !dbg !44
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: define i1 @_CTestNeq.Main(i64 %a, i64 %b) !dbg !45 {
  128. // CHECK:STDOUT: entry:
  129. // CHECK:STDOUT: %int.neq = icmp ne i64 %a, %b, !dbg !46
  130. // CHECK:STDOUT: ret i1 %int.neq, !dbg !47
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: define i1 @_CTestLess.Main(i64 %a, i64 %b) !dbg !48 {
  134. // CHECK:STDOUT: entry:
  135. // CHECK:STDOUT: %int.less = icmp ult i64 %a, %b, !dbg !49
  136. // CHECK:STDOUT: ret i1 %int.less, !dbg !50
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: define i1 @_CTestLessEq.Main(i64 %a, i64 %b) !dbg !51 {
  140. // CHECK:STDOUT: entry:
  141. // CHECK:STDOUT: %int.less_eq = icmp ule i64 %a, %b, !dbg !52
  142. // CHECK:STDOUT: ret i1 %int.less_eq, !dbg !53
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: define i1 @_CTestGreater.Main(i64 %a, i64 %b) !dbg !54 {
  146. // CHECK:STDOUT: entry:
  147. // CHECK:STDOUT: %int.greater = icmp ugt i64 %a, %b, !dbg !55
  148. // CHECK:STDOUT: ret i1 %int.greater, !dbg !56
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: define i1 @_CTestGreaterEq.Main(i64 %a, i64 %b) !dbg !57 {
  152. // CHECK:STDOUT: entry:
  153. // CHECK:STDOUT: %int.greater_eq = icmp uge i64 %a, %b, !dbg !58
  154. // CHECK:STDOUT: ret i1 %int.greater_eq, !dbg !59
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
  158. // CHECK:STDOUT: !llvm.dbg.cu = !{!2}
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
  161. // CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
  162. // CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
  163. // CHECK:STDOUT: !3 = !DIFile(filename: "uint.carbon", directory: "")
  164. // CHECK:STDOUT: !4 = distinct !DISubprogram(name: "TestNegate", linkageName: "_CTestNegate.Main", scope: null, file: !3, line: 12, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  165. // CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
  166. // CHECK:STDOUT: !6 = !{}
  167. // CHECK:STDOUT: !7 = !DILocation(line: 12, column: 39, scope: !4)
  168. // CHECK:STDOUT: !8 = !DILocation(line: 12, column: 32, scope: !4)
  169. // CHECK:STDOUT: !9 = distinct !DISubprogram(name: "TestAdd", linkageName: "_CTestAdd.Main", scope: null, file: !3, line: 15, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  170. // CHECK:STDOUT: !10 = !DILocation(line: 15, column: 44, scope: !9)
  171. // CHECK:STDOUT: !11 = !DILocation(line: 15, column: 37, scope: !9)
  172. // CHECK:STDOUT: !12 = distinct !DISubprogram(name: "TestSub", linkageName: "_CTestSub.Main", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  173. // CHECK:STDOUT: !13 = !DILocation(line: 18, column: 44, scope: !12)
  174. // CHECK:STDOUT: !14 = !DILocation(line: 18, column: 37, scope: !12)
  175. // CHECK:STDOUT: !15 = distinct !DISubprogram(name: "TestMul", linkageName: "_CTestMul.Main", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  176. // CHECK:STDOUT: !16 = !DILocation(line: 21, column: 44, scope: !15)
  177. // CHECK:STDOUT: !17 = !DILocation(line: 21, column: 37, scope: !15)
  178. // CHECK:STDOUT: !18 = distinct !DISubprogram(name: "TestDiv", linkageName: "_CTestDiv.Main", scope: null, file: !3, line: 24, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  179. // CHECK:STDOUT: !19 = !DILocation(line: 24, column: 44, scope: !18)
  180. // CHECK:STDOUT: !20 = !DILocation(line: 24, column: 37, scope: !18)
  181. // CHECK:STDOUT: !21 = distinct !DISubprogram(name: "TestMod", linkageName: "_CTestMod.Main", scope: null, file: !3, line: 27, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  182. // CHECK:STDOUT: !22 = !DILocation(line: 27, column: 44, scope: !21)
  183. // CHECK:STDOUT: !23 = !DILocation(line: 27, column: 37, scope: !21)
  184. // CHECK:STDOUT: !24 = distinct !DISubprogram(name: "TestComplement", linkageName: "_CTestComplement.Main", scope: null, file: !3, line: 30, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  185. // CHECK:STDOUT: !25 = !DILocation(line: 30, column: 43, scope: !24)
  186. // CHECK:STDOUT: !26 = !DILocation(line: 30, column: 36, scope: !24)
  187. // CHECK:STDOUT: !27 = distinct !DISubprogram(name: "TestAnd", linkageName: "_CTestAnd.Main", scope: null, file: !3, line: 33, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  188. // CHECK:STDOUT: !28 = !DILocation(line: 33, column: 44, scope: !27)
  189. // CHECK:STDOUT: !29 = !DILocation(line: 33, column: 37, scope: !27)
  190. // CHECK:STDOUT: !30 = distinct !DISubprogram(name: "TestOr", linkageName: "_CTestOr.Main", scope: null, file: !3, line: 36, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  191. // CHECK:STDOUT: !31 = !DILocation(line: 36, column: 43, scope: !30)
  192. // CHECK:STDOUT: !32 = !DILocation(line: 36, column: 36, scope: !30)
  193. // CHECK:STDOUT: !33 = distinct !DISubprogram(name: "TestXor", linkageName: "_CTestXor.Main", scope: null, file: !3, line: 39, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  194. // CHECK:STDOUT: !34 = !DILocation(line: 39, column: 44, scope: !33)
  195. // CHECK:STDOUT: !35 = !DILocation(line: 39, column: 37, scope: !33)
  196. // CHECK:STDOUT: !36 = distinct !DISubprogram(name: "TestLeftShift", linkageName: "_CTestLeftShift.Main", scope: null, file: !3, line: 42, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  197. // CHECK:STDOUT: !37 = !DILocation(line: 42, column: 50, scope: !36)
  198. // CHECK:STDOUT: !38 = !DILocation(line: 42, column: 43, scope: !36)
  199. // CHECK:STDOUT: !39 = distinct !DISubprogram(name: "TestRightShift", linkageName: "_CTestRightShift.Main", scope: null, file: !3, line: 45, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  200. // CHECK:STDOUT: !40 = !DILocation(line: 45, column: 51, scope: !39)
  201. // CHECK:STDOUT: !41 = !DILocation(line: 45, column: 44, scope: !39)
  202. // CHECK:STDOUT: !42 = distinct !DISubprogram(name: "TestEq", linkageName: "_CTestEq.Main", scope: null, file: !3, line: 48, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  203. // CHECK:STDOUT: !43 = !DILocation(line: 48, column: 44, scope: !42)
  204. // CHECK:STDOUT: !44 = !DILocation(line: 48, column: 37, scope: !42)
  205. // CHECK:STDOUT: !45 = distinct !DISubprogram(name: "TestNeq", linkageName: "_CTestNeq.Main", scope: null, file: !3, line: 51, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  206. // CHECK:STDOUT: !46 = !DILocation(line: 51, column: 45, scope: !45)
  207. // CHECK:STDOUT: !47 = !DILocation(line: 51, column: 38, scope: !45)
  208. // CHECK:STDOUT: !48 = distinct !DISubprogram(name: "TestLess", linkageName: "_CTestLess.Main", scope: null, file: !3, line: 54, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  209. // CHECK:STDOUT: !49 = !DILocation(line: 54, column: 46, scope: !48)
  210. // CHECK:STDOUT: !50 = !DILocation(line: 54, column: 39, scope: !48)
  211. // CHECK:STDOUT: !51 = distinct !DISubprogram(name: "TestLessEq", linkageName: "_CTestLessEq.Main", scope: null, file: !3, line: 57, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  212. // CHECK:STDOUT: !52 = !DILocation(line: 57, column: 48, scope: !51)
  213. // CHECK:STDOUT: !53 = !DILocation(line: 57, column: 41, scope: !51)
  214. // CHECK:STDOUT: !54 = distinct !DISubprogram(name: "TestGreater", linkageName: "_CTestGreater.Main", scope: null, file: !3, line: 60, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  215. // CHECK:STDOUT: !55 = !DILocation(line: 60, column: 49, scope: !54)
  216. // CHECK:STDOUT: !56 = !DILocation(line: 60, column: 42, scope: !54)
  217. // CHECK:STDOUT: !57 = distinct !DISubprogram(name: "TestGreaterEq", linkageName: "_CTestGreaterEq.Main", scope: null, file: !3, line: 63, type: !5, spFlags: DISPFlagDefinition, unit: !2)
  218. // CHECK:STDOUT: !58 = !DILocation(line: 63, column: 51, scope: !57)
  219. // CHECK:STDOUT: !59 = !DILocation(line: 63, column: 44, scope: !57)