From 0fe0d9d4ef152243f47f9c8e17520d10a67ba2c6 Mon Sep 17 00:00:00 2001 From: Allen Winter Date: Mon, 3 Oct 2022 11:43:20 -0400 Subject: add clang diagnostic pragmas to quiet unreachable-code warnings fixes: #486 --- CMakeLists.txt | 8 ++++++++ ReleaseNotes.txt | 1 + src/libicalss/icalssyacc.c | 6 ++++-- src/test/regression-storage.c | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f889f985..6ac0c7f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -510,6 +510,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") check_c_compiler_flag(-Wsizeof-pointer-memaccess HAVE_GCC_POINTER_MEMACCESS) check_c_compiler_flag(-Wformat-security HAVE_GCC_FORMAT_SECURITY) check_c_compiler_flag(-Wredundant-decls HAVE_GCC_REDUNDANT_DECLS) + check_c_compiler_flag(-Wunreachable-code HAVE_GCC_UNREACHABLE_CODE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -Wno-deprecated -Wall -Wno-unknown-pragmas -Wextra -Winit-self -Wunused -Wno-div-by-zero -Wundef -Wpointer-arith -Wtype-limits -Wwrite-strings -Werror=return-type") if(HAVE_GCC_UNUSED_BUT_SET) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused-but-set-variable") @@ -526,6 +527,9 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") if(HAVE_GCC_REDUNDANT_DECLS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wredundant-decls") endif() + if(HAVE_GCC_UNREACHABLE_CODE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunreachable-code") + endif() if(CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME STREQUAL GNU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=500 -D_DEFAULT_SOURCE -D_GNU_SOURCE") endif() @@ -542,6 +546,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") check_cxx_compiler_flag(-Wreorder HAVE_GXX_REORDER) check_cxx_compiler_flag(-Wformat-security HAVE_GXX_FORMAT_SECURITY) check_cxx_compiler_flag(-Wredundant-decls HAVE_GXX_REDUNDANT_DECLS) + check_cxx_compiler_flag(-Wunreachable-code HAVE_GXX_UNREACHABLE_CODE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -Weffc++ -Wno-deprecated -Wall -Wextra -Woverloaded-virtual -Winit-self -Wunused -Wno-div-by-zero -Wundef -Wpointer-arith -Wtype-limits -Wwrite-strings -Werror=return-type") if(HAVE_GXX_UNUSED_BUT_SET) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-but-set-variable") @@ -561,6 +566,9 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") if(HAVE_GXX_REDUNDANT_DECLS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wredundant-decls") endif() + if(HAVE_GXX_UNREACHABLE_CODE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunreachable-code") + endif() if(CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME STREQUAL GNU) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_XOPEN_SOURCE=500 -D_DEFAULT_SOURCE -D_GNU_SOURCE") endif() diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 11ceac75..98826346 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -10,6 +10,7 @@ Version 3.0.15 (UNRELEASED): * Fix x-property comma handling and escaping * Built-in timezones updated to tzdata2022d (now with a VTIMEZONE for each time zone alias) * Fix fuzzer issues + * Handle unreachable-code compile warnings with clang Version 3.0.14 (05 February 2022): ---------------------------------- diff --git a/src/libicalss/icalssyacc.c b/src/libicalss/icalssyacc.c index 2416e528..e386ad80 100644 --- a/src/libicalss/icalssyacc.c +++ b/src/libicalss/icalssyacc.c @@ -1599,9 +1599,11 @@ yyerrorlab: /* Pacify compilers like GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ - if (/*CONSTCOND*/ 0) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" + if (/*CONSTCOND*/ 0) goto yyerrorlab; - +#pragma clang diagnostic pop /* Do not reclaim the symbols of the rule which action triggered this YYERROR. */ YYPOPSTACK (yylen); diff --git a/src/test/regression-storage.c b/src/test/regression-storage.c index 7ce594d2..eb11f6d5 100644 --- a/src/test/regression-storage.c +++ b/src/test/regression-storage.c @@ -305,6 +305,8 @@ void test_bdbset() return; // for now... TODO fix these broken tests.. +#pragma clang diagnostic push /* remove when/if we remove the proceeding return statement */ +#pragma clang diagnostic ignored "-Wunreachable-code" start = icaltime_from_timet_with_zone(time(0), 0, NULL); end = start; end.hour++; @@ -452,6 +454,7 @@ void test_bdbset() } icalset_free(cout); } +#pragma clang diagnostic pop } #endif -- cgit v1.2.1