mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
translate-c: check for noreturn in switch in more cases
This commit is contained in:
parent
f3ee10b454
commit
d83698ab54
@ -2374,6 +2374,9 @@ fn transSwitchProngStmtInline(
|
||||
const result = try transStmt(c, &block.base, sub, .unused);
|
||||
assert(result.tag() != .declaration);
|
||||
try block.statements.append(result);
|
||||
if (result.isNoreturn(true)) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
.DefaultStmtClass => {
|
||||
var sub = @ptrCast(*const clang.DefaultStmt, it[0]).getSubStmt();
|
||||
@ -2385,14 +2388,12 @@ fn transSwitchProngStmtInline(
|
||||
const result = try transStmt(c, &block.base, sub, .unused);
|
||||
assert(result.tag() != .declaration);
|
||||
try block.statements.append(result);
|
||||
if (result.isNoreturn(true)) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
.CompoundStmtClass => {
|
||||
const compound_stmt = @ptrCast(*const clang.CompoundStmt, it[0]);
|
||||
var child_block = try Scope.Block.init(c, &block.base, false);
|
||||
defer child_block.deinit();
|
||||
|
||||
try transCompoundStmtInline(c, compound_stmt, &child_block);
|
||||
const result = try child_block.complete(c);
|
||||
const result = try transCompoundStmt(c, &block.base, @ptrCast(*const clang.CompoundStmt, it[0]));
|
||||
try block.statements.append(result);
|
||||
if (result.isNoreturn(true)) {
|
||||
return;
|
||||
|
||||
@ -401,7 +401,7 @@ pub const Node = extern union {
|
||||
return true;
|
||||
},
|
||||
.@"return", .return_void => return true,
|
||||
.break_val, .@"break" => if (break_counts) return true,
|
||||
.@"break" => if (break_counts) return true,
|
||||
else => {},
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -2047,6 +2047,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\ res = 3 * i;
|
||||
\\ break;
|
||||
\\ break;
|
||||
\\ case 7: {
|
||||
\\ res = 7;
|
||||
\\ break;
|
||||
\\ }
|
||||
\\ case 4:
|
||||
\\ case 5:
|
||||
\\ res = 69;
|
||||
@ -2079,6 +2083,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\ else => {
|
||||
\\ res = @as(c_int, 3) * i;
|
||||
\\ },
|
||||
\\ @as(c_int, 7) => {
|
||||
\\ {
|
||||
\\ res = 7;
|
||||
\\ break;
|
||||
\\ }
|
||||
\\ },
|
||||
\\ @as(c_int, 4), @as(c_int, 5) => {
|
||||
\\ res = 69;
|
||||
\\ {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user