Files
carbon-lang/toolchain/semantics/testdata/if/fail_reachable_fallthrough.carbon
T
Richard Smith 4b69264cb1 Add implied return; at end of non-value-returning functions. (#2942)
Add validation that every code block in a function is terminated by a sequence of terminating instructions, and that terminators don't appear anywhere else in code blocks.

This required tracking whether we're in a reachable code block. That's done on the fly when we create a new code block; the new `SemanticsNodeBlockId::Unreachable` is used to represent the case where we're not actually creating a code block because we're in unreachable code.
2023-06-26 15:17:47 -07:00

144 lines
4.7 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
// CHECK:STDOUT: cross_reference_irs_size: 1
// CHECK:STDOUT: functions: [
// CHECK:STDOUT: {name: str0, param_refs: block2, return_type: type1, body: {block4, block5, block6, block7}}},
// CHECK:STDOUT: {name: str2, param_refs: block9, return_type: type1, body: {block10, block11, block12, block13}}},
// CHECK:STDOUT: {name: str3, param_refs: block15, return_type: type1, body: {block16, block17, block18}}},
// CHECK:STDOUT: ]
// CHECK:STDOUT: integer_literals: [
// CHECK:STDOUT: 1,
// CHECK:STDOUT: 2,
// CHECK:STDOUT: 1,
// CHECK:STDOUT: ]
// CHECK:STDOUT: real_literals: [
// CHECK:STDOUT: ]
// CHECK:STDOUT: strings: [
// CHECK:STDOUT: If1,
// CHECK:STDOUT: b,
// CHECK:STDOUT: If2,
// CHECK:STDOUT: If3,
// CHECK:STDOUT: ]
// CHECK:STDOUT: types: [
// CHECK:STDOUT: nodeBoolType,
// CHECK:STDOUT: nodeIntegerType,
// CHECK:STDOUT: ]
// CHECK:STDOUT: nodes: [
// CHECK:STDOUT: {kind: VarStorage, type: type0},
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+0, type: type0},
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function0},
// CHECK:STDOUT: {kind: BranchIf, arg0: block5, arg1: node+0},
// CHECK:STDOUT: {kind: Branch, arg0: block6},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int0, type: type1},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+5, type: type1},
// CHECK:STDOUT: {kind: Branch, arg0: block7},
// CHECK:STDOUT: {kind: VarStorage, type: type0},
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+8, type: type0},
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function1},
// CHECK:STDOUT: {kind: BranchIf, arg0: block11, arg1: node+8},
// CHECK:STDOUT: {kind: Branch, arg0: block12},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int1, type: type1},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+13, type: type1},
// CHECK:STDOUT: {kind: Branch, arg0: block13},
// CHECK:STDOUT: {kind: VarStorage, type: type0},
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+16, type: type0},
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function2},
// CHECK:STDOUT: {kind: BranchIf, arg0: block17, arg1: node+16},
// CHECK:STDOUT: {kind: Branch, arg0: block18},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int2, type: type1},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+21, type: type1},
// CHECK:STDOUT: {kind: Branch, arg0: block18},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+0,
// CHECK:STDOUT: node+1,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+1,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+2,
// CHECK:STDOUT: node+10,
// CHECK:STDOUT: node+18,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+3,
// CHECK:STDOUT: node+4,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+5,
// CHECK:STDOUT: node+6,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+7,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+8,
// CHECK:STDOUT: node+9,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+9,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+11,
// CHECK:STDOUT: node+12,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+15,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+13,
// CHECK:STDOUT: node+14,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+16,
// CHECK:STDOUT: node+17,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+17,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+19,
// CHECK:STDOUT: node+20,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: node+21,
// CHECK:STDOUT: node+22,
// CHECK:STDOUT: ],
// CHECK:STDOUT: [
// CHECK:STDOUT: ],
// CHECK:STDOUT: ]
fn If1(b: bool) -> i32 {
if (b) {
return 1;
} else {
}
// CHECK:STDERR: fail_reachable_fallthrough.carbon:[[@LINE+1]]:1: Missing `return` at end of function with declared return type.
}
fn If2(b: bool) -> i32 {
if (b) {
} else {
return 2;
}
// CHECK:STDERR: fail_reachable_fallthrough.carbon:[[@LINE+1]]:1: Missing `return` at end of function with declared return type.
}
fn If3(b: bool) -> i32 {
if (b) {
return 1;
}
// CHECK:STDERR: fail_reachable_fallthrough.carbon:[[@LINE+1]]:1: Missing `return` at end of function with declared return type.
}