OpDescriptor.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //===-- OpDescriptor.cpp --------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/FuzzMutate/OpDescriptor.h"
  9. #include "llvm/IR/Constants.h"
  10. using namespace llvm;
  11. using namespace fuzzerop;
  12. void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
  13. if (auto *IntTy = dyn_cast<IntegerType>(T)) {
  14. uint64_t W = IntTy->getBitWidth();
  15. Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));
  16. Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));
  17. Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));
  18. Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));
  19. Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));
  20. } else if (T->isFloatingPointTy()) {
  21. auto &Ctx = T->getContext();
  22. auto &Sem = T->getFltSemantics();
  23. Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));
  24. Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));
  25. Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));
  26. } else
  27. Cs.push_back(UndefValue::get(T));
  28. }
  29. std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {
  30. std::vector<Constant *> Result;
  31. makeConstantsWithType(T, Result);
  32. return Result;
  33. }