MCPcopy Create free account
hub / github.com/AliveToolkit/alive2 / go

Method go

tools/quick-fuzz.cpp:703–754  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

701};
702
703void ValueFuzzer::go() {
704 assert(!gone);
705 gone = true;
706
707 const int NumIntParams = 1 + C.choose(MaxIntParams);
708 auto *RetTy = Type::getIntNTy(Ctx, VG.getWidth());
709 vector<Type *> ParamsTy, ParamsRealTy;
710 for (int i = 0; i < NumIntParams; ++i) {
711 auto *origTy = Type::getIntNTy(Ctx, VG.getWidth());
712 auto *realTy =
713 C.flip() ? (Type *)origTy : (Type *)PointerType::get(Ctx, 0);
714 ParamsRealTy.push_back(origTy);
715 ParamsTy.push_back(realTy);
716 }
717 auto *FTy = FunctionType::get(RetTy, ParamsTy, false);
718 auto *F = Function::Create(FTy, GlobalValue::ExternalLinkage, 0, "f", &M);
719 if (C.flip()) {
720 F->addRetAttr(C.flip() ? Attribute::ZExt : Attribute::SExt);
721 }
722 if (C.choose(4) == 0)
723 F->addRetAttr(Attribute::NoUndef);
724 auto BB = BasicBlock::Create(Ctx, "", F);
725 VG.setBB(BB);
726
727 vector<Value *> PointerParams;
728 int idx = 0;
729 for (auto &arg : F->args()) {
730 VG.addVal(&arg);
731 if (arg.getType()->isPointerTy()) {
732 PointerParams.push_back(&arg);
733 VG.addArgTy(arg, ParamsRealTy[idx]);
734 } else {
735 if (C.flip()) {
736 arg.addAttr(C.flip() ? Attribute::ZExt : Attribute::SExt);
737 }
738 }
739 if (C.choose(4) == 0)
740 arg.addAttr(Attribute::NoUndef);
741 ++idx;
742 }
743
744 int num_insts = C.choose(MaxInsts);
745 for (int i = 0; i < num_insts; ++i) {
746 auto *v = VG.genInst();
747 if (C.choose(4) == 0 && !PointerParams.empty()) {
748 auto *p = PointerParams[C.choose(PointerParams.size())];
749 new StoreInst(VG.adapt(v, VG.getArgTy(p)), p, BB);
750 }
751 }
752
753 ReturnInst::Create(Ctx, VG.getVal(RetTy), BB);
754}
755
756class BBFuzzer : public Fuzzer {
757 const int MaxBBs = 50;

Callers 1

mainFunction · 0.80

Calls 13

chooseMethod · 0.80
getWidthMethod · 0.80
flipMethod · 0.80
setBBMethod · 0.80
addValMethod · 0.80
addArgTyMethod · 0.80
genInstMethod · 0.80
adaptMethod · 0.80
getArgTyMethod · 0.80
getValMethod · 0.80
randomPredMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected