diff --git a/test/tools/ossfuzz/SolidityGenerator.cpp b/test/tools/ossfuzz/SolidityGenerator.cpp index e7ccf0cbc..0d71a8516 100644 --- a/test/tools/ossfuzz/SolidityGenerator.cpp +++ b/test/tools/ossfuzz/SolidityGenerator.cpp @@ -518,10 +518,15 @@ string WhileStmtGenerator::visit() pair boolTypeName = {boolType, {}}; auto expression = exprGen.rLValueOrLiteral(boolTypeName); solAssert(expression.has_value(), ""); - whileStmt << indentation() - << "while (" - << expression.value().second - << ")\n"; + bool doWhile = uRandDist()->probable(2); + if (doWhile) + whileStmt << indentation() + << "do\n"; + else + whileStmt << indentation() + << "while (" + << expression.value().second + << ")\n"; // Make sure block stmt generator does not output an unchecked block mutator->generator()->unchecked(false); ostringstream whileBlock; @@ -529,6 +534,11 @@ string WhileStmtGenerator::visit() if (whileBlock.str().empty()) whileBlock << indentation() << "{ }\n"; whileStmt << whileBlock.str(); + if (doWhile) + whileStmt << indentation() + << "while (" + << expression.value().second + << ")\n"; return whileStmt.str(); } diff --git a/test/tools/ossfuzz/SolidityGenerator.h b/test/tools/ossfuzz/SolidityGenerator.h index 6323ada3c..35649f25a 100644 --- a/test/tools/ossfuzz/SolidityGenerator.h +++ b/test/tools/ossfuzz/SolidityGenerator.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -525,7 +526,7 @@ struct TestState numFunctions(0), indentationLevel(0), insideContract(false), - loopState(false, false) + loopState({false}) {} /// Adds @param _path to @name sourceUnitPaths updates /// @name currentSourceUnitPath. @@ -652,16 +653,15 @@ struct TestState } void enterLoop() { - loopState.wasLoop = loopState.inLoop; - loopState.inLoop = true; + loopState.push(true); } void exitLoop() { - loopState.inLoop = loopState.wasLoop; + loopState.pop(); } bool inLoop() { - return loopState.inLoop; + return loopState.top(); } ~TestState() { @@ -703,7 +703,7 @@ struct TestState /// Contract scope bool insideContract; /// Loop state - LoopState loopState; + std::stack loopState; /// Source name prefix std::string const sourceUnitNamePrefix = "su"; /// Contract name prefix