mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Form a side table with constant values for each instruction. Evaluation is only supported for a few very simple kinds of instruction for now. This is not observable outside of the SemIR output, because nothing depends on expressions having a constant value phase yet.
61 lines
3.1 KiB
Plaintext
61 lines
3.1 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
|
|
|
|
// TODO: Should work with compile-time evaluation.
|
|
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+9]]:14: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
|
|
// CHECK:STDERR: let x: i32 = if true then 1 else 0;
|
|
// CHECK:STDERR: ^~~~~~~
|
|
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+6]]:14: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
|
|
// CHECK:STDERR: let x: i32 = if true then 1 else 0;
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+3]]:22: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
|
|
// CHECK:STDERR: let x: i32 = if true then 1 else 0;
|
|
// CHECK:STDERR: ^~~~~~
|
|
let x: i32 = if true then 1 else 0;
|
|
|
|
class C {
|
|
// TODO: Should work with compile-time evaluation.
|
|
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+12]]:10: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
|
|
// CHECK:STDERR: var n: if true then i32 else f64;
|
|
// CHECK:STDERR: ^~~~~~~
|
|
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+9]]:10: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
|
|
// CHECK:STDERR: var n: if true then i32 else f64;
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+6]]:10: ERROR: Cannot evaluate type expression.
|
|
// CHECK:STDERR: var n: if true then i32 else f64;
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+3]]:18: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
|
|
// CHECK:STDERR: var n: if true then i32 else f64;
|
|
// CHECK:STDERR: ^~~~~~~~
|
|
var n: if true then i32 else f64;
|
|
}
|
|
|
|
// CHECK:STDOUT: --- fail_not_in_function.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %.loc17_17: bool = bool_literal true, const
|
|
// CHECK:STDOUT: %.loc17_27: i32 = int_literal 1, const
|
|
// CHECK:STDOUT: %.loc17_34: i32 = int_literal 0, const
|
|
// CHECK:STDOUT: %.loc33: bool = bool_literal true, const
|
|
// CHECK:STDOUT: %.loc34: type = struct_type {.n: <error>}, const
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %.loc17: i32 = block_arg <unexpected instblockref block5>
|
|
// CHECK:STDOUT: %x: i32 = bind_name x, %.loc17
|
|
// CHECK:STDOUT: %C.decl = class_decl @C, ()
|
|
// CHECK:STDOUT: %C: type = class_type @C, const
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @C {
|
|
// CHECK:STDOUT: %.loc33: bool = bool_literal true, const = constants.%.loc33
|
|
// CHECK:STDOUT: if %.loc33 br !if.expr.then else br !if.expr.else
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .n = <unexpected instref inst+25>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|