chore: add additional compiler flags (#17815)

Added:
  - -Wdouble-promotion
  - -Wmissing-noreturn
  - -Wmissing-format-attribute
  - -Wsuggest-attribute={pure,const,malloc,cold}

Resolves: #343
This commit is contained in:
Lewis Russell 2022-03-24 11:14:04 +00:00 committed by GitHub
parent 0c45753119
commit fcd57980f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 42 additions and 16 deletions

View File

@ -284,6 +284,9 @@ if(MSVC)
else()
add_compile_options(-Wall -Wextra -pedantic -Wno-unused-parameter
-Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion
-Wdouble-promotion
-Wmissing-noreturn
-Wmissing-format-attribute
-Wmissing-prototypes)
check_c_compiler_flag(-Wimplicit-fallthrough HAVE_WIMPLICIT_FALLTHROUGH_FLAG)
@ -291,6 +294,27 @@ else()
add_compile_options(-Wimplicit-fallthrough)
endif()
# Clang doesn't have -Wsuggest-attribute so check for each one.
check_c_compiler_flag(-Wsuggest-attribute=pure HAVE_WSUGGEST_ATTRIBUTE_PURE)
if(HAVE_WSUGGEST_ATTRIBUTE_PURE)
add_compile_options(-Wsuggest-attribute=pure)
endif()
check_c_compiler_flag(-Wsuggest-attribute=const HAVE_WSUGGEST_ATTRIBUTE_CONST)
if(HAVE_WSUGGEST_ATTRIBUTE_CONST)
add_compile_options(-Wsuggest-attribute=const)
endif()
check_c_compiler_flag(-Wsuggest-attribute=malloc HAVE_WSUGGEST_ATTRIBUTE_MALLOC)
if(HAVE_WSUGGEST_ATTRIBUTE_MALLOC)
add_compile_options(-Wsuggest-attribute=malloc)
endif()
check_c_compiler_flag(-Wsuggest-attribute=cold HAVE_WSUGGEST_ATTRIBUTE_COLD)
if(HAVE_WSUGGEST_ATTRIBUTE_COLD)
add_compile_options(-Wsuggest-attribute=cold)
endif()
# On FreeBSD 64 math.h uses unguarded C11 extension, which taints clang
# 3.4.1 used there.
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND CMAKE_C_COMPILER_ID MATCHES "Clang")

View File

@ -182,12 +182,15 @@ foreach(sfile ${CONV_SOURCES})
message(FATAL_ERROR "${sfile} doesn't exist (it was added to CONV_SOURCES)")
endif()
endforeach()
# xdiff, mpack, lua-cjson: inlined external project, we don't maintain it. #9306
list(APPEND CONV_SOURCES ${EXTERNAL_SOURCES})
if(NOT MSVC)
set_source_files_properties(
${CONV_SOURCES} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion")
# xdiff, mpack, lua-cjson: inlined external project, we don't maintain it. #9306
set_source_files_properties(
${EXTERNAL_SOURCES} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion -Wno-missing-noreturn -Wno-missing-format-attribute -Wno-double-promotion")
# gperf generates ANSI-C with incorrect linkage, ignore it.
check_c_compiler_flag(-Wstatic-in-inline HAS_WSTATIC_IN_INLINE)
if(HAS_WSTATIC_IN_INLINE)

View File

@ -3976,18 +3976,11 @@ static int eval6(char_u **arg, typval_T *rettv, int evaluate, int want_string)
f1 = f1 * f2;
} else if (op == '/') {
// Division by zero triggers error from AddressSanitizer
f1 = (f2 == 0
? (
f1 = (f2 == 0 ? (
#ifdef NAN
f1 == 0
? NAN
:
f1 == 0 ? (float_T)NAN :
#endif
(f1 > 0
? INFINITY
: -INFINITY)
)
: f1 / f2);
(f1 > 0 ? (float_T)INFINITY : (float_T)-INFINITY)) : f1 / f2);
} else {
emsg(_("E804: Cannot use '%' with Float"));
return FAIL;
@ -5842,15 +5835,15 @@ size_t string2float(const char *const text, float_T *const ret_value)
// MS-Windows does not deal with "inf" and "nan" properly
if (STRNICMP(text, "inf", 3) == 0) {
*ret_value = INFINITY;
*ret_value = (float_T)INFINITY;
return 3;
}
if (STRNICMP(text, "-inf", 3) == 0) {
*ret_value = -INFINITY;
*ret_value = (float_T)-INFINITY;
return 4;
}
if (STRNICMP(text, "nan", 3) == 0) {
*ret_value = NAN;
*ret_value = (float_T)NAN;
return 3;
}
*ret_value = strtod(text, &s);

View File

@ -6629,6 +6629,7 @@ static void ex_quit(exarg_T *eap)
/// ":cquit".
static void ex_cquit(exarg_T *eap)
FUNC_ATTR_NORETURN
{
// this does not always pass on the exit code to the Manx compiler. why?
getout(eap->addr_count > 0 ? (int)eap->line2 : EXIT_FAILURE);

View File

@ -282,6 +282,7 @@ static bool do_log_to_file(FILE *log_file, int log_level, const char *context,
static bool v_do_log_to_file(FILE *log_file, int log_level, const char *context,
const char *func_name, int line_num, bool eol, const char *fmt,
va_list args)
FUNC_ATTR_PRINTF(7, 0)
{
static const char *log_levels[] = {
[DEBUG_LOG_LEVEL] = "DEBUG",

View File

@ -2099,6 +2099,7 @@ static bool file_owned(const char *fname)
/// @param errstr string containing an error message
/// @param str string to append to the primary error message, or NULL
static void mainerr(const char *errstr, const char *str)
FUNC_ATTR_NORETURN
{
char *prgname = (char *)path_tail((char_u *)argv0);

View File

@ -522,6 +522,7 @@ static bool input_ready(MultiQueue *events)
// Exit because of an input read error.
static void read_error_exit(void)
FUNC_ATTR_NORETURN
{
if (silent_mode) { // Normal way to exit for "nvim -es".
getout(0);

View File

@ -152,6 +152,7 @@ static char *signal_name(int signum)
// NOTE: Avoid unsafe functions, such as allocating memory, they can result in
// a deadlock.
static void deadly_signal(int signum)
FUNC_ATTR_NORETURN
{
// Set the v:dying variable.
set_vim_var_nr(VV_DYING, 1);

View File

@ -87,6 +87,7 @@ Object ui_client_handle_redraw(uint64_t channel_id, Array args, Error *error)
///
/// This is just a stub. the full version will handle input, resizing, etc
void ui_client_execute(uint64_t chan)
FUNC_ATTR_NORETURN
{
while (true) {
loop_poll_events(&main_loop, -1);

View File

@ -836,7 +836,7 @@ void ui_ext_win_position(win_T *wp)
FloatConfig c = wp->w_float_config;
if (!c.external) {
ScreenGrid *grid = &default_grid;
float row = c.row, col = c.col;
Float row = c.row, col = c.col;
if (c.relative == kFloatRelativeWindow) {
Error dummy = ERROR_INIT;
win_T *win = find_window_by_handle(c.window, &dummy);