NFC: Formatting changes.

Run clang-format over these files.

Capitalize some variable names per clang-tidy's request.

Pulled out to simplify review of D98302.
This commit is contained in:
Nick Lewycky 2021-03-15 14:26:39 -07:00
parent 6811b96100
commit 483a253ae9
2 changed files with 145 additions and 165 deletions

View File

@ -79,7 +79,7 @@ class ConstantInt final : public ConstantData {
APInt Val;
ConstantInt(IntegerType *Ty, const APInt& V);
ConstantInt(IntegerType *Ty, const APInt &V);
void destroyConstantImpl();
@ -95,16 +95,15 @@ public:
/// If Ty is a vector type, return a Constant with a splat of the given
/// value. Otherwise return a ConstantInt for the given value.
static Constant *get(Type *Ty, uint64_t V, bool isSigned = false);
static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false);
/// Return a ConstantInt with the specified integer value for the specified
/// type. If the type is wider than 64 bits, the value will be zero-extended
/// to fit the type, unless isSigned is true, in which case the value will
/// to fit the type, unless IsSigned is true, in which case the value will
/// be interpreted as a 64-bit signed integer and sign-extended to fit
/// the type.
/// Get a ConstantInt for a specific value.
static ConstantInt *get(IntegerType *Ty, uint64_t V,
bool isSigned = false);
static ConstantInt *get(IntegerType *Ty, uint64_t V, bool IsSigned = false);
/// Return a ConstantInt with the specified value for the specified type. The
/// value V will be canonicalized to a an unsigned APInt. Accessing it with
@ -120,19 +119,16 @@ public:
/// Return a ConstantInt constructed from the string strStart with the given
/// radix.
static ConstantInt *get(IntegerType *Ty, StringRef Str,
uint8_t radix);
static ConstantInt *get(IntegerType *Ty, StringRef Str, uint8_t Radix);
/// If Ty is a vector type, return a Constant with a splat of the given
/// value. Otherwise return a ConstantInt for the given value.
static Constant *get(Type* Ty, const APInt& V);
static Constant *get(Type *Ty, const APInt &V);
/// Return the constant as an APInt value reference. This allows clients to
/// obtain a full-precision copy of the value.
/// Return the constant's value.
inline const APInt &getValue() const {
return Val;
}
inline const APInt &getValue() const { return Val; }
/// getBitWidth - Return the bitwidth of this constant.
unsigned getBitWidth() const { return Val.getBitWidth(); }
@ -141,17 +137,13 @@ public:
/// has been zero extended as appropriate for the type of this constant. Note
/// that this method can assert if the value does not fit in 64 bits.
/// Return the zero extended value.
inline uint64_t getZExtValue() const {
return Val.getZExtValue();
}
inline uint64_t getZExtValue() const { return Val.getZExtValue(); }
/// Return the constant as a 64-bit integer value after it has been sign
/// extended as appropriate for the type of this constant. Note that
/// this method can assert if the value does not fit in 64 bits.
/// Return the sign extended value.
inline int64_t getSExtValue() const {
return Val.getSExtValue();
}
inline int64_t getSExtValue() const { return Val.getSExtValue(); }
/// Return the constant as an llvm::MaybeAlign.
/// Note that this method can assert if the value does not fit in 64 bits or
@ -171,9 +163,7 @@ public:
/// within is equal to a constant. This only works for very small values,
/// because this is all that can be represented with all types.
/// Determine if this constant's value is same as an unsigned char.
bool equalsInt(uint64_t V) const {
return Val == V;
}
bool equalsInt(uint64_t V) const { return Val == V; }
/// getType - Specialize the getType() method to always return an IntegerType,
/// which reduces the amount of casting needed in parts of the compiler.
@ -199,33 +189,27 @@ public:
/// This is just a convenience method to make client code smaller for a
/// common code. It also correctly performs the comparison without the
/// potential for an assertion from getZExtValue().
bool isZero() const {
return Val.isNullValue();
}
bool isZero() const { return Val.isNullValue(); }
/// This is just a convenience method to make client code smaller for a
/// common case. It also correctly performs the comparison without the
/// potential for an assertion from getZExtValue().
/// Determine if the value is one.
bool isOne() const {
return Val.isOneValue();
}
bool isOne() const { return Val.isOneValue(); }
/// This function will return true iff every bit in this constant is set
/// to true.
/// @returns true iff this constant's bits are all set to true.
/// Determine if the value is all ones.
bool isMinusOne() const {
return Val.isAllOnesValue();
}
bool isMinusOne() const { return Val.isAllOnesValue(); }
/// This function will return true iff this constant represents the largest
/// value that may be represented by the constant's type.
/// @returns true iff this is the largest value that may be represented
/// by this type.
/// Determine if the value is maximal.
bool isMaxValue(bool isSigned) const {
if (isSigned)
bool isMaxValue(bool IsSigned) const {
if (IsSigned)
return Val.isMaxSignedValue();
else
return Val.isMaxValue();
@ -236,8 +220,8 @@ public:
/// @returns true if this is the smallest value that may be represented by
/// this type.
/// Determine if the value is minimal.
bool isMinValue(bool isSigned) const {
if (isSigned)
bool isMinValue(bool IsSigned) const {
if (IsSigned)
return Val.isMinSignedValue();
else
return Val.isMinValue();
@ -248,9 +232,7 @@ public:
/// value.
/// @returns true iff this constant is greater or equal to the given number.
/// Determine if the value is greater or equal to the given number.
bool uge(uint64_t Num) const {
return Val.uge(Num);
}
bool uge(uint64_t Num) const { return Val.uge(Num); }
/// getLimitedValue - If the value is smaller than the specified limit,
/// return it, otherwise return the limit value. This causes the value
@ -275,7 +257,7 @@ class ConstantFP final : public ConstantData {
APFloat Val;
ConstantFP(Type *Ty, const APFloat& V);
ConstantFP(Type *Ty, const APFloat &V);
void destroyConstantImpl();
@ -291,15 +273,16 @@ public:
/// for the specified value in the specified type. This should only be used
/// for simple constant values like 2.0/1.0 etc, that are known-valid both as
/// host double and as the target format.
static Constant *get(Type* Ty, double V);
static Constant *get(Type *Ty, double V);
/// If Ty is a vector type, return a Constant with a splat of the given
/// value. Otherwise return a ConstantFP for the given value.
static Constant *get(Type *Ty, const APFloat &V);
static Constant *get(Type* Ty, StringRef Str);
static Constant *get(Type *Ty, StringRef Str);
static ConstantFP *get(LLVMContext &Context, const APFloat &V);
static Constant *getNaN(Type *Ty, bool Negative = false, uint64_t Payload = 0);
static Constant *getNaN(Type *Ty, bool Negative = false,
uint64_t Payload = 0);
static Constant *getQNaN(Type *Ty, bool Negative = false,
APInt *Payload = nullptr);
static Constant *getSNaN(Type *Ty, bool Negative = false,
@ -432,7 +415,7 @@ class ConstantArray final : public ConstantAggregate {
public:
// ConstantArray accessors
static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
static Constant *get(ArrayType *T, ArrayRef<Constant *> V);
private:
static Constant *getImpl(ArrayType *T, ArrayRef<Constant *> V);
@ -464,32 +447,32 @@ class ConstantStruct final : public ConstantAggregate {
public:
// ConstantStruct accessors
static Constant *get(StructType *T, ArrayRef<Constant*> V);
static Constant *get(StructType *T, ArrayRef<Constant *> V);
template <typename... Csts>
static std::enable_if_t<are_base_of<Constant, Csts...>::value, Constant *>
get(StructType *T, Csts *... Vs) {
get(StructType *T, Csts *...Vs) {
SmallVector<Constant *, 8> Values({Vs...});
return get(T, Values);
}
/// Return an anonymous struct that has the specified elements.
/// If the struct is possibly empty, then you must specify a context.
static Constant *getAnon(ArrayRef<Constant*> V, bool Packed = false) {
static Constant *getAnon(ArrayRef<Constant *> V, bool Packed = false) {
return get(getTypeForElements(V, Packed), V);
}
static Constant *getAnon(LLVMContext &Ctx,
ArrayRef<Constant*> V, bool Packed = false) {
static Constant *getAnon(LLVMContext &Ctx, ArrayRef<Constant *> V,
bool Packed = false) {
return get(getTypeForElements(Ctx, V, Packed), V);
}
/// Return an anonymous struct type to use for a constant with the specified
/// set of elements. The list must not be empty.
static StructType *getTypeForElements(ArrayRef<Constant*> V,
static StructType *getTypeForElements(ArrayRef<Constant *> V,
bool Packed = false);
/// This version of the method allows an empty list.
static StructType *getTypeForElements(LLVMContext &Ctx,
ArrayRef<Constant*> V,
ArrayRef<Constant *> V,
bool Packed = false);
/// Specialization - reduce amount of casting.
@ -517,7 +500,7 @@ class ConstantVector final : public ConstantAggregate {
public:
// ConstantVector accessors
static Constant *get(ArrayRef<Constant*> V);
static Constant *get(ArrayRef<Constant *> V);
private:
static Constant *getImpl(ArrayRef<Constant *> V);
@ -667,7 +650,7 @@ public:
StringRef getAsCString() const {
assert(isCString() && "Isn't a C string");
StringRef Str = getAsString();
return Str.substr(0, Str.size()-1);
return Str.substr(0, Str.size() - 1);
}
/// Return the raw, underlying, bytes of this data. Note that this is an
@ -723,7 +706,8 @@ public:
/// ElementTy needs to be one of i8/i16/i32/i64/float/double. Data is the
/// buffer containing the elements. Be careful to make sure Data uses the
/// right endianness, the buffer will be used as-is.
static Constant *getRaw(StringRef Data, uint64_t NumElements, Type *ElementTy) {
static Constant *getRaw(StringRef Data, uint64_t NumElements,
Type *ElementTy) {
Type *Ty = ArrayType::get(ElementTy, NumElements);
return getImpl(Data, Ty);
}
@ -874,8 +858,8 @@ public:
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Function *getFunction() const { return (Function*)Op<0>().get(); }
BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
Function *getFunction() const { return (Function *)Op<0>().get(); }
BasicBlock *getBasicBlock() const { return (BasicBlock *)Op<1>().get(); }
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
@ -884,9 +868,8 @@ public:
};
template <>
struct OperandTraits<BlockAddress> :
public FixedNumOperandTraits<BlockAddress, 2> {
};
struct OperandTraits<BlockAddress>
: public FixedNumOperandTraits<BlockAddress, 2> {};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value)
@ -975,17 +958,18 @@ public:
///
static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false);
static Constant *getNeg(Constant *C, bool HasNUW = false,
bool HasNSW = false);
static Constant *getFNeg(Constant *C);
static Constant *getNot(Constant *C);
static Constant *getAdd(Constant *C1, Constant *C2,
bool HasNUW = false, bool HasNSW = false);
static Constant *getAdd(Constant *C1, Constant *C2, bool HasNUW = false,
bool HasNSW = false);
static Constant *getFAdd(Constant *C1, Constant *C2);
static Constant *getSub(Constant *C1, Constant *C2,
bool HasNUW = false, bool HasNSW = false);
static Constant *getSub(Constant *C1, Constant *C2, bool HasNUW = false,
bool HasNSW = false);
static Constant *getFSub(Constant *C1, Constant *C2);
static Constant *getMul(Constant *C1, Constant *C2,
bool HasNUW = false, bool HasNSW = false);
static Constant *getMul(Constant *C1, Constant *C2, bool HasNUW = false,
bool HasNSW = false);
static Constant *getFMul(Constant *C1, Constant *C2);
static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false);
@ -997,8 +981,8 @@ public:
static Constant *getOr(Constant *C1, Constant *C2);
static Constant *getXor(Constant *C1, Constant *C2);
static Constant *getUMin(Constant *C1, Constant *C2);
static Constant *getShl(Constant *C1, Constant *C2,
bool HasNUW = false, bool HasNSW = false);
static Constant *getShl(Constant *C1, Constant *C2, bool HasNUW = false,
bool HasNSW = false);
static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
@ -1107,48 +1091,47 @@ public:
bool OnlyIfReduced = false);
// Create a ZExt or BitCast cast constant expression
static Constant *getZExtOrBitCast(
Constant *C, ///< The constant to zext or bitcast
Type *Ty ///< The type to zext or bitcast C to
static Constant *
getZExtOrBitCast(Constant *C, ///< The constant to zext or bitcast
Type *Ty ///< The type to zext or bitcast C to
);
// Create a SExt or BitCast cast constant expression
static Constant *getSExtOrBitCast(
Constant *C, ///< The constant to sext or bitcast
Type *Ty ///< The type to sext or bitcast C to
static Constant *
getSExtOrBitCast(Constant *C, ///< The constant to sext or bitcast
Type *Ty ///< The type to sext or bitcast C to
);
// Create a Trunc or BitCast cast constant expression
static Constant *getTruncOrBitCast(
Constant *C, ///< The constant to trunc or bitcast
Type *Ty ///< The type to trunc or bitcast C to
static Constant *
getTruncOrBitCast(Constant *C, ///< The constant to trunc or bitcast
Type *Ty ///< The type to trunc or bitcast C to
);
/// Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant
/// expression.
static Constant *getPointerCast(
Constant *C, ///< The pointer value to be casted (operand 0)
Type *Ty ///< The type to which cast should be made
static Constant *
getPointerCast(Constant *C, ///< The pointer value to be casted (operand 0)
Type *Ty ///< The type to which cast should be made
);
/// Create a BitCast or AddrSpaceCast for a pointer type depending on
/// the address space.
static Constant *getPointerBitCastOrAddrSpaceCast(
Constant *C, ///< The constant to addrspacecast or bitcast
Type *Ty ///< The type to bitcast or addrspacecast C to
Constant *C, ///< The constant to addrspacecast or bitcast
Type *Ty ///< The type to bitcast or addrspacecast C to
);
/// Create a ZExt, Bitcast or Trunc for integer -> integer casts
static Constant *getIntegerCast(
Constant *C, ///< The integer constant to be casted
Type *Ty, ///< The integer type to cast to
bool isSigned ///< Whether C should be treated as signed or not
static Constant *
getIntegerCast(Constant *C, ///< The integer constant to be casted
Type *Ty, ///< The integer type to cast to
bool IsSigned ///< Whether C should be treated as signed or not
);
/// Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
static Constant *getFPCast(
Constant *C, ///< The integer constant to be casted
Type *Ty ///< The integer type to cast to
static Constant *getFPCast(Constant *C, ///< The integer constant to be casted
Type *Ty ///< The integer type to cast to
);
/// Return true if this is a convert constant expression
@ -1178,7 +1161,7 @@ public:
/// folding if possible.
///
/// \param OnlyIfReducedTy see \a getWithOperands() docs.
static Constant *get(unsigned Opcode, Constant *C1, unsigned Flags = 0,
static Constant *get(unsigned Opcode, Constant *C1, unsigned Flags = 0,
Type *OnlyIfReducedTy = nullptr);
/// get - Return a binary or shift operator constant expression,
@ -1213,7 +1196,7 @@ public:
Optional<unsigned> InRangeIndex = None,
Type *OnlyIfReducedTy = nullptr) {
return getGetElementPtr(
Ty, C, makeArrayRef((Value * const *)IdxList.data(), IdxList.size()),
Ty, C, makeArrayRef((Value *const *)IdxList.data(), IdxList.size()),
InBounds, InRangeIndex, OnlyIfReducedTy);
}
static Constant *getGetElementPtr(Type *Ty, Constant *C, Constant *Idx,
@ -1294,7 +1277,7 @@ public:
/// This returns the current constant expression with the operands replaced
/// with the specified values. The specified array must have the same number
/// of operands as our current one.
Constant *getWithOperands(ArrayRef<Constant*> Ops) const {
Constant *getWithOperands(ArrayRef<Constant *> Ops) const {
return getWithOperands(Ops, getType());
}
@ -1334,9 +1317,8 @@ private:
};
template <>
struct OperandTraits<ConstantExpr> :
public VariadicOperandTraits<ConstantExpr, 1> {
};
struct OperandTraits<ConstantExpr>
: public VariadicOperandTraits<ConstantExpr, 1> {};
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)

View File

@ -23,11 +23,11 @@ namespace {
TEST(ConstantsTest, Integer_i1) {
LLVMContext Context;
IntegerType *Int1 = IntegerType::get(Context, 1);
Constant* One = ConstantInt::get(Int1, 1, true);
Constant* Zero = ConstantInt::get(Int1, 0);
Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true);
Constant *One = ConstantInt::get(Int1, 1, true);
Constant *Zero = ConstantInt::get(Int1, 0);
Constant *NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true);
EXPECT_EQ(NegOne, ConstantInt::getSigned(Int1, -1));
Constant* Undef = UndefValue::get(Int1);
Constant *Undef = UndefValue::get(Int1);
// Input: @b = constant i1 add(i1 1 , i1 1)
// Output: @b = constant i1 false
@ -136,35 +136,33 @@ TEST(ConstantsTest, PointerCast) {
VectorType *Int64VecTy = FixedVectorType::get(Int64Ty, 4);
// ptrtoint i8* to i64
EXPECT_EQ(Constant::getNullValue(Int64Ty),
ConstantExpr::getPointerCast(
Constant::getNullValue(Int8PtrTy), Int64Ty));
EXPECT_EQ(
Constant::getNullValue(Int64Ty),
ConstantExpr::getPointerCast(Constant::getNullValue(Int8PtrTy), Int64Ty));
// bitcast i8* to i32*
EXPECT_EQ(Constant::getNullValue(Int32PtrTy),
ConstantExpr::getPointerCast(
Constant::getNullValue(Int8PtrTy), Int32PtrTy));
ConstantExpr::getPointerCast(Constant::getNullValue(Int8PtrTy),
Int32PtrTy));
// ptrtoint <4 x i8*> to <4 x i64>
EXPECT_EQ(Constant::getNullValue(Int64VecTy),
ConstantExpr::getPointerCast(
Constant::getNullValue(Int8PtrVecTy), Int64VecTy));
ConstantExpr::getPointerCast(Constant::getNullValue(Int8PtrVecTy),
Int64VecTy));
// bitcast <4 x i8*> to <4 x i32*>
EXPECT_EQ(Constant::getNullValue(Int32PtrVecTy),
ConstantExpr::getPointerCast(
Constant::getNullValue(Int8PtrVecTy), Int32PtrVecTy));
ConstantExpr::getPointerCast(Constant::getNullValue(Int8PtrVecTy),
Int32PtrVecTy));
Type *Int32Ptr1Ty = Type::getInt32PtrTy(C, 1);
ConstantInt *K = ConstantInt::get(Type::getInt64Ty(C), 1234);
// Make sure that addrspacecast of inttoptr is not folded away.
EXPECT_NE(K,
ConstantExpr::getAddrSpaceCast(
ConstantExpr::getIntToPtr(K, Int32PtrTy), Int32Ptr1Ty));
EXPECT_NE(K,
ConstantExpr::getAddrSpaceCast(
ConstantExpr::getIntToPtr(K, Int32Ptr1Ty), Int32PtrTy));
EXPECT_NE(K, ConstantExpr::getAddrSpaceCast(
ConstantExpr::getIntToPtr(K, Int32PtrTy), Int32Ptr1Ty));
EXPECT_NE(K, ConstantExpr::getAddrSpaceCast(
ConstantExpr::getIntToPtr(K, Int32Ptr1Ty), Int32PtrTy));
Constant *NullInt32Ptr0 = Constant::getNullValue(Int32PtrTy);
Constant *NullInt32Ptr1 = Constant::getNullValue(Int32Ptr1Ty);
@ -199,10 +197,10 @@ TEST(ConstantsTest, AsInstructionsTest) {
Type *FloatTy = Type::getFloatTy(Context);
Type *DoubleTy = Type::getDoubleTy(Context);
Constant *Global = M->getOrInsertGlobal("dummy",
PointerType::getUnqual(Int32Ty));
Constant *Global2 = M->getOrInsertGlobal("dummy2",
PointerType::getUnqual(Int32Ty));
Constant *Global =
M->getOrInsertGlobal("dummy", PointerType::getUnqual(Int32Ty));
Constant *Global2 =
M->getOrInsertGlobal("dummy2", PointerType::getUnqual(Int32Ty));
Constant *P0 = ConstantExpr::getPtrToInt(Global, Int32Ty);
Constant *P1 = ConstantExpr::getUIToFP(P0, FloatTy);
@ -217,26 +215,26 @@ TEST(ConstantsTest, AsInstructionsTest) {
Constant *Big = ConstantInt::get(Context, APInt{256, uint64_t(-1), true});
Constant *Elt = ConstantInt::get(Int16Ty, 2015);
Constant *Poison16 = PoisonValue::get(Int16Ty);
Constant *Undef64 = UndefValue::get(Int64Ty);
Constant *Undef64 = UndefValue::get(Int64Ty);
Constant *UndefV16 = UndefValue::get(P6->getType());
Constant *PoisonV16 = PoisonValue::get(P6->getType());
#define P0STR "ptrtoint (i32** @dummy to i32)"
#define P1STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to float)"
#define P2STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to double)"
#define P3STR "ptrtoint (i32** @dummy to i1)"
#define P4STR "ptrtoint (i32** @dummy2 to i32)"
#define P5STR "uitofp (i32 ptrtoint (i32** @dummy2 to i32) to float)"
#define P6STR "bitcast (i32 ptrtoint (i32** @dummy2 to i32) to <2 x i16>)"
#define P0STR "ptrtoint (i32** @dummy to i32)"
#define P1STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to float)"
#define P2STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to double)"
#define P3STR "ptrtoint (i32** @dummy to i1)"
#define P4STR "ptrtoint (i32** @dummy2 to i32)"
#define P5STR "uitofp (i32 ptrtoint (i32** @dummy2 to i32) to float)"
#define P6STR "bitcast (i32 ptrtoint (i32** @dummy2 to i32) to <2 x i16>)"
CHECK(ConstantExpr::getNeg(P0), "sub i32 0, " P0STR);
CHECK(ConstantExpr::getFNeg(P1), "fneg float " P1STR);
CHECK(ConstantExpr::getNot(P0), "xor i32 " P0STR ", -1");
CHECK(ConstantExpr::getAdd(P0, P0), "add i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getAdd(P0, P0, false, true), "add nsw i32 " P0STR ", "
P0STR);
CHECK(ConstantExpr::getAdd(P0, P0, true, true), "add nuw nsw i32 " P0STR ", "
P0STR);
CHECK(ConstantExpr::getAdd(P0, P0, false, true),
"add nsw i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getAdd(P0, P0, true, true),
"add nuw nsw i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getFAdd(P1, P1), "fadd float " P1STR ", " P1STR);
CHECK(ConstantExpr::getSub(P0, P0), "sub i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getFSub(P1, P1), "fsub float " P1STR ", " P1STR);
@ -253,48 +251,50 @@ TEST(ConstantsTest, AsInstructionsTest) {
CHECK(ConstantExpr::getXor(P0, P0), "xor i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getShl(P0, P0), "shl i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getShl(P0, P0, true), "shl nuw i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getShl(P0, P0, false, true), "shl nsw i32 " P0STR ", "
P0STR);
CHECK(ConstantExpr::getShl(P0, P0, false, true),
"shl nsw i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getLShr(P0, P0, false), "lshr i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getLShr(P0, P0, true), "lshr exact i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getLShr(P0, P0, true),
"lshr exact i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getAShr(P0, P0, false), "ashr i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getAShr(P0, P0, true), "ashr exact i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getAShr(P0, P0, true),
"ashr exact i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getSExt(P0, Int64Ty), "sext i32 " P0STR " to i64");
CHECK(ConstantExpr::getZExt(P0, Int64Ty), "zext i32 " P0STR " to i64");
CHECK(ConstantExpr::getFPTrunc(P2, FloatTy), "fptrunc double " P2STR
" to float");
CHECK(ConstantExpr::getFPExtend(P1, DoubleTy), "fpext float " P1STR
" to double");
CHECK(ConstantExpr::getFPTrunc(P2, FloatTy),
"fptrunc double " P2STR " to float");
CHECK(ConstantExpr::getFPExtend(P1, DoubleTy),
"fpext float " P1STR " to double");
CHECK(ConstantExpr::getExactUDiv(P0, P0), "udiv exact i32 " P0STR ", " P0STR);
CHECK(ConstantExpr::getSelect(P3, P0, P4), "select i1 " P3STR ", i32 " P0STR
", i32 " P4STR);
CHECK(ConstantExpr::getICmp(CmpInst::ICMP_EQ, P0, P4), "icmp eq i32 " P0STR
", " P4STR);
CHECK(ConstantExpr::getFCmp(CmpInst::FCMP_ULT, P1, P5), "fcmp ult float "
P1STR ", " P5STR);
CHECK(ConstantExpr::getSelect(P3, P0, P4),
"select i1 " P3STR ", i32 " P0STR ", i32 " P4STR);
CHECK(ConstantExpr::getICmp(CmpInst::ICMP_EQ, P0, P4),
"icmp eq i32 " P0STR ", " P4STR);
CHECK(ConstantExpr::getFCmp(CmpInst::FCMP_ULT, P1, P5),
"fcmp ult float " P1STR ", " P5STR);
std::vector<Constant*> V;
std::vector<Constant *> V;
V.push_back(One);
// FIXME: getGetElementPtr() actually creates an inbounds ConstantGEP,
// not a normal one!
//CHECK(ConstantExpr::getGetElementPtr(Global, V, false),
// CHECK(ConstantExpr::getGetElementPtr(Global, V, false),
// "getelementptr i32*, i32** @dummy, i32 1");
CHECK(ConstantExpr::getInBoundsGetElementPtr(PointerType::getUnqual(Int32Ty),
Global, V),
"getelementptr inbounds i32*, i32** @dummy, i32 1");
CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> "
P6STR ", i32 1");
CHECK(ConstantExpr::getExtractElement(P6, One),
"extractelement <2 x i16> " P6STR ", i32 1");
EXPECT_EQ(Poison16, ConstantExpr::getExtractElement(P6, Two));
EXPECT_EQ(Poison16, ConstantExpr::getExtractElement(P6, Big));
EXPECT_EQ(Poison16, ConstantExpr::getExtractElement(P6, Undef64));
EXPECT_EQ(Elt, ConstantExpr::getExtractElement(
ConstantExpr::getInsertElement(P6, Elt, One), One));
ConstantExpr::getInsertElement(P6, Elt, One), One));
EXPECT_EQ(UndefV16, ConstantExpr::getInsertElement(P6, Elt, Two));
EXPECT_EQ(UndefV16, ConstantExpr::getInsertElement(P6, Elt, Big));
EXPECT_EQ(PoisonV16, ConstantExpr::getInsertElement(P6, Elt, Undef64));
@ -469,8 +469,8 @@ TEST(ConstantsTest, BitcastToGEP) {
Type *EltTys[] = {i32, U};
auto *S = StructType::create(EltTys);
auto *G = new GlobalVariable(*M, S, false,
GlobalValue::ExternalLinkage, nullptr);
auto *G =
new GlobalVariable(*M, S, false, GlobalValue::ExternalLinkage, nullptr);
auto *PtrTy = PointerType::get(i32, 0);
auto *C = ConstantExpr::getBitCast(G, PtrTy);
ASSERT_EQ(cast<ConstantExpr>(C)->getOpcode(), Instruction::BitCast);
@ -481,8 +481,8 @@ bool foldFuncPtrAndConstToNull(LLVMContext &Context, Module *TheModule,
MaybeAlign FunctionAlign = llvm::None) {
Type *VoidType(Type::getVoidTy(Context));
FunctionType *FuncType(FunctionType::get(VoidType, false));
Function *Func(Function::Create(
FuncType, GlobalValue::ExternalLinkage, "", TheModule));
Function *Func(
Function::Create(FuncType, GlobalValue::ExternalLinkage, "", TheModule));
if (FunctionAlign)
Func->setAlignment(*FunctionAlign);
@ -490,19 +490,18 @@ bool foldFuncPtrAndConstToNull(LLVMContext &Context, Module *TheModule,
IntegerType *ConstantIntType(Type::getInt32Ty(Context));
ConstantInt *TheConstant(ConstantInt::get(ConstantIntType, AndValue));
Constant *TheConstantExpr(
ConstantExpr::getPtrToInt(Func, ConstantIntType));
Constant *TheConstantExpr(ConstantExpr::getPtrToInt(Func, ConstantIntType));
bool result = ConstantExpr::get(Instruction::And, TheConstantExpr,
TheConstant)->isNullValue();
bool Result =
ConstantExpr::get(Instruction::And, TheConstantExpr, TheConstant)
->isNullValue();
if (!TheModule) {
// If the Module exists then it will delete the Function.
delete Func;
}
return result;
return Result;
}
TEST(ConstantsTest, FoldFunctionPtrAlignUnknownAnd2) {
@ -525,7 +524,7 @@ TEST(ConstantsTest, DontFoldFunctionPtrAlignUnknownAnd4) {
TEST(ConstantsTest, FoldFunctionPtrAlign4) {
LLVMContext Context;
Module TheModule("TestModule", Context);
const char* AlignmentStrings[] = { "Fi32", "Fn32" };
const char *AlignmentStrings[] = {"Fi32", "Fn32"};
for (unsigned AndValue = 1; AndValue <= 2; ++AndValue) {
for (const char *AlignmentString : AlignmentStrings) {
@ -538,9 +537,9 @@ TEST(ConstantsTest, FoldFunctionPtrAlign4) {
TEST(ConstantsTest, DontFoldFunctionPtrAlign1) {
LLVMContext Context;
Module TheModule("TestModule", Context);
const char* AlignmentStrings[] = { "Fi8", "Fn8" };
const char *AlignmentStrings[] = {"Fi8", "Fn8"};
for (const char* AlignmentString : AlignmentStrings) {
for (const char *AlignmentString : AlignmentStrings) {
TheModule.setDataLayout(AlignmentString);
ASSERT_FALSE(foldFuncPtrAndConstToNull(Context, &TheModule, 2));
}
@ -579,11 +578,10 @@ TEST(ConstantsTest, FoldGlobalVariablePtr) {
ConstantInt *TheConstant(ConstantInt::get(IntType, 2));
Constant *TheConstantExpr(
ConstantExpr::getPtrToInt(Global.get(), IntType));
Constant *TheConstantExpr(ConstantExpr::getPtrToInt(Global.get(), IntType));
ASSERT_TRUE(ConstantExpr::get( \
Instruction::And, TheConstantExpr, TheConstant)->isNullValue());
ASSERT_TRUE(ConstantExpr::get(Instruction::And, TheConstantExpr, TheConstant)
->isNullValue());
}
// Check that containsUndefOrPoisonElement and containsPoisonElement is working
@ -713,5 +711,5 @@ TEST(ConstantsTest, GetSplatValueRoundTrip) {
}
}
} // end anonymous namespace
} // end namespace llvm
} // end anonymous namespace
} // end namespace llvm