Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,18 +1368,36 @@ namespace {

ValueFlow::Value executeImpl(const Token* expr)
{
const ValueFlow::Value* value = nullptr;
if (!expr)
return unknown();
if (expr->hasKnownIntValue() && !expr->isAssignmentOp() && expr->str() != ",")
return expr->values().front();
if ((value = expr->getKnownValue(ValueFlow::Value::ValueType::FLOAT)) ||
(value = expr->getKnownValue(ValueFlow::Value::ValueType::TOK)) ||
(value = expr->getKnownValue(ValueFlow::Value::ValueType::ITERATOR_START)) ||
(value = expr->getKnownValue(ValueFlow::Value::ValueType::ITERATOR_END)) ||
(value = expr->getKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE))) {
return *value;
const ValueFlow::Value* value = nullptr;
for (const auto& val : expr->values())
{
if (!val.isKnown())
continue;
switch (val.valueType) {
case ValueFlow::Value::ValueType::INT: {
if (!expr->isAssignmentOp() && expr->str() != ",")
return expr->values().front();
break;
}
case ValueFlow::Value::ValueType::FLOAT:
case ValueFlow::Value::ValueType::TOK:
case ValueFlow::Value::ValueType::ITERATOR_START:
case ValueFlow::Value::ValueType::ITERATOR_END:
case ValueFlow::Value::ValueType::CONTAINER_SIZE: {
assert(!value);
value = &val;
break;
}
default:
break;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to make this a function that returns a pointer to the value. Then we can just write if((const ValueFlow::Value* value = findKnownValue(expr->values()))) here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

But then we would need to exclude the INT handling since that currently has priority and a different handling.

//if (value)
// return *value;
}
if (value)
return *value;
if (expr->isNumber()) {
if (MathLib::isFloat(expr->str()))
return unknown();
Expand Down