some `-Wdouble-promotion` Clang compiler warnings (#4820)

This commit is contained in:
Oliver Stöneberg 2023-08-07 20:44:25 +02:00 committed by GitHub
parent cc592a6927
commit dcdf67a694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 21 deletions

View File

@ -73,14 +73,11 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_link_options(-lc++)
endif()
add_compile_options_safe(-Wno-documentation-unknown-command)
# TODO: fix and enable these warnings - or move to suppression list below
add_compile_options_safe(-Wno-documentation-unknown-command) # TODO: Clang currently does not support all commands
add_compile_options_safe(-Wno-inconsistent-missing-destructor-override) # caused by Qt moc code
add_compile_options_safe(-Wno-unused-exception-parameter)
add_compile_options_safe(-Wno-old-style-cast)
add_compile_options_safe(-Wno-global-constructors)
add_compile_options_safe(-Wno-exit-time-destructors)
add_compile_options_safe(-Wno-sign-conversion)
add_compile_options_safe(-Wno-shadow-field-in-constructor)
add_compile_options_safe(-Wno-covered-switch-default)
@ -102,16 +99,26 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options_safe(-Wno-tautological-type-limit-compare)
add_compile_options(-Wno-disabled-macro-expansion)
add_compile_options_safe(-Wno-bitwise-instead-of-logical)
add_compile_options_safe(-Wno-unsafe-buffer-usage)
# warnings we are not interested in
add_compile_options(-Wno-four-char-constants)
add_compile_options(-Wno-c++98-compat)
add_compile_options(-Wno-weak-vtables)
# these cannot be fixed properly without adopting later C++ standards
add_compile_options_safe(-Wno-unsafe-buffer-usage)
add_compile_options_safe(-Wno-global-constructors)
add_compile_options_safe(-Wno-exit-time-destructors)
# can only be partially addressed
add_compile_options(-Wno-padded)
# no need for C++98 compatibility
add_compile_options(-Wno-c++98-compat)
add_compile_options(-Wno-c++98-compat-pedantic)
# only need to be addressed to work around issues in older compilers
add_compile_options_safe(-Wno-return-std-move-in-c++11)
# warnings we are currently not interested in
add_compile_options(-Wno-four-char-constants)
add_compile_options(-Wno-weak-vtables)
if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML)
message(FATAL_ERROR "Do not use clang to generate code coverage. Use GCC instead.")
endif()

View File

@ -17,5 +17,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options_safe(tinyxml2_objs -Wno-suggest-destructor-override)
target_compile_options_safe(tinyxml2_objs -Wno-zero-as-null-pointer-constant)
target_compile_options_safe(tinyxml2_objs -Wno-format-nonliteral)
target_compile_options_safe(tinyxml2_objs -Wno-old-style-cast)
endif()

View File

@ -36,7 +36,7 @@ inline bool isEqual(double x, double y)
}
inline bool isEqual(float x, float y)
{
return isEqual(double{x}, double{y});
return isEqual(double(x), double(y));
}
template<class T>

View File

@ -981,7 +981,7 @@ T getvalue3(const T value1, const T value2)
template<>
double getvalue3(const double value1, const double value2)
{
return (value1 + value2) / 2.0f;
return (value1 + value2) / 2.0;
}

View File

@ -9112,12 +9112,12 @@ static void valueFlowSafeFunctions(TokenList& tokenlist, const SymbolDatabase& s
std::list<ValueFlow::Value> argValues;
argValues.emplace_back(0);
argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT;
argValues.back().floatValue = isLow ? low : -1E25f;
argValues.back().floatValue = isLow ? low : -1E25;
argValues.back().errorPath.emplace_back(arg.nameToken(), "Safe checks: Assuming argument has value " + MathLib::toString(argValues.back().floatValue));
argValues.back().safe = true;
argValues.emplace_back(0);
argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT;
argValues.back().floatValue = isHigh ? high : 1E25f;
argValues.back().floatValue = isHigh ? high : 1E25;
argValues.back().errorPath.emplace_back(arg.nameToken(), "Safe checks: Assuming argument has value " + MathLib::toString(argValues.back().floatValue));
argValues.back().safe = true;
valueFlowForward(const_cast<Token*>(functionScope->bodyStart->next()),

View File

@ -349,7 +349,7 @@ private:
return false;
}
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, float value, float diff) {
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, double value, double diff) {
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
@ -565,7 +565,7 @@ private:
void valueFlowNumber() {
ASSERT_EQUALS(123, valueOfTok("x=123;", "123").intvalue);
ASSERT_EQUALS_DOUBLE(192.0, valueOfTok("x=0x0.3p10;", "0x0.3p10").floatValue, 1e-5); // 3 * 16^-1 * 2^10 = 192
ASSERT(std::fabs(valueOfTok("x=0.5;", "0.5").floatValue - 0.5f) < 0.1f);
ASSERT(std::fabs(valueOfTok("x=0.5;", "0.5").floatValue - 0.5) < 0.1);
ASSERT_EQUALS(10, valueOfTok("enum {A=10,B=15}; x=A+0;", "+").intvalue);
ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue);
ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue);
@ -3491,7 +3491,7 @@ private:
void valueFlowForwardCompoundAssign() {
const char *code;
code = "void f() {\n"
code = "int f() {\n"
" int x = 123;\n"
" x += 43;\n"
" return x;\n"
@ -3501,19 +3501,26 @@ private:
"3,Compound assignment '+=', assigned value is 166\n",
getErrorPathForX(code, 4U));
code = "void f() {\n"
code = "int f() {\n"
" int x = 123;\n"
" x /= 0;\n" // don't crash when evaluating x/=0
" return x;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 123));
code = "void f() {\n"
" float x = 123.45;\n"
code = "float f() {\n"
" float x = 123.45f;\n"
" x += 67;\n"
" return x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 123.45F + 67, 0.01F));
ASSERT_EQUALS(true, testValueOfX(code, 4U, (double)123.45f + 67, 0.01));
code = "double f() {\n"
" double x = 123.45;\n"
" x += 67;\n"
" return x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 123.45 + 67, 0.01));
code = "void f() {\n"
" int x = 123;\n"
@ -3522,7 +3529,7 @@ private:
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 61));
code = "void f() {\n"
code = "int f() {\n"
" int x = 123;\n"
" x <<= 1;\n"
" return x;\n"