diff --git a/cfg/std.cfg b/cfg/std.cfg index 5212261ca..2c5bc1919 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -1414,7 +1414,7 @@ - + exp2(arg1) false @@ -1425,7 +1425,7 @@ - + exp2(arg1) false @@ -1436,7 +1436,7 @@ - + exp2(arg1) false diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 3fd5be1fb..92feb0d58 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -785,6 +785,17 @@ static std::unordered_map createBuiltinLibr v.valueType = ValueFlow::Value::ValueType::FLOAT; return v; }; + functions["exp2"] = [](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 af8ac8e40..c7475579d 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -148,6 +148,13 @@ int moduloofone_exp() return 42 % i; } +int moduloofone_exp2() +{ + int i = std::exp2(0); + // cppcheck-suppress moduloofone + return 42 % i; +} + int moduloofone_pow() { int i = std::pow(2, 0);