diff --git a/cfg/std.cfg b/cfg/std.cfg index 2c5bc1919..d96383c0b 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -1447,7 +1447,7 @@ - + expm1(arg1) false @@ -1458,7 +1458,7 @@ - + expm1(arg1) false @@ -1469,7 +1469,7 @@ - + expm1(arg1) false diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 92feb0d58..66b7c0969 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -796,6 +796,17 @@ static std::unordered_map createBuiltinLibr v.valueType = ValueFlow::Value::ValueType::FLOAT; return v; }; + functions["expm1"] = [](const std::vector& 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::exp2(value); + v.valueType = ValueFlow::Value::ValueType::FLOAT; + return v; + }; functions["log"] = [](const std::vector& args) { if (args.size() != 1) return ValueFlow::Value::unknown(); diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index c7475579d..f7b9fb7ef 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -141,6 +141,13 @@ 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);