Skip to content

Commit e0d9dec

Browse files
committed
Permit control flow mutations in global scope of a Yul program.
1 parent 16a6981 commit e0d9dec

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

test/tools/ossfuzz/protomutators/YulProtoMutator.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static addControlFlow<SwitchStmt> c4;
7373
static addControlFlow<FunctionDef> c5;
7474
static addControlFlow<CaseStmt> c6;
7575
static addControlFlow<Code> c7;
76+
static addControlFlow<Program> c8;
7677

7778
Literal* YPM::intLiteral(unsigned _value)
7879
{
@@ -261,6 +262,24 @@ Block* YPM::basicBlock(T* _msg)
261262
return _msg->mutable_case_block();
262263
else if constexpr (std::is_same_v<T, Code>)
263264
return _msg->mutable_block();
265+
else if constexpr (std::is_same_v<T, Program>)
266+
return globalBlock(_msg);
264267
else
265268
static_assert(AlwaysFalse<T>::value, "Yul proto mutator: non-exhaustive visitor.");
266269
}
270+
271+
Block* YPM::globalBlock(Program* _program)
272+
{
273+
switch (_program->program_oneof_case())
274+
{
275+
case Program::kBlock:
276+
return _program->mutable_block();
277+
case Program::kObj:
278+
return _program->mutable_obj()->mutable_code()->mutable_block();
279+
case Program::PROGRAM_ONEOF_NOT_SET:
280+
{
281+
_program->set_allocated_block(new Block());
282+
return _program->mutable_block();
283+
}
284+
}
285+
}

test/tools/ossfuzz/protomutators/YulProtoMutator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,7 @@ struct YulProtoMutator
103103
/// Obtain a basic block in a for stmt uniformly
104104
/// at random
105105
static Block* randomBlock(ForStmt* _msg);
106+
/// Obtain a basic block in global scope.
107+
static Block* globalBlock(Program* _program);
106108
};
107109
}

0 commit comments

Comments
 (0)