diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 86b49c0b137..7aa0ce4aac6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1511,7 +1511,7 @@ ValueFlow::Value ValueFlow::getLifetimeObjValue(const Token *tok, bool inconclus // There should only be one lifetime if (values.size() != 1) return ValueFlow::Value{}; - return values.front(); + return std::move(values.front()); } template @@ -3652,7 +3652,7 @@ static void valueFlowSymbolicOperators(const SymbolDatabase& symboldatabase, con continue; ValueFlow::Value v = makeSymbolic(arg); - v.errorPath = c.errorPath; + v.errorPath = std::move(c.errorPath); v.errorPath.emplace_back(tok, "Passed to " + tok->str()); if (c.intvalue == 0) v.setImpossible(); @@ -5070,8 +5070,7 @@ static void valueFlowInferCondition(TokenList& tokenlist, const Settings& settin std::vector result = infer(makeIntegralInferModel(), "!=", tok->values(), 0); if (result.size() != 1) continue; - ValueFlow::Value value = result.front(); - setTokenValue(tok, std::move(value), settings); + setTokenValue(tok, std::move(result.front()), settings); } } } @@ -5490,7 +5489,7 @@ static void valueFlowInjectParameter(const TokenList& tokenlist, const Settings& settings, const Variable* arg, const Scope* functionScope, - const std::list& argvalues) + std::list argvalues) { // Is argument passed by value or const reference, and is it a known non-class type? if (arg->isReference() && !arg->isConst() && !arg->isClass()) @@ -5504,7 +5503,7 @@ static void valueFlowInjectParameter(const TokenList& tokenlist, valueFlowForward(const_cast(functionScope->bodyStart->next()), functionScope->bodyEnd, arg->nameToken(), - argvalues, + std::move(argvalues), tokenlist, errorLogger, settings); @@ -5731,7 +5730,7 @@ static void valueFlowFunctionDefaultParameter(const TokenList& tokenlist, const argvalues.push_back(std::move(v)); } if (!argvalues.empty()) - valueFlowInjectParameter(tokenlist, errorLogger, settings, var, scope, argvalues); + valueFlowInjectParameter(tokenlist, errorLogger, settings, var, scope, std::move(argvalues)); } } } diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index 4d39d35daae..b2647bf46ec 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -126,32 +126,31 @@ namespace ValueFlow return value.isIntValue() || value.isFloatValue(); } - static void setTokenValueCast(Token *parent, const ValueType &valueType, const Value &value, const Settings &settings) + static void setTokenValueCast(Token *parent, const ValueType &valueType, Value value, const Settings &settings) { if (valueType.pointer || value.isImpossible()) - setTokenValue(parent,value,settings); + setTokenValue(parent,std::move(value),settings); else if (valueType.type == ValueType::Type::CHAR) - setTokenValue(parent, castValue(value, valueType.sign, settings.platform.char_bit), settings); + setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.char_bit), settings); else if (valueType.type == ValueType::Type::SHORT) - setTokenValue(parent, castValue(value, valueType.sign, settings.platform.short_bit), settings); + setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.short_bit), settings); else if (valueType.type == ValueType::Type::INT) - setTokenValue(parent, castValue(value, valueType.sign, settings.platform.int_bit), settings); + setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.int_bit), settings); else if (valueType.type == ValueType::Type::LONG) - setTokenValue(parent, castValue(value, valueType.sign, settings.platform.long_bit), settings); + setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.long_bit), settings); else if (valueType.type == ValueType::Type::LONGLONG) - setTokenValue(parent, castValue(value, valueType.sign, settings.platform.long_long_bit), settings); + setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.long_long_bit), settings); else if (valueType.isFloat() && isNumeric(value)) { - Value floatValue = value; - floatValue.valueType = Value::ValueType::FLOAT; if (value.isIntValue()) - floatValue.floatValue = static_cast(value.intvalue); - setTokenValue(parent, std::move(floatValue), settings); + value.floatValue = static_cast(value.intvalue); + value.valueType = Value::ValueType::FLOAT; + setTokenValue(parent, std::move(value), settings); } else if (value.isIntValue()) { const long long charMax = settings.platform.signedCharMax(); const long long charMin = settings.platform.signedCharMin(); if (charMin <= value.intvalue && value.intvalue <= charMax) { // unknown type, but value is small so there should be no truncation etc - setTokenValue(parent,value,settings); + setTokenValue(parent,std::move(value),settings); } } } @@ -307,22 +306,23 @@ namespace ValueFlow value.valueType = Value::ValueType::INT; setTokenValue(next, std::move(value), settings); } else if (yields == Library::Container::Yield::EMPTY) { - Value v(value); - v.valueType = Value::ValueType::INT; - v.bound = Value::Bound::Point; + const Value::Bound bound = value.bound; + const long long intvalue = value.intvalue; + value.valueType = Value::ValueType::INT; + value.bound = Value::Bound::Point; if (value.isImpossible()) { - if (value.intvalue == 0) - v.setKnown(); - else if ((value.bound == Value::Bound::Upper && value.intvalue > 0) || - (value.bound == Value::Bound::Lower && value.intvalue < 0)) { - v.intvalue = 0; - v.setKnown(); + if (intvalue == 0) + value.setKnown(); + else if ((bound == Value::Bound::Upper && intvalue > 0) || + (bound == Value::Bound::Lower && intvalue < 0)) { + value.intvalue = 0; + value.setKnown(); } else - v.setPossible(); + value.setPossible(); } else { - v.intvalue = !v.intvalue; + value.intvalue = !value.intvalue; } - setTokenValue(next, std::move(v), settings); + setTokenValue(next, std::move(value), settings); } return; } @@ -346,27 +346,26 @@ namespace ValueFlow setTokenValue(parent, std::move(value), settings); return; } - Value pvalue = value; if (!value.subexpressions.empty() && Token::Match(parent, ". %var%")) { if (contains(value.subexpressions, parent->strAt(1))) - pvalue.subexpressions.clear(); + value.subexpressions.clear(); else return; } if (parent->isUnaryOp("&")) { - pvalue.indirect++; - setTokenValue(parent, std::move(pvalue), settings); + value.indirect++; + setTokenValue(parent, std::move(value), settings); } else if (Token::Match(parent, ". %var%") && parent->astOperand1() == tok && parent->astOperand2()) { - if (parent->originalName() == "->" && pvalue.indirect > 0) - pvalue.indirect--; - setTokenValue(parent->astOperand2(), std::move(pvalue), settings); + if (parent->originalName() == "->" && value.indirect > 0) + value.indirect--; + setTokenValue(parent->astOperand2(), std::move(value), settings); } else if (Token::Match(parent->astParent(), ". %var%") && parent->astParent()->astOperand1() == parent) { - if (parent->astParent()->originalName() == "->" && pvalue.indirect > 0) - pvalue.indirect--; - setTokenValue(parent->astParent()->astOperand2(), std::move(pvalue), settings); - } else if (parent->isUnaryOp("*") && pvalue.indirect > 0) { - pvalue.indirect--; - setTokenValue(parent, std::move(pvalue), settings); + if (parent->astParent()->originalName() == "->" && value.indirect > 0) + value.indirect--; + setTokenValue(parent->astParent()->astOperand2(), std::move(value), settings); + } else if (parent->isUnaryOp("*") && value.indirect > 0) { + value.indirect--; + setTokenValue(parent, std::move(value), settings); } return; } @@ -382,7 +381,7 @@ namespace ValueFlow && tok->valueType()->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer) >= valueType.getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer)) return; - setTokenValueCast(parent, valueType, value, settings); + setTokenValueCast(parent, valueType, std::move(value), settings); } else if (parent->str() == ":") { @@ -421,11 +420,10 @@ namespace ValueFlow if (ret) return; - Value v(std::move(value)); - v.conditional = true; - v.changeKnownToPossible(); + value.conditional = true; + value.changeKnownToPossible(); - setTokenValue(parent, std::move(v), settings); + setTokenValue(parent, std::move(value), settings); } } @@ -713,15 +711,13 @@ namespace ValueFlow std::vector args = getArguments(value.tokvalue); if (const Library::Function* f = settings.library.getFunction(parent->previous())) { if (f->containerYield == Library::Container::Yield::SIZE) { - Value v(std::move(value)); - v.valueType = Value::ValueType::INT; - v.intvalue = args.size(); - setTokenValue(parent, std::move(v), settings); + value.valueType = Value::ValueType::INT; + value.intvalue = args.size(); + setTokenValue(parent, std::move(value), settings); } else if (f->containerYield == Library::Container::Yield::EMPTY) { - Value v(std::move(value)); - v.intvalue = args.empty(); - v.valueType = Value::ValueType::INT; - setTokenValue(parent, std::move(v), settings); + value.intvalue = args.empty(); + value.valueType = Value::ValueType::INT; + setTokenValue(parent, std::move(value), settings); } } }