MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / isSameSymbolicValue

Function isSameSymbolicValue

lib/vf_analyzers.cpp:519–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517 }
518
519 bool isSameSymbolicValue(const Token* tok, ValueFlow::Value* value = nullptr) const
520 {
521 if (!useSymbolicValues())
522 return false;
523 if (Token::Match(tok, "%assign%"))
524 return false;
525 const ValueFlow::Value* currValue = getValue(tok);
526 if (!currValue)
527 return false;
528 // If the same symbolic value is already there then skip
529 if (currValue->isSymbolicValue() &&
530 std::any_of(tok->values().cbegin(), tok->values().cend(), [&](const ValueFlow::Value& v) {
531 return v.isSymbolicValue() && currValue->equalValue(v);
532 }))
533 return false;
534 const bool isPoint = currValue->bound == ValueFlow::Value::Bound::Point && currValue->isIntValue();
535 const bool exact = !currValue->isIntValue() || currValue->isImpossible();
536 for (const ValueFlow::Value& v : tok->values()) {
537 if (!v.isSymbolicValue())
538 continue;
539 if (currValue->equalValue(v))
540 continue;
541 const bool toImpossible = v.isImpossible() && currValue->isKnown();
542 if (!v.isKnown() && !toImpossible)
543 continue;
544 if (exact && v.intvalue != 0 && !isPoint)
545 continue;
546 if (astIsUnsigned(tok) != astIsUnsigned(v.tokvalue))
547 continue;
548 std::vector<MathLib::bigint> r;
549 ValueFlow::Value::Bound bound = currValue->bound;
550 if (match(v.tokvalue)) {
551 r = {currValue->intvalue};
552 } else if (!exact && findMatch(v.tokvalue)) {
553 r = evaluate(Evaluate::Integral, v.tokvalue, tok);
554 if (bound == ValueFlow::Value::Bound::Point)
555 bound = v.bound;
556 }
557 if (!r.empty()) {
558 if (value) {
559 value->errorPath.insert(value->errorPath.end(), v.errorPath.cbegin(), v.errorPath.cend());
560 value->intvalue = r.front() + v.intvalue;
561 if (toImpossible)
562 value->setImpossible();
563 value->bound = bound;
564 }
565 return true;
566 }
567 }
568 return false;
569 }
570
571 Action analyzeMatch(const Token* tok, Direction d) const {
572 const Token* parent = tok->astParent();

Callers 2

analyzeTokenFunction · 0.85
updateFunction · 0.85

Calls 11

useSymbolicValuesFunction · 0.85
getValueFunction · 0.85
astIsUnsignedFunction · 0.85
findMatchFunction · 0.85
isImpossibleMethod · 0.80
isKnownMethod · 0.80
frontMethod · 0.80
matchFunction · 0.70
evaluateFunction · 0.70
emptyMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected