translate_c: prevent a while under an if from stealing the else

This commit is contained in:
Matthew Borkowski
2021-10-19 03:45:18 -04:00
committed by Andrew Kelley
parent 135cb529de
commit 2d7b55aa0a
2 changed files with 40 additions and 9 deletions

View File

@@ -1767,4 +1767,21 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
\\ return 0;
\\}
, "");
cases.add("Ensure while loop under an if doesn't steal the else. Issue #9953",
\\#include <stdio.h>
\\void doWork(int id) { }
\\int reallyDelete(int id) { printf("deleted %d\n", id); return 1; }
\\int process(int id, int n, int delete) {
\\ if(!delete)
\\ while(n-- > 0) doWork(id);
\\ else
\\ return reallyDelete(id);
\\ return 0;
\\}
\\int main(void) {
\\ process(99, 3, 0);
\\ return 0;
\\}
, "");
}