Skip to content

Commit

Permalink
Make -Wno-maybe-uninitialized the default with GCC
Browse files Browse the repository at this point in the history
With our use of optionalt/std::optional, these warnings pop up in an
unpredictable manner. See
https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=std%3A%3Aoptional
for a number of bug reports against GCC about this.
  • Loading branch information
tautschnig committed Nov 17, 2023
1 parent bf6d759 commit d05574b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 44 deletions.
17 changes: 12 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,22 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Ensure NDEBUG is not set for release builds
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
# Enable lots of warnings
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wswitch-enum \
-Wno-deprecated-declarations -Wno-maybe-uninitialized")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
# Ensure NDEBUG is not set for release builds
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
# Enable lots of warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wno-deprecated-declarations -Wswitch-enum")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wswitch-enum -Wno-deprecated-declarations")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# This would be the place to enable warnings for Windows builds, although
# config.inc doesn't seem to do that currently
Expand Down
5 changes: 4 additions & 1 deletion src/config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ BUILD_ENV = AUTO
ifeq ($(BUILD_ENV),MSVC)
#CXXFLAGS += /Wall /WX
else
CXXFLAGS += -Wall -pedantic -Werror -Wno-deprecated-declarations -Wswitch-enum
CXXFLAGS += -Wall -pedantic -Werror -Wswitch-enum
CXXFLAGS += -Wno-deprecated-declarations
# GCC only, silence clang warning
CXXFLAGS += -Wno-maybe-uninitialized -Wunknown-warning-option
endif

ifeq ($(CPROVER_WITH_PROFILING),1)
Expand Down
18 changes: 0 additions & 18 deletions src/goto-instrument/unwindset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ void unwindsett::parse_unwindset_one_loop(
if(val.empty())
return;

// Work around spurious GCC 12 warning about thread_nr being uninitialised.
#pragma GCC diagnostic push
#ifndef __clang__
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
optionalt<unsigned> thread_nr;
#pragma GCC diagnostic pop
if(isdigit(val[0]))
{
auto c_pos = val.find(':');
Expand Down Expand Up @@ -160,13 +154,7 @@ void unwindsett::parse_unwindset_one_loop(
return;
}
else
// Work around spurious GCC 12 warning about thread_nr being uninitialised.
#pragma GCC diagnostic push
#ifndef __clang__
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
id = function_id + "." + std::to_string(*nr);
#pragma GCC diagnostic pop
}
}

Expand All @@ -182,13 +170,7 @@ void unwindsett::parse_unwindset_one_loop(

if(thread_nr.has_value())
{
// Work around spurious GCC 12 warning about thread_nr being uninitialised.
#pragma GCC diagnostic push
#ifndef __clang__
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
thread_loop_map[std::pair<irep_idt, unsigned>(id, *thread_nr)] = uw;
#pragma GCC diagnostic pop
}
else
{
Expand Down
6 changes: 0 additions & 6 deletions src/util/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,7 @@ bool cmdlinet::parse_arguments(int argc, const char **argv)
return true;
}

// Work around spurious GCC 12 warning about optnr being uninitialised.
#pragma GCC diagnostic push
#ifndef __clang__
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
options[*optnr].isset = true;
#pragma GCC diagnostic pop

if(options[*optnr].hasval)
{
Expand Down
7 changes: 0 additions & 7 deletions src/util/lower_byte_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,15 +1110,8 @@ static exprt lower_byte_extract_array_vector(

if(num_elements.has_value())
{
exprt::operandst operands;
// Work around spurious GCC warning about num_elements being uninitialised.
#pragma GCC diagnostic push
#ifndef __clang__
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
operands.reserve(*num_elements);
for(std::size_t i = 0; i < *num_elements; ++i)
#pragma GCC diagnostic pop
{
plus_exprt new_offset(
unpacked.offset(),
Expand Down
7 changes: 0 additions & 7 deletions src/util/simplify_expr_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@ static bool mul_expr(
return true;
}

// Work around spurious GCC 12 warning about c_sizeof_type being
// uninitialised in its destructor (!).
#pragma GCC diagnostic push
#ifndef __clang__
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
simplify_exprt::resultt<> simplify_exprt::simplify_mult(const mult_exprt &expr)
{
// check to see if it is a number type
Expand Down Expand Up @@ -276,7 +270,6 @@ simplify_exprt::resultt<> simplify_exprt::simplify_mult(const mult_exprt &expr)
return std::move(tmp);
}
}
#pragma GCC diagnostic pop

simplify_exprt::resultt<> simplify_exprt::simplify_div(const div_exprt &expr)
{
Expand Down

0 comments on commit d05574b

Please sign in to comment.