Files
carbon-lang/toolchain/check/testdata/if_expr/basic.carbon
T
Jon Ross-Perkins 30155dbb72 Add support for 'package' in expressions. (#3445)
This creates a namespace for `package` scope.

It looks like names of class_decls in namespaces lead to an unexpected
instref. This is already true, as best as I can tell. I'm not sure if
there's a preferred approach to address that, so I've left a TODO for
now.
2023-12-04 21:05:41 +00:00

40 lines
1.4 KiB
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
fn F(b: bool, n: i32, m: i32) -> i32 {
return if b then n + m else m + n;
}
// CHECK:STDOUT: --- basic.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {.F = %F}
// CHECK:STDOUT: %F: <function> = fn_decl @F
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F(%b: bool, %n: i32, %m: i32) -> i32 {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %b.ref: bool = name_ref b, %b
// CHECK:STDOUT: if %b.ref br !if.expr.then else br !if.expr.else
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.then:
// CHECK:STDOUT: %n.ref.loc8_20: i32 = name_ref n, %n
// CHECK:STDOUT: %m.ref.loc8_24: i32 = name_ref m, %m
// CHECK:STDOUT: %.loc8_22: i32 = add %n.ref.loc8_20, %m.ref.loc8_24
// CHECK:STDOUT: br !if.expr.result(%.loc8_22)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.else:
// CHECK:STDOUT: %m.ref.loc8_31: i32 = name_ref m, %m
// CHECK:STDOUT: %n.ref.loc8_35: i32 = name_ref n, %n
// CHECK:STDOUT: %.loc8_33: i32 = add %m.ref.loc8_31, %n.ref.loc8_35
// CHECK:STDOUT: br !if.expr.result(%.loc8_33)
// CHECK:STDOUT:
// CHECK:STDOUT: !if.expr.result:
// CHECK:STDOUT: %.loc8_10: i32 = block_arg !if.expr.result
// CHECK:STDOUT: return %.loc8_10
// CHECK:STDOUT: }
// CHECK:STDOUT: