diff options
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/AutoUpgrade.cpp | 1 | ||||
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 21 | ||||
-rw-r--r-- | lib/VMCore/Core.cpp | 1 | ||||
-rw-r--r-- | lib/VMCore/Instructions.cpp | 17 | ||||
-rw-r--r-- | lib/VMCore/Value.cpp | 2 |
5 files changed, 27 insertions, 15 deletions
diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp index 4d0eb1c..53e97f4 100644 --- a/lib/VMCore/AutoUpgrade.cpp +++ b/lib/VMCore/AutoUpgrade.cpp @@ -18,6 +18,7 @@ #include "llvm/Instructions.h" #include "llvm/ParameterAttributes.h" #include "llvm/Intrinsics.h" +#include <cstring> using namespace llvm; diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 06dc9dc..451190f 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -660,25 +660,28 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, case Instruction::Xor: return ConstantInt::get(C1V ^ C2V); case Instruction::Shl: - if (uint32_t shiftAmt = C2V.getZExtValue()) + if (uint32_t shiftAmt = C2V.getZExtValue()) { if (shiftAmt < C1V.getBitWidth()) return ConstantInt::get(C1V.shl(shiftAmt)); else return UndefValue::get(C1->getType()); // too big shift is undef + } return const_cast<ConstantInt*>(CI1); // Zero shift is identity case Instruction::LShr: - if (uint32_t shiftAmt = C2V.getZExtValue()) + if (uint32_t shiftAmt = C2V.getZExtValue()) { if (shiftAmt < C1V.getBitWidth()) return ConstantInt::get(C1V.lshr(shiftAmt)); else return UndefValue::get(C1->getType()); // too big shift is undef + } return const_cast<ConstantInt*>(CI1); // Zero shift is identity case Instruction::AShr: - if (uint32_t shiftAmt = C2V.getZExtValue()) + if (uint32_t shiftAmt = C2V.getZExtValue()) { if (shiftAmt < C1V.getBitWidth()) return ConstantInt::get(C1V.ashr(shiftAmt)); else return UndefValue::get(C1->getType()); // too big shift is undef + } return const_cast<ConstantInt*>(CI1); // Zero shift is identity } } @@ -1083,18 +1086,20 @@ static ICmpInst::Predicate evaluateICmpRelation(const Constant *V1, // Ok, we ran out of things they have in common. If any leftovers // are non-zero then we have a difference, otherwise we are equal. for (; i < CE1->getNumOperands(); ++i) - if (!CE1->getOperand(i)->isNullValue()) + if (!CE1->getOperand(i)->isNullValue()) { if (isa<ConstantInt>(CE1->getOperand(i))) return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; else return ICmpInst::BAD_ICMP_PREDICATE; // Might be equal. + } for (; i < CE2->getNumOperands(); ++i) - if (!CE2->getOperand(i)->isNullValue()) + if (!CE2->getOperand(i)->isNullValue()) { if (isa<ConstantInt>(CE2->getOperand(i))) return isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; else return ICmpInst::BAD_ICMP_PREDICATE; // Might be equal. + } return ICmpInst::ICMP_EQ; } } @@ -1123,20 +1128,22 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred, if (C1->isNullValue()) { if (const GlobalValue *GV = dyn_cast<GlobalValue>(C2)) // Don't try to evaluate aliases. External weak GV can be null. - if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) + if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) { if (pred == ICmpInst::ICMP_EQ) return ConstantInt::getFalse(); else if (pred == ICmpInst::ICMP_NE) return ConstantInt::getTrue(); + } // icmp eq/ne(GV,null) -> false/true } else if (C2->isNullValue()) { if (const GlobalValue *GV = dyn_cast<GlobalValue>(C1)) // Don't try to evaluate aliases. External weak GV can be null. - if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) + if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) { if (pred == ICmpInst::ICMP_EQ) return ConstantInt::getFalse(); else if (pred == ICmpInst::ICMP_NE) return ConstantInt::getTrue(); + } } if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) { diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 0c913ff..c159bbc 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/MemoryBuffer.h" #include <cassert> #include <cstdlib> +#include <cstring> using namespace llvm; diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 959ac9b..65bc183 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -186,11 +186,12 @@ void PHINode::resizeOperands(unsigned NumOps) { /// Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const { // If the PHI node only has one incoming value, eliminate the PHI node... - if (getNumIncomingValues() == 1) + if (getNumIncomingValues() == 1) { if (getIncomingValue(0) != this) // not X = phi X return getIncomingValue(0); else return UndefValue::get(getType()); // Self cycle is dead. + } // Otherwise if all of the incoming values are the same for the PHI, replace // the PHI node with the incoming value. @@ -198,13 +199,14 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const { Value *InVal = 0; bool HasUndefInput = false; for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i) - if (isa<UndefValue>(getIncomingValue(i))) + if (isa<UndefValue>(getIncomingValue(i))) { HasUndefInput = true; - else if (getIncomingValue(i) != this) // Not the PHI node itself... + } else if (getIncomingValue(i) != this) { // Not the PHI node itself... if (InVal && getIncomingValue(i) != InVal) return 0; // Not the same, bail out. else InVal = getIncomingValue(i); + } // The only case that could cause InVal to be null is if we have a PHI node // that only has entries for itself. In this case, there is no entry into the @@ -451,8 +453,8 @@ void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()); FTy = FTy; // silence warning. - assert((NumArgs == FTy->getNumParams()) || - (FTy->isVarArg() && NumArgs > FTy->getNumParams()) && + assert(((NumArgs == FTy->getNumParams()) || + (FTy->isVarArg() && NumArgs > FTy->getNumParams())) && "Calling a function with bad signature"); for (unsigned i = 0, e = NumArgs; i != e; i++) { @@ -1037,12 +1039,13 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, if (!isa<PointerType>(Ptr)) return 0; // Type isn't a pointer type! // Handle the special case of the empty set index set... - if (NumIdx == 0) + if (NumIdx == 0) { if (AllowCompositeLeaf || cast<PointerType>(Ptr)->getElementType()->isFirstClassType()) return cast<PointerType>(Ptr)->getElementType(); else return 0; + } unsigned CurIdx = 0; while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) { @@ -2329,7 +2332,7 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS, assert(Op0Ty == Op1Ty && "Both operands to ICmp instruction are not of the same type!"); // Check that the operands are the right type - assert(Op0Ty->isInteger() || isa<PointerType>(Op0Ty) && + assert((Op0Ty->isInteger() || isa<PointerType>(Op0Ty)) && "Invalid operand types for ICmp instruction"); return; } diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 54ea5b7..7b9d7f0 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -307,7 +307,7 @@ void Value::replaceAllUsesWith(Value *New) { void User::replaceUsesOfWith(Value *From, Value *To) { if (From == To) return; // Duh what? - assert(!isa<Constant>(this) || isa<GlobalValue>(this) && + assert((!isa<Constant>(this) || isa<GlobalValue>(this)) && "Cannot call User::replaceUsesofWith on a constant!"); for (unsigned i = 0, E = getNumOperands(); i != E; ++i) |