Fixed zerodiv FN for '1/std::cbrt(0)' and added more test cases for other math functions

This commit is contained in:
orbitcowboy 2022-07-09 17:28:15 +02:00
parent a8816a2d2f
commit 41b6452604
3 changed files with 42 additions and 3 deletions

View File

@ -1057,7 +1057,7 @@
<function name="cbrt,std::cbrt">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">cbrt(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1068,7 +1068,7 @@
<function name="cbrtf,std::cbrtf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">cbrt(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -1079,7 +1079,7 @@
<function name="cbrtl,std::cbrtl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">cbrt(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">

View File

@ -730,6 +730,17 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["cbrt"] = [](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::cbrt(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["exp"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1)
return ValueFlow::Value::unknown();

View File

@ -43,6 +43,20 @@ int zerodiv_sqrt()
return 42 / i;
}
int zerodiv_cbrt()
{
int i = std::cbrt(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_asin()
{
int i = std::asin(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_acos()
{
int i = std::acos(1);
@ -78,6 +92,20 @@ int zerodiv_tanh()
return 42 / i;
}
int zerodiv_atanh()
{
int i = std::atanh(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_atan()
{
int i = std::atan(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_sin()
{
int i = std::sin(0)+std::sin(M_PI)+std::sin(2*M_PI);