mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
c: don't generate while(condition) loops due to UB in C spec
See https://www.iso-9899.info/n1570.html#6.8.5p6 Fix #885
This commit is contained in:
parent
c95af17eae
commit
393cd7f807
|
@ -1245,13 +1245,15 @@ public class CodeGenerationVisitor implements ExprVisitor, StatementVisitor {
|
||||||
|
|
||||||
int statementId = registerIdentifiedStatement(statement);
|
int statementId = registerIdentifiedStatement(statement);
|
||||||
|
|
||||||
writer.print("while (");
|
writer.println("while (1) {").indent();
|
||||||
|
|
||||||
|
// This can't be moved to 'while', since C11 standard allows removing infinite loops
|
||||||
|
// See https://www.iso-9899.info/n1570.html#6.8.5p6
|
||||||
if (statement.getCondition() != null) {
|
if (statement.getCondition() != null) {
|
||||||
|
writer.print("if (!");
|
||||||
statement.getCondition().acceptVisitor(this);
|
statement.getCondition().acceptVisitor(this);
|
||||||
} else {
|
writer.println(") break;");
|
||||||
writer.print("1");
|
|
||||||
}
|
}
|
||||||
writer.println(") {").indent();
|
|
||||||
|
|
||||||
boolean oldEnd = end;
|
boolean oldEnd = end;
|
||||||
for (Statement part : statement.getBody()) {
|
for (Statement part : statement.getBody()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user