@@ -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+
359381void 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