aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2009-08-17 14:33:27 +0000
committerDuncan Sands <baldrick@free.fr>2009-08-17 14:33:27 +0000
commitfa6a1cf1ed4282145269b12578f687b3869d6476 (patch)
tree0e96b83a73e5615ed24d1ca49d67c1b8133f4c5d
parentafc4940466b6d573fb3adbfe20fa8922f8255165 (diff)
downloadexternal_llvm-fa6a1cf1ed4282145269b12578f687b3869d6476.zip
external_llvm-fa6a1cf1ed4282145269b12578f687b3869d6476.tar.gz
external_llvm-fa6a1cf1ed4282145269b12578f687b3869d6476.tar.bz2
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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79237 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index df49f7d..46ff307 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2156,7 +2156,7 @@ static Constant *ComputeLoadResult(Constant *P,
/// successful, false if we can't evaluate it. ActualArgs contains the formal
/// arguments for the function.
static bool EvaluateFunction(Function *F, Constant *&RetVal,
- const std::vector<Constant*> &ActualArgs,
+ const SmallVectorImpl<Constant*> &ActualArgs,
std::vector<Function*> &CallStack,
DenseMap<Constant*, Constant*> &MutatedMemory,
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)));
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();
i != e; ++i)
Formals.push_back(getVal(Values, *i));
-
+
if (Callee->isDeclaration()) {
// 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())) {
InstResult = C;
} else {
@@ -2353,8 +2353,9 @@ static bool EvaluateStaticConstructor(Function *F) {
// Call the function.
Constant *RetValDummy;
- bool EvalSuccess = EvaluateFunction(F, RetValDummy, std::vector<Constant*>(),
- CallStack, MutatedMemory, AllocaTmps);
+ bool EvalSuccess = EvaluateFunction(F, RetValDummy,
+ SmallVector<Constant*, 0>(), CallStack,
+ MutatedMemory, AllocaTmps);
if (EvalSuccess) {
// We succeeded at evaluation: commit the result.
DEBUG(errs() << "FULLY EVALUATED GLOBAL CTOR FUNCTION '"