Fixed zerodiv/moduloofone FNs for more math functions

This commit is contained in:
orbitcowboy 2022-07-09 19:59:16 +02:00
parent ef47d34e75
commit 8215521843
3 changed files with 77 additions and 12 deletions

View File

@ -2119,7 +2119,7 @@
<function name="hypot,std::hypot">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">hypot(arg1, arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -2136,7 +2136,7 @@
<function name="hypotf,std::hypotf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">hypot(arg1, arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -2150,7 +2150,7 @@
<function name="hypotl,std::hypotl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">hypot(arg1, arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -2989,7 +2989,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="ldexp,std::ldexp">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">ldexp(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3003,7 +3003,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="ldexpf,std::ldexpf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">ldexp(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3017,7 +3017,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="ldexpl,std::ldexpl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">ldexp(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3031,7 +3031,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="lgamma,std::lgamma">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">lgamma(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3042,7 +3042,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="lgammaf,std::lgammaf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">lgamma(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3053,7 +3053,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="lgammal,std::lgammal">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">lgamma(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3511,7 +3511,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="ilogb,std::ilogb">
<use-retval/>
<pure/>
<returnValue type="int"/>
<returnValue type="int">ilogb(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3522,7 +3522,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="ilogbf,std::ilogbf">
<use-retval/>
<pure/>
<returnValue type="int"/>
<returnValue type="int">ilogb(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3533,7 +3533,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="ilogbl,std::ilogbl">
<use-retval/>
<pure/>
<returnValue type="int"/>
<returnValue type="int">ilogb(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">

View File

@ -642,6 +642,17 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["lgamma"] = [](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::lgamma(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["cos"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1)
return ValueFlow::Value::unknown();
@ -708,6 +719,17 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["hypot"] = [](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::hypot(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["fdim"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
return ValueFlow::Value::unknown();
@ -763,6 +785,28 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["ldexp"] = [](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::ldexp(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["ilogb"] = [](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.intvalue = std::ilogb(value);
v.valueType = ValueFlow::Value::ValueType::INT;
return v;
};
functions["erf"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1)
return ValueFlow::Value::unknown();

View File

@ -36,6 +36,27 @@
#include <iterator>
#include <vector>
int zerodiv_ldexp()
{
int i = std::ldexp(0.0, 42.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_ilogb()
{
int i = std::ilogb(1.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_hypot()
{
int i = std::hypot(0.0, 0.0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_fmod()
{
int i = std::fmod(0.0, 42.0);