| 701 | }; |
| 702 | |
| 703 | void 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 | |
| 756 | class BBFuzzer : public Fuzzer { |
| 757 | const int MaxBBs = 50; |
no test coverage detected