Don't access the first element of a potentially empty

vector (&Formals[0]).  With this change llvm-gcc builds
with expensive checking enabled for C, C++ and Fortran.
While there, change a std::vector into a SmallVector.
This is partly gratuitous, but mostly because not all
STL vector implementations define the data method (and
it should be faster).

llvm-svn: 79237
This commit is contained in:
Duncan Sands 2009-08-17 14:33:27 +00:00
parent b562444cf8
commit c4ce58d8fe
1 changed files with 7 additions and 6 deletions

View File

@ -2156,7 +2156,7 @@ static Constant *ComputeLoadResult(Constant *P,
/// successful, false if we can't evaluate it. ActualArgs contains the formal /// successful, false if we can't evaluate it. ActualArgs contains the formal
/// arguments for the function. /// arguments for the function.
static bool EvaluateFunction(Function *F, Constant *&RetVal, static bool EvaluateFunction(Function *F, Constant *&RetVal,
const std::vector<Constant*> &ActualArgs, const SmallVectorImpl<Constant*> &ActualArgs,
std::vector<Function*> &CallStack, std::vector<Function*> &CallStack,
DenseMap<Constant*, Constant*> &MutatedMemory, DenseMap<Constant*, Constant*> &MutatedMemory,
std::vector<GlobalVariable*> &AllocaTmps) { std::vector<GlobalVariable*> &AllocaTmps) {
@ -2251,14 +2251,14 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
Function *Callee = dyn_cast<Function>(getVal(Values, CI->getOperand(0))); Function *Callee = dyn_cast<Function>(getVal(Values, CI->getOperand(0)));
if (!Callee) return false; // Cannot resolve. if (!Callee) return false; // Cannot resolve.
std::vector<Constant*> Formals; SmallVector<Constant*, 8> Formals;
for (User::op_iterator i = CI->op_begin() + 1, e = CI->op_end(); for (User::op_iterator i = CI->op_begin() + 1, e = CI->op_end();
i != e; ++i) i != e; ++i)
Formals.push_back(getVal(Values, *i)); Formals.push_back(getVal(Values, *i));
if (Callee->isDeclaration()) { if (Callee->isDeclaration()) {
// If this is a function we can constant fold, do it. // If this is a function we can constant fold, do it.
if (Constant *C = ConstantFoldCall(Callee, &Formals[0], if (Constant *C = ConstantFoldCall(Callee, Formals.data(),
Formals.size())) { Formals.size())) {
InstResult = C; InstResult = C;
} else { } else {
@ -2353,8 +2353,9 @@ static bool EvaluateStaticConstructor(Function *F) {
// Call the function. // Call the function.
Constant *RetValDummy; Constant *RetValDummy;
bool EvalSuccess = EvaluateFunction(F, RetValDummy, std::vector<Constant*>(), bool EvalSuccess = EvaluateFunction(F, RetValDummy,
CallStack, MutatedMemory, AllocaTmps); SmallVector<Constant*, 0>(), CallStack,
MutatedMemory, AllocaTmps);
if (EvalSuccess) { if (EvalSuccess) {
// We succeeded at evaluation: commit the result. // We succeeded at evaluation: commit the result.
DEBUG(errs() << "FULLY EVALUATED GLOBAL CTOR FUNCTION '" DEBUG(errs() << "FULLY EVALUATED GLOBAL CTOR FUNCTION '"