Fixed zerodiv/moduloofone FNs for more math functions

This commit is contained in:
orbitcowboy 2022-07-09 19:21:58 +02:00
parent 0282c3a86e
commit ef47d34e75
3 changed files with 134 additions and 26 deletions

View File

@ -1498,7 +1498,7 @@
<function name="fabs,std::fabs">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">fabs(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1509,7 +1509,7 @@
<function name="fabsf,std::fabsf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">fabs(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1520,7 +1520,7 @@
<function name="fabsl,std::fabsl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">fabs(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1531,7 +1531,7 @@
<function name="fdim,std::fdim">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">fdim(arg1, arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1545,7 +1545,7 @@
<function name="fdimf,std::fdimf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">fdim(arg1, arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1559,7 +1559,7 @@
<function name="fdiml,std::fdiml">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">fdim(arg1, arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1649,7 +1649,7 @@
<function name="floor,std::floor">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">floor(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1660,7 +1660,7 @@
<function name="floorf,std::floorf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">floor(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1671,7 +1671,7 @@
<function name="floorl,std::floorl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">floor(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1733,7 +1733,7 @@
<function name="fmax,std::fmax">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">fmax(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1747,7 +1747,7 @@
<function name="fmaxf,std::fmaxf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">fmax(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1761,7 +1761,7 @@
<function name="fmaxl,std::fmaxl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">fmax(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1775,7 +1775,7 @@
<function name="fmin,std::fmin">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">fmin(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1789,7 +1789,7 @@
<function name="fminf,std::fminf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">fmin(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1803,7 +1803,7 @@
<function name="fminl,std::fminl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">fmin(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1817,7 +1817,7 @@
<function name="fmod,std::fmod">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">fmod(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1832,7 +1832,7 @@
<function name="fmodf,std::fmodf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">fmod(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1847,7 +1847,7 @@
<function name="fmodl,std::fmodl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">fmod(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">

View File

@ -708,6 +708,50 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["fdim"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
return ValueFlow::Value::unknown();
ValueFlow::Value v = args[0];
if (!v.isFloatValue() && !v.isIntValue())
return ValueFlow::Value::unknown();
double value = args[0].isFloatValue() ? args[0].floatValue : args[0].intvalue;
v.floatValue = std::fdim(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["fmax"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
return ValueFlow::Value::unknown();
ValueFlow::Value v = args[0];
if (!v.isFloatValue() && !v.isIntValue())
return ValueFlow::Value::unknown();
double value = args[0].isFloatValue() ? args[0].floatValue : args[0].intvalue;
v.floatValue = std::fmax(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["fmin"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
return ValueFlow::Value::unknown();
ValueFlow::Value v = args[0];
if (!v.isFloatValue() && !v.isIntValue())
return ValueFlow::Value::unknown();
double value = args[0].isFloatValue() ? args[0].floatValue : args[0].intvalue;
v.floatValue = std::fmin(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["fmod"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
return ValueFlow::Value::unknown();
ValueFlow::Value v = args[0];
if (!v.isFloatValue() && !v.isIntValue())
return ValueFlow::Value::unknown();
double value = args[0].isFloatValue() ? args[0].floatValue : args[0].intvalue;
v.floatValue = std::fmod(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["pow"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
return ValueFlow::Value::unknown();
@ -741,6 +785,17 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["floor"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1)
return ValueFlow::Value::unknown();
ValueFlow::Value v = args[0];
if (!v.isFloatValue() && !v.isIntValue())
return ValueFlow::Value::unknown();
double value = args[0].isFloatValue() ? args[0].floatValue : args[0].intvalue;
v.floatValue = std::floor(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["sqrt"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1)
return ValueFlow::Value::unknown();
@ -803,7 +858,18 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
if (!v.isFloatValue() && !v.isIntValue())
return ValueFlow::Value::unknown();
double value = args[0].isFloatValue() ? args[0].floatValue : args[0].intvalue;
v.floatValue = std::exp2(value);
v.floatValue = std::expm1(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["fabs"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1)
return ValueFlow::Value::unknown();
ValueFlow::Value v = args[0];
if (!v.isFloatValue() && !v.isIntValue())
return ValueFlow::Value::unknown();
double value = args[0].isFloatValue() ? args[0].floatValue : args[0].intvalue;
v.floatValue = std::fabs(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};

View File

@ -36,6 +36,48 @@
#include <iterator>
#include <vector>
int zerodiv_fmod()
{
int i = std::fmod(0.0, 42.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fmin()
{
int i = std::fmin(0.0, 0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fmax()
{
int i = std::fmax(0.0, 0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_floor()
{
int i = std::floor(0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fabs()
{
int i = std::fabs(-0.0) + std::fabs(+0.0) + std::fabs(0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fdim()
{
int i = std::fdim(1.0, 1.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_ceil()
{
int i = std::ceil(0);
@ -134,6 +176,13 @@ int zerodiv_sin()
return 42 / i;
}
int zerodiv_expm1()
{
int i = std::expm1(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int moduloofone_cos()
{
int i = std::cos(0);
@ -141,13 +190,6 @@ int moduloofone_cos()
return 42 % i;
}
int moduloofone_expm1()
{
int i = std::expm1(0);
// cppcheck-suppress moduloofone
return 42 % i;
}
int moduloofone_exp()
{
int i = std::exp(0);