Fixed zerodiv FN for '1/std::erfc(42)'

This commit is contained in:
orbitcowboy 2022-07-09 17:43:17 +02:00
parent 87c1e6587a
commit 048d31ec56
3 changed files with 21 additions and 3 deletions

View File

@ -1291,7 +1291,7 @@
<function name="erfc,std::erfc"> <function name="erfc,std::erfc">
<use-retval/> <use-retval/>
<pure/> <pure/>
<returnValue type="double"/> <returnValue type="double">erfc(arg1)</returnValue>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<leak-ignore/> <leak-ignore/>
<arg nr="1" direction="in"> <arg nr="1" direction="in">
@ -1302,7 +1302,7 @@
<function name="erfcf,std::erfcf"> <function name="erfcf,std::erfcf">
<use-retval/> <use-retval/>
<pure/> <pure/>
<returnValue type="float"/> <returnValue type="float">erfc(arg1)</returnValue>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<leak-ignore/> <leak-ignore/>
<arg nr="1" direction="in"> <arg nr="1" direction="in">
@ -1313,7 +1313,7 @@
<function name="erfcl,std::erfcl"> <function name="erfcl,std::erfcl">
<use-retval/> <use-retval/>
<pure/> <pure/>
<returnValue type="long double"/> <returnValue type="long double">erfc(arg1)</returnValue>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<leak-ignore/> <leak-ignore/>
<arg nr="1" direction="in"> <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; v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v; return v;
}; };
functions["erfc"] = [](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::erfc(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["sqrt"] = [](const std::vector<ValueFlow::Value>& args) { functions["sqrt"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1) if (args.size() != 1)
return ValueFlow::Value::unknown(); return ValueFlow::Value::unknown();

View File

@ -64,6 +64,13 @@ int zerodiv_erf()
return 42 / i; return 42 / i;
} }
int zerodiv_erfc()
{
int i = std::erfc(42);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_asin() int zerodiv_asin()
{ {
int i = std::asin(0); int i = std::asin(0);