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 
9 #include "llvm/FuzzMutate/OpDescriptor.h"
10 #include "llvm/IR/Constants.h"
11 
12 using namespace llvm;
13 using namespace fuzzerop;
14 
15 void fuzzerop::makeConstantsWithType(Type *T, std::vector<Constant *> &Cs) {
16   if (auto *IntTy = dyn_cast<IntegerType>(T)) {
17     uint64_t W = IntTy->getBitWidth();
18     Cs.push_back(ConstantInt::get(IntTy, APInt::getMaxValue(W)));
19     Cs.push_back(ConstantInt::get(IntTy, APInt::getMinValue(W)));
20     Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMaxValue(W)));
21     Cs.push_back(ConstantInt::get(IntTy, APInt::getSignedMinValue(W)));
22     Cs.push_back(ConstantInt::get(IntTy, APInt::getOneBitSet(W, W / 2)));
23   } else if (T->isFloatingPointTy()) {
24     auto &Ctx = T->getContext();
25     auto &Sem = T->getFltSemantics();
26     Cs.push_back(ConstantFP::get(Ctx, APFloat::getZero(Sem)));
27     Cs.push_back(ConstantFP::get(Ctx, APFloat::getLargest(Sem)));
28     Cs.push_back(ConstantFP::get(Ctx, APFloat::getSmallest(Sem)));
29   } else
30     Cs.push_back(UndefValue::get(T));
31 }
32 
33 std::vector<Constant *> fuzzerop::makeConstantsWithType(Type *T) {
34   std::vector<Constant *> Result;
35   makeConstantsWithType(T, Result);
36   return Result;
37 }
38