neq.carbon 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. // --- float_neq.carbon
  7. fn Neq(a: f64, b: f64) -> bool = "float.neq";
  8. class True {}
  9. class False {}
  10. fn F(true_: True, false_: False) {
  11. true_ as (if Neq(1.0, 2.0) then True else False);
  12. false_ as (if Neq(1.0, 1.0) then True else False);
  13. }
  14. fn RuntimeCall(a: f64, b: f64) -> bool {
  15. return Neq(a, b);
  16. }
  17. // --- fail_bad_decl.carbon
  18. package FailBadDecl api;
  19. // CHECK:STDERR: fail_bad_decl.carbon:[[@LINE+3]]:1: ERROR: Invalid signature for builtin function "float.neq".
  20. // CHECK:STDERR: fn WrongResult(a: f64, b: f64) -> f64 = "float.neq";
  21. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. fn WrongResult(a: f64, b: f64) -> f64 = "float.neq";
  23. // CHECK:STDOUT: --- float_neq.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %Neq: type = fn_type @Neq [template]
  27. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  28. // CHECK:STDOUT: %struct.1: Neq = struct_value () [template]
  29. // CHECK:STDOUT: %True: type = class_type @True [template]
  30. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  31. // CHECK:STDOUT: %False: type = class_type @False [template]
  32. // CHECK:STDOUT: %F: type = fn_type @F [template]
  33. // CHECK:STDOUT: %struct.2: F = struct_value () [template]
  34. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  35. // CHECK:STDOUT: %.4: f64 = float_literal 1 [template]
  36. // CHECK:STDOUT: %.5: f64 = float_literal 2 [template]
  37. // CHECK:STDOUT: %.6: bool = bool_literal true [template]
  38. // CHECK:STDOUT: %.7: f64 = float_literal 1 [template]
  39. // CHECK:STDOUT: %.8: f64 = float_literal 1 [template]
  40. // CHECK:STDOUT: %.9: bool = bool_literal false [template]
  41. // CHECK:STDOUT: %RuntimeCall: type = fn_type @RuntimeCall [template]
  42. // CHECK:STDOUT: %struct.3: RuntimeCall = struct_value () [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Core = %Core
  48. // CHECK:STDOUT: .Neq = %Neq.decl
  49. // CHECK:STDOUT: .True = %True.decl
  50. // CHECK:STDOUT: .False = %False.decl
  51. // CHECK:STDOUT: .F = %F.decl
  52. // CHECK:STDOUT: .RuntimeCall = %RuntimeCall.decl
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  55. // CHECK:STDOUT: %Neq.decl: Neq = fn_decl @Neq [template = constants.%struct.1] {
  56. // CHECK:STDOUT: %a.loc2_8.1: f64 = param a
  57. // CHECK:STDOUT: @Neq.%a: f64 = bind_name a, %a.loc2_8.1
  58. // CHECK:STDOUT: %b.loc2_16.1: f64 = param b
  59. // CHECK:STDOUT: @Neq.%b: f64 = bind_name b, %b.loc2_16.1
  60. // CHECK:STDOUT: @Neq.%return: ref bool = var <return slot>
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %True.decl: type = class_decl @True [template = constants.%True] {}
  63. // CHECK:STDOUT: %False.decl: type = class_decl @False [template = constants.%False] {}
  64. // CHECK:STDOUT: %F.decl: F = fn_decl @F [template = constants.%struct.2] {
  65. // CHECK:STDOUT: %True.ref: type = name_ref True, %True.decl [template = constants.%True]
  66. // CHECK:STDOUT: %true_.loc7_6.1: True = param true_
  67. // CHECK:STDOUT: @F.%true_: True = bind_name true_, %true_.loc7_6.1
  68. // CHECK:STDOUT: %False.ref: type = name_ref False, %False.decl [template = constants.%False]
  69. // CHECK:STDOUT: %false_.loc7_19.1: False = param false_
  70. // CHECK:STDOUT: @F.%false_: False = bind_name false_, %false_.loc7_19.1
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %RuntimeCall.decl: RuntimeCall = fn_decl @RuntimeCall [template = constants.%struct.3] {
  73. // CHECK:STDOUT: %a.loc12_16.1: f64 = param a
  74. // CHECK:STDOUT: @RuntimeCall.%a: f64 = bind_name a, %a.loc12_16.1
  75. // CHECK:STDOUT: %b.loc12_24.1: f64 = param b
  76. // CHECK:STDOUT: @RuntimeCall.%b: f64 = bind_name b, %b.loc12_24.1
  77. // CHECK:STDOUT: @RuntimeCall.%return: ref bool = var <return slot>
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: class @True {
  82. // CHECK:STDOUT: !members:
  83. // CHECK:STDOUT: .Self = constants.%True
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: class @False {
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = constants.%False
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @Neq(%a: f64, %b: f64) -> bool = "float.neq";
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @F(%true_: True, %false_: False) {
  94. // CHECK:STDOUT: !entry:
  95. // CHECK:STDOUT: %true_.ref: True = name_ref true_, %true_
  96. // CHECK:STDOUT: %Neq.ref.loc8: Neq = name_ref Neq, file.%Neq.decl [template = constants.%struct.1]
  97. // CHECK:STDOUT: %.loc8_20: f64 = float_literal 1 [template = constants.%.4]
  98. // CHECK:STDOUT: %.loc8_25: f64 = float_literal 2 [template = constants.%.5]
  99. // CHECK:STDOUT: %float.neq.loc8: init bool = call %Neq.ref.loc8(%.loc8_20, %.loc8_25) [template = constants.%.6]
  100. // CHECK:STDOUT: %.loc8_13.1: bool = value_of_initializer %float.neq.loc8 [template = constants.%.6]
  101. // CHECK:STDOUT: %.loc8_13.2: bool = converted %float.neq.loc8, %.loc8_13.1 [template = constants.%.6]
  102. // CHECK:STDOUT: if %.loc8_13.2 br !if.expr.then.loc8 else br !if.expr.else.loc8
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: !if.expr.then.loc8:
  105. // CHECK:STDOUT: %True.ref.loc8: type = name_ref True, file.%True.decl [template = constants.%True]
  106. // CHECK:STDOUT: br !if.expr.result.loc8(%True.ref.loc8)
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: !if.expr.else.loc8:
  109. // CHECK:STDOUT: %False.ref.loc8: type = name_ref False, file.%False.decl [template = constants.%False]
  110. // CHECK:STDOUT: br !if.expr.result.loc8(%False.ref.loc8)
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: !if.expr.result.loc8:
  113. // CHECK:STDOUT: %.loc8_13.3: type = block_arg !if.expr.result.loc8 [template = constants.%True]
  114. // CHECK:STDOUT: %false_.ref: False = name_ref false_, %false_
  115. // CHECK:STDOUT: %Neq.ref.loc9: Neq = name_ref Neq, file.%Neq.decl [template = constants.%struct.1]
  116. // CHECK:STDOUT: %.loc9_21: f64 = float_literal 1 [template = constants.%.7]
  117. // CHECK:STDOUT: %.loc9_26: f64 = float_literal 1 [template = constants.%.8]
  118. // CHECK:STDOUT: %float.neq.loc9: init bool = call %Neq.ref.loc9(%.loc9_21, %.loc9_26) [template = constants.%.9]
  119. // CHECK:STDOUT: %.loc9_14.1: bool = value_of_initializer %float.neq.loc9 [template = constants.%.9]
  120. // CHECK:STDOUT: %.loc9_14.2: bool = converted %float.neq.loc9, %.loc9_14.1 [template = constants.%.9]
  121. // CHECK:STDOUT: if %.loc9_14.2 br !if.expr.then.loc9 else br !if.expr.else.loc9
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: !if.expr.then.loc9:
  124. // CHECK:STDOUT: %True.ref.loc9: type = name_ref True, file.%True.decl [template = constants.%True]
  125. // CHECK:STDOUT: br !if.expr.result.loc9(%True.ref.loc9)
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: !if.expr.else.loc9:
  128. // CHECK:STDOUT: %False.ref.loc9: type = name_ref False, file.%False.decl [template = constants.%False]
  129. // CHECK:STDOUT: br !if.expr.result.loc9(%False.ref.loc9)
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: !if.expr.result.loc9:
  132. // CHECK:STDOUT: %.loc9_14.3: type = block_arg !if.expr.result.loc9 [template = constants.%False]
  133. // CHECK:STDOUT: return
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: fn @RuntimeCall(%a: f64, %b: f64) -> bool {
  137. // CHECK:STDOUT: !entry:
  138. // CHECK:STDOUT: %Neq.ref: Neq = name_ref Neq, file.%Neq.decl [template = constants.%struct.1]
  139. // CHECK:STDOUT: %a.ref: f64 = name_ref a, %a
  140. // CHECK:STDOUT: %b.ref: f64 = name_ref b, %b
  141. // CHECK:STDOUT: %float.neq: init bool = call %Neq.ref(%a.ref, %b.ref)
  142. // CHECK:STDOUT: %.loc13_19.1: bool = value_of_initializer %float.neq
  143. // CHECK:STDOUT: %.loc13_19.2: bool = converted %float.neq, %.loc13_19.1
  144. // CHECK:STDOUT: return %.loc13_19.2
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: --- fail_bad_decl.carbon
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: constants {
  150. // CHECK:STDOUT: %WrongResult: type = fn_type @WrongResult [template]
  151. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  152. // CHECK:STDOUT: %struct: WrongResult = struct_value () [template]
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: file {
  156. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  157. // CHECK:STDOUT: .Core = %Core
  158. // CHECK:STDOUT: .WrongResult = %WrongResult.decl
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  161. // CHECK:STDOUT: %WrongResult.decl: WrongResult = fn_decl @WrongResult [template = constants.%struct] {
  162. // CHECK:STDOUT: %a.loc7_16.1: f64 = param a
  163. // CHECK:STDOUT: @WrongResult.%a: f64 = bind_name a, %a.loc7_16.1
  164. // CHECK:STDOUT: %b.loc7_24.1: f64 = param b
  165. // CHECK:STDOUT: @WrongResult.%b: f64 = bind_name b, %b.loc7_24.1
  166. // CHECK:STDOUT: @WrongResult.%return: ref f64 = var <return slot>
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: fn @WrongResult(%a: f64, %b: f64) -> f64;
  171. // CHECK:STDOUT: