Skip to content

Commit f1534b0

Browse files
committed
[FuzzMutate] Refactor code determining whether the target function is unsupported.
1 parent a6532bd commit f1534b0

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

llvm/include/llvm/FuzzMutate/IRMutator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ class LLVM_ABI InsertFunctionStrategy : public IRMutationStrategy {
144144

145145
using IRMutationStrategy::mutate;
146146
void mutate(BasicBlock &BB, RandomIRBuilder &IB) override;
147+
148+
private:
149+
bool isUnsupportedFunction(Function *F);
147150
};
148151

149152
/// Strategy to split a random block and insert a random CFG in between.

llvm/lib/FuzzMutate/IRMutator.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,28 @@ static uint64_t getUniqueCaseValue(SmallSet<uint64_t, 4> &CasesTaken,
356356
return tmp;
357357
}
358358

359+
bool InsertFunctionStrategy::isUnsupportedFunction(Function *F) {
360+
// Some functions accept metadata type or token type as arguments.
361+
// We don't call those functions for now.
362+
// For example, `@llvm.dbg.declare(metadata, metadata, metadata)`
363+
// https://llvm.org/docs/SourceLevelDebugging.html#llvm-dbg-declare
364+
auto IsUnsupportedTy = [](Type *T) {
365+
return T->isMetadataTy() || T->isTokenTy();
366+
};
367+
368+
if (IsUnsupportedTy(F->getReturnType()) ||
369+
any_of(F->getFunctionType()->params(), IsUnsupportedTy)) {
370+
return true;
371+
}
372+
373+
// If it is not satisfied, the IR will be invalid.
374+
if (!isCallableCC(F->getCallingConv())) {
375+
return true;
376+
}
377+
378+
return false;
379+
}
380+
359381
void InsertFunctionStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
360382
Module *M = BB.getParent()->getParent();
361383
// If nullptr is selected, we will create a new function declaration.
@@ -366,16 +388,8 @@ void InsertFunctionStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
366388

367389
auto RS = makeSampler(IB.Rand, Functions);
368390
Function *F = RS.getSelection();
369-
// Some functions accept metadata type or token type as arguments.
370-
// We don't call those functions for now.
371-
// For example, `@llvm.dbg.declare(metadata, metadata, metadata)`
372-
// https://llvm.org/docs/SourceLevelDebugging.html#llvm-dbg-declare
373-
auto IsUnsupportedTy = [](Type *T) {
374-
return T->isMetadataTy() || T->isTokenTy();
375-
};
376-
if (!F || IsUnsupportedTy(F->getReturnType()) ||
377-
any_of(F->getFunctionType()->params(), IsUnsupportedTy) ||
378-
!isCallableCC(F->getCallingConv())) {
391+
392+
if (!F || isUnsupportedFunction(F)) {
379393
F = IB.createFunctionDeclaration(*M);
380394
}
381395

0 commit comments

Comments
 (0)