@@ -3742,24 +3742,28 @@ static void valueFlowSymbolicOperators(const SymbolDatabase& symboldatabase, con
37423742 if (Token::Match (tok, " <<|>>|/|-" ) && !astIsLHS (vartok))
37433743 continue ;
37443744 if (Token::Match (tok, " +|-" ) && constant->intvalue != 0 ) {
3745- std::unordered_set<nonneg int > ids;
3746- for (const auto &value : vartok->values ()) {
3747- if (!value.isSymbolicValue ())
3748- continue ;
3749- if (!value.isKnown ())
3750- continue ;
3751- if (!value.tokvalue )
3752- continue ;
3753- if (!ids.insert (value.tokvalue ->exprId ()).second )
3754- continue ;
3755- const bool add = tok->str () == " +" ;
3756- if (add && MathLib::additionWouldOverflow (value.intvalue , constant->intvalue ))
3757- continue ;
3758- if (!add && MathLib::subtractionWouldOverflow (value.intvalue , constant->intvalue ))
3759- continue ;
3760- ValueFlow::Value newValue (value);
3761- newValue.intvalue = add ? newValue.intvalue + constant->intvalue : newValue.intvalue - constant->intvalue ;
3762- setTokenValue (tok, std::move (newValue), settings);
3745+ const ValueType *vt = vartok->valueType ();
3746+ const bool promoted = vt && vt->pointer == 0 && vt->type < ValueType::Type::INT ;
3747+ if (!promoted) {
3748+ std::unordered_set<nonneg int > ids;
3749+ for (const auto &value : vartok->values ()) {
3750+ if (!value.isSymbolicValue ())
3751+ continue ;
3752+ if (!value.isKnown ())
3753+ continue ;
3754+ if (!value.tokvalue )
3755+ continue ;
3756+ if (!ids.insert (value.tokvalue ->exprId ()).second )
3757+ continue ;
3758+ const bool add = tok->str () == " +" ;
3759+ if (add && MathLib::additionWouldOverflow (value.intvalue , constant->intvalue ))
3760+ continue ;
3761+ if (!add && MathLib::subtractionWouldOverflow (value.intvalue , constant->intvalue ))
3762+ continue ;
3763+ ValueFlow::Value newValue (value);
3764+ newValue.intvalue = add ? newValue.intvalue + constant->intvalue : newValue.intvalue - constant->intvalue ;
3765+ setTokenValue (tok, std::move (newValue), settings);
3766+ }
37633767 }
37643768 }
37653769 if (Token::Match (tok, " <<|>>|^|+|-|%or%" ) && constant->intvalue != 0 )
0 commit comments