Skip to content

Commit c58572a

Browse files
authored
Merge pull request #8047 from tautschnig/maybe-uninit
Make -Wno-maybe-uninitialized the default with GCC
2 parents 3e2cbc5 + 7c0641d commit c58572a

File tree

6 files changed

+16
-43
lines changed

6 files changed

+16
-43
lines changed

CMakeLists.txt

+12-5
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,22 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
7171
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
7272
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
7373

74-
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
75-
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" OR
76-
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"
77-
)
74+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
75+
# Ensure NDEBUG is not set for release builds
76+
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
77+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
78+
# Enable lots of warnings
79+
set(CMAKE_CXX_FLAGS
80+
"${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wswitch-enum \
81+
-Wno-deprecated-declarations -Wno-maybe-uninitialized")
82+
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
83+
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
7884
# Ensure NDEBUG is not set for release builds
7985
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
8086
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
8187
# Enable lots of warnings
82-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wno-deprecated-declarations -Wswitch-enum")
88+
set(CMAKE_CXX_FLAGS
89+
"${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wswitch-enum -Wno-deprecated-declarations")
8390
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
8491
# This would be the place to enable warnings for Windows builds, although
8592
# config.inc doesn't seem to do that currently

src/config.inc

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ BUILD_ENV = AUTO
55
ifeq ($(BUILD_ENV),MSVC)
66
#CXXFLAGS += /Wall /WX
77
else
8-
CXXFLAGS += -Wall -pedantic -Werror -Wno-deprecated-declarations -Wswitch-enum
8+
CXXFLAGS += -Wall -pedantic -Werror -Wswitch-enum
9+
CXXFLAGS += -Wno-deprecated-declarations
10+
# GCC only, silence clang warning
11+
CXXFLAGS += -Wno-maybe-uninitialized -Wno-unknown-warning-option
912
endif
1013

1114
ifeq ($(CPROVER_WITH_PROFILING),1)

src/goto-instrument/unwindset.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ void unwindsett::parse_unwindset_one_loop(
3333
if(val.empty())
3434
return;
3535

36-
// Work around spurious GCC 12 warning about thread_nr being uninitialised.
37-
#pragma GCC diagnostic push
38-
#ifndef __clang__
39-
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
40-
#endif
4136
optionalt<unsigned> thread_nr;
42-
#pragma GCC diagnostic pop
4337
if(isdigit(val[0]))
4438
{
4539
auto c_pos = val.find(':');
@@ -160,13 +154,7 @@ void unwindsett::parse_unwindset_one_loop(
160154
return;
161155
}
162156
else
163-
// Work around spurious GCC 12 warning about thread_nr being uninitialised.
164-
#pragma GCC diagnostic push
165-
#ifndef __clang__
166-
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
167-
#endif
168157
id = function_id + "." + std::to_string(*nr);
169-
#pragma GCC diagnostic pop
170158
}
171159
}
172160

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

183171
if(thread_nr.has_value())
184172
{
185-
// Work around spurious GCC 12 warning about thread_nr being uninitialised.
186-
#pragma GCC diagnostic push
187-
#ifndef __clang__
188-
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
189-
#endif
190173
thread_loop_map[std::pair<irep_idt, unsigned>(id, *thread_nr)] = uw;
191-
#pragma GCC diagnostic pop
192174
}
193175
else
194176
{

src/util/cmdline.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,7 @@ bool cmdlinet::parse_arguments(int argc, const char **argv)
296296
return true;
297297
}
298298

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

307301
if(options[*optnr].hasval)
308302
{

src/util/lower_byte_operators.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -1111,14 +1111,8 @@ static exprt lower_byte_extract_array_vector(
11111111
if(num_elements.has_value())
11121112
{
11131113
exprt::operandst operands;
1114-
// Work around spurious GCC warning about num_elements being uninitialised.
1115-
#pragma GCC diagnostic push
1116-
#ifndef __clang__
1117-
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
1118-
#endif
11191114
operands.reserve(*num_elements);
11201115
for(std::size_t i = 0; i < *num_elements; ++i)
1121-
#pragma GCC diagnostic pop
11221116
{
11231117
plus_exprt new_offset(
11241118
unpacked.offset(),

src/util/simplify_expr_int.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,6 @@ static bool mul_expr(
159159
return true;
160160
}
161161

162-
// Work around spurious GCC 12 warning about c_sizeof_type being
163-
// uninitialised in its destructor (!).
164-
#pragma GCC diagnostic push
165-
#ifndef __clang__
166-
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
167-
#endif
168162
simplify_exprt::resultt<> simplify_exprt::simplify_mult(const mult_exprt &expr)
169163
{
170164
// check to see if it is a number type
@@ -276,7 +270,6 @@ simplify_exprt::resultt<> simplify_exprt::simplify_mult(const mult_exprt &expr)
276270
return std::move(tmp);
277271
}
278272
}
279-
#pragma GCC diagnostic pop
280273

281274
simplify_exprt::resultt<> simplify_exprt::simplify_div(const div_exprt &expr)
282275
{

0 commit comments

Comments
 (0)