unary_op.carbon 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/operators/builtin/unary_op.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/builtin/unary_op.carbon
  10. fn Not(b: bool) -> bool {
  11. return not b;
  12. }
  13. let not_true: bool = not true;
  14. let not_false: bool = not false;
  15. fn Constant() {
  16. var a: if not true then bool else () = ();
  17. var b: if not false then bool else () = true;
  18. }
  19. // CHECK:STDOUT: --- unary_op.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  23. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  24. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  25. // CHECK:STDOUT: %Not.type: type = fn_type @Not [template]
  26. // CHECK:STDOUT: %Not: %Not.type = struct_value () [template]
  27. // CHECK:STDOUT: %true: bool = bool_literal true [template]
  28. // CHECK:STDOUT: %false: bool = bool_literal false [template]
  29. // CHECK:STDOUT: %Constant.type: type = fn_type @Constant [template]
  30. // CHECK:STDOUT: %Constant: %Constant.type = struct_value () [template]
  31. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [template]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  36. // CHECK:STDOUT: .Bool = %import_ref
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .Not = %Not.decl
  46. // CHECK:STDOUT: .not_true = @__global_init.%not_true
  47. // CHECK:STDOUT: .not_false = @__global_init.%not_false
  48. // CHECK:STDOUT: .Constant = %Constant.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core.import = import Core
  51. // CHECK:STDOUT: %Not.decl: %Not.type = fn_decl @Not [template = constants.%Not] {
  52. // CHECK:STDOUT: %b.patt: bool = binding_pattern b
  53. // CHECK:STDOUT: %b.param_patt: bool = value_param_pattern %b.patt, runtime_param0
  54. // CHECK:STDOUT: %return.patt: bool = return_slot_pattern
  55. // CHECK:STDOUT: %return.param_patt: bool = out_param_pattern %return.patt, runtime_param1
  56. // CHECK:STDOUT: } {
  57. // CHECK:STDOUT: %bool.make_type.loc11_20: init type = call constants.%Bool() [template = bool]
  58. // CHECK:STDOUT: %.loc11_20.1: type = value_of_initializer %bool.make_type.loc11_20 [template = bool]
  59. // CHECK:STDOUT: %.loc11_20.2: type = converted %bool.make_type.loc11_20, %.loc11_20.1 [template = bool]
  60. // CHECK:STDOUT: %b.param: bool = value_param runtime_param0
  61. // CHECK:STDOUT: %.loc11_11.1: type = splice_block %.loc11_11.3 [template = bool] {
  62. // CHECK:STDOUT: %bool.make_type.loc11_11: init type = call constants.%Bool() [template = bool]
  63. // CHECK:STDOUT: %.loc11_11.2: type = value_of_initializer %bool.make_type.loc11_11 [template = bool]
  64. // CHECK:STDOUT: %.loc11_11.3: type = converted %bool.make_type.loc11_11, %.loc11_11.2 [template = bool]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %b: bool = bind_name b, %b.param
  67. // CHECK:STDOUT: %return.param: ref bool = out_param runtime_param1
  68. // CHECK:STDOUT: %return: ref bool = return_slot %return.param
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %Constant.decl: %Constant.type = fn_decl @Constant [template = constants.%Constant] {} {}
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @Not(%b.param_patt: bool) -> bool {
  74. // CHECK:STDOUT: !entry:
  75. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  76. // CHECK:STDOUT: %.loc12: bool = not %b.ref
  77. // CHECK:STDOUT: return %.loc12
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @Constant() {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %a.var: ref %empty_tuple.type = var a
  83. // CHECK:STDOUT: %a: ref %empty_tuple.type = bind_name a, %a.var
  84. // CHECK:STDOUT: %.loc19_43.1: %empty_tuple.type = tuple_literal ()
  85. // CHECK:STDOUT: %.loc19_43.2: init %empty_tuple.type = tuple_init () to %a.var [template = constants.%empty_tuple]
  86. // CHECK:STDOUT: %.loc19_44: init %empty_tuple.type = converted %.loc19_43.1, %.loc19_43.2 [template = constants.%empty_tuple]
  87. // CHECK:STDOUT: assign %a.var, %.loc19_44
  88. // CHECK:STDOUT: %b.var: ref bool = var b
  89. // CHECK:STDOUT: %b: ref bool = bind_name b, %b.var
  90. // CHECK:STDOUT: %true: bool = bool_literal true [template = constants.%true]
  91. // CHECK:STDOUT: assign %b.var, %true
  92. // CHECK:STDOUT: return
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn @__global_init() {
  96. // CHECK:STDOUT: !entry:
  97. // CHECK:STDOUT: %true: bool = bool_literal true [template = constants.%true]
  98. // CHECK:STDOUT: %.loc15: bool = not %true [template = constants.%false]
  99. // CHECK:STDOUT: %not_true: bool = bind_name not_true, %.loc15
  100. // CHECK:STDOUT: %false: bool = bool_literal false [template = constants.%false]
  101. // CHECK:STDOUT: %.loc16: bool = not %false [template = constants.%true]
  102. // CHECK:STDOUT: %not_false: bool = bind_name not_false, %.loc16
  103. // CHECK:STDOUT: return
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: