Skip to content

Commit 51a1b1b

Browse files
committed
Make goto-cc fail when warnings are emitted and -Werror and -Wextra are set
For goto-cl, goto-armcc, etc the equivalent options enable fail-on-warnings mode. Do not fail with -Werror -Wall (but not -Wextra) as that breaks too many builds as we don't have an equivalent of -Wno-...
1 parent 9b79eb6 commit 51a1b1b

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

src/goto-cc/armcc_mode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int armcc_modet::doit()
4646

4747
unsigned int verbosity=1;
4848

49-
compilet compiler(cmdline);
49+
compilet compiler(cmdline, cmdline.isset("diag_error="));
5050

5151
#if 0
5252
bool act_as_ld=

src/goto-cc/as_mode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int as_modet::doit()
159159
config.set(cmdline);
160160

161161
// determine actions to be undertaken
162-
compilet compiler(cmdline);
162+
compilet compiler(cmdline, cmdline.isset("fatal-warnings"));
163163
compiler.ui_message_handler.set_verbosity(verbosity);
164164

165165
if(cmdline.isset('b')) // as86 only

src/goto-cc/compile.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ bool compilet::doit()
121121
return true;
122122
}
123123

124+
const unsigned warnings_before=
125+
get_message_handler().get_message_count(messaget::M_WARNING);
126+
124127
if(source_files.size()>0)
125128
if(compile())
126129
return true;
@@ -133,7 +136,10 @@ bool compilet::doit()
133136
return true;
134137
}
135138

136-
return false;
139+
return
140+
warning_is_fatal &&
141+
get_message_handler().get_message_count(messaget::M_WARNING)!=
142+
warnings_before;
137143
}
138144

139145
/*******************************************************************\
@@ -156,8 +162,8 @@ bool compilet::add_input_file(const std::string &file_name)
156162
std::ifstream in(file_name);
157163
if(!in)
158164
{
159-
error() << "failed to open file `" << file_name << "'" << eom;
160-
return false; // generously ignore
165+
warning() << "failed to open file `" << file_name << "'" << eom;
166+
return warning_is_fatal; // generously ignore unless -Werror
161167
}
162168
}
163169

@@ -168,7 +174,7 @@ bool compilet::add_input_file(const std::string &file_name)
168174
// a file without extension; will ignore
169175
warning() << "input file `" << file_name
170176
<< "' has no extension, not considered" << eom;
171-
return false;
177+
return warning_is_fatal;
172178
}
173179

174180
std::string ext = file_name.substr(r+1, file_name.length());
@@ -329,7 +335,7 @@ bool compilet::find_library(const std::string &name)
329335
else if(is_elf_file(libname))
330336
{
331337
warning() << "Warning: Cannot read ELF library " << libname << eom;
332-
return false;
338+
return warning_is_fatal;
333339
}
334340
}
335341
}
@@ -752,11 +758,12 @@ Function: compilet::compilet
752758
753759
\*******************************************************************/
754760

755-
compilet::compilet(cmdlinet &_cmdline):
761+
compilet::compilet(cmdlinet &_cmdline, bool Werror):
756762
language_uit(_cmdline, ui_message_handler),
757763
ui_message_handler(_cmdline, "goto-cc " CBMC_VERSION),
758764
ns(symbol_table),
759-
cmdline(_cmdline)
765+
cmdline(_cmdline),
766+
warning_is_fatal(Werror)
760767
{
761768
mode=COMPILE_LINK_EXECUTABLE;
762769
echo_file_name=false;

src/goto-cc/compile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class compilet:public language_uit
4545
std::string object_file_extension;
4646
std::string output_file_object, output_file_executable;
4747

48-
explicit compilet(cmdlinet &_cmdline);
48+
compilet(cmdlinet &_cmdline, bool Werror);
4949

5050
~compilet();
5151

@@ -72,6 +72,7 @@ class compilet:public language_uit
7272

7373
protected:
7474
cmdlinet &cmdline;
75+
bool warning_is_fatal;
7576

7677
unsigned function_body_count(const goto_functionst &);
7778

src/goto-cc/cw_mode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int cw_modet::doit()
4646

4747
unsigned int verbosity=1;
4848

49-
compilet compiler(cmdline);
49+
compilet compiler(cmdline, cmdline.isset("Werror"));
5050

5151
#if 0
5252
bool act_as_ld=

src/goto-cc/gcc_mode.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ int gcc_modet::doit()
218218
return EX_OK;
219219
}
220220

221-
if(cmdline.isset("Wall"))
221+
if(cmdline.isset("Wall") || cmdline.isset("Wextra"))
222222
verbosity=2;
223223

224224
if(cmdline.isset("verbosity"))
@@ -303,7 +303,10 @@ int gcc_modet::doit()
303303
config.ansi_c.double_width=config.ansi_c.single_width;
304304

305305
// determine actions to be undertaken
306-
compilet compiler(cmdline);
306+
compilet compiler(cmdline,
307+
cmdline.isset("Werror") &&
308+
cmdline.isset("Wextra") &&
309+
!cmdline.isset("Wno-error"));
307310
compiler.set_message_handler(get_message_handler());
308311

309312
if(act_as_ld)

src/goto-cc/ms_cl_mode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int ms_cl_modet::doit()
5959

6060
unsigned int verbosity=1;
6161

62-
compilet compiler(cmdline);
62+
compilet compiler(cmdline, cmdline.isset("WX"));
6363

6464
#if 0
6565
bool act_as_ld=

0 commit comments

Comments
 (0)