translate-c: check for noreturn in switch in more cases

This commit is contained in:
Veikka Tuominen 2021-02-22 21:23:17 +02:00
parent f3ee10b454
commit d83698ab54
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
3 changed files with 18 additions and 7 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
\\ {