Skip to content

Commit 12c051b

Browse files
author
Daniel Kroening
authored
Merge pull request #517 from diffblue/gcc-errors2
gcc-style error messages
2 parents 40f553c + 0d86b46 commit 12c051b

18 files changed

+151
-37
lines changed

regression/ansi-c/function_return1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
33
--verbosity 2
4-
^file main.c line 3 function fun: function has return void but a return statement returning signed int$
4+
^main.c:3:1: warning: function has return void but a return statement returning signed int$
55
^SIGNAL=0$
66

77
--

regression/ansi-c/struct6/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ main.c
33

44
^EXIT=\(64\|1\)$
55
^SIGNAL=0$
6-
^file main.c line 2: incomplete type not permitted here$
6+
^main.c:2:1: error: incomplete type not permitted here$
77
^CONVERSION ERROR$
88
--

regression/ansi-c/struct7/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ main.c
33

44
^EXIT=\(64\|1\)$
55
^SIGNAL=0$
6-
^file main.c line 4: duplicate member x$
6+
^main.c:4:1: error: duplicate member .*$
77
^CONVERSION ERROR$
88
--

src/ansi-c/c_typecheck_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ void c_typecheck_baset::typecheck_compound_body(
918918
if(!members.insert(it->get_name()).second)
919919
{
920920
error().source_location=it->source_location();
921-
error() << "duplicate member " << it->get_name() << eom;
921+
error() << "duplicate member '" << it->get_name() << '\'' << eom;
922922
throw 0;
923923
}
924924
}

src/goto-cc/armcc_mode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ int armcc_modet::doit()
5959
if(cmdline.isset("verbosity"))
6060
verbosity=unsafe_string2int(cmdline.get_value("verbosity"));
6161

62-
compiler.ui_message_handler.set_verbosity(verbosity);
63-
ui_message_handler.set_verbosity(verbosity);
62+
compiler.set_message_handler(get_message_handler());
63+
message_handler.set_verbosity(verbosity);
6464

6565
debug() << "ARM mode" << eom;
6666

src/goto-cc/armcc_mode.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,28 @@ Date: June 2006
1111
#ifndef CPROVER_GOTO_CC_ARMCC_MODE_H
1212
#define CPROVER_GOTO_CC_ARMCC_MODE_H
1313

14+
#include <util/cout_message.h>
15+
1416
#include "goto_cc_mode.h"
1517
#include "armcc_cmdline.h"
1618

1719
class armcc_modet:public goto_cc_modet
1820
{
1921
public:
20-
virtual int doit();
21-
virtual void help_mode();
22+
int doit() final;
23+
void help_mode() final;
2224

2325
armcc_modet(
2426
armcc_cmdlinet &_armcc_cmdline,
2527
const std::string &_base_name):
26-
goto_cc_modet(_armcc_cmdline, _base_name),
28+
goto_cc_modet(_armcc_cmdline, _base_name, message_handler),
2729
cmdline(_armcc_cmdline)
2830
{
2931
}
3032

3133
protected:
3234
armcc_cmdlinet &cmdline;
35+
gcc_message_handlert message_handler;
3336
};
3437

3538
#endif // CPROVER_GOTO_CC_ARMCC_MODE_H

src/goto-cc/as_mode.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Author: Michael Tautschnig
2222
#include <util/tempdir.h>
2323
#include <util/config.h>
2424
#include <util/get_base_name.h>
25+
#include <util/cout_message.h>
2526

2627
#include <cbmc/version.h>
2728

@@ -79,7 +80,7 @@ as_modet::as_modet(
7980
goto_cc_cmdlinet &_cmdline,
8081
const std::string &_base_name,
8182
bool _produce_hybrid_binary):
82-
goto_cc_modet(_cmdline, _base_name),
83+
goto_cc_modet(_cmdline, _base_name, message_handler),
8384
produce_hybrid_binary(_produce_hybrid_binary),
8485
native_tool_name(assembler_name(cmdline, base_name))
8586
{
@@ -137,7 +138,7 @@ int as_modet::doit()
137138
if(cmdline.isset("verbosity"))
138139
verbosity=unsafe_string2unsigned(cmdline.get_value("verbosity"));
139140

140-
ui_message_handler.set_verbosity(verbosity);
141+
message_handler.set_verbosity(verbosity);
141142

142143
if(act_as_as86)
143144
{

src/goto-cc/as_mode.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Date: July 2016
1111
#ifndef CPROVER_GOTO_CC_AS_MODE_H
1212
#define CPROVER_GOTO_CC_AS_MODE_H
1313

14+
#include <util/cout_message.h>
15+
1416
#include "goto_cc_mode.h"
1517

1618
class as_modet:public goto_cc_modet
@@ -22,10 +24,11 @@ class as_modet:public goto_cc_modet
2224
as_modet(
2325
goto_cc_cmdlinet &_cmdline,
2426
const std::string &_base_name,
25-
bool _produce_hybrid_binar);
27+
bool _produce_hybrid_binary);
2628

2729
protected:
28-
bool produce_hybrid_binary;
30+
gcc_message_handlert message_handler;
31+
const bool produce_hybrid_binary;
2932
const std::string native_tool_name;
3033

3134
int run_as(); // call as with original command line

src/goto-cc/cw_mode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ int cw_modet::doit()
5959
if(cmdline.isset("verbosity"))
6060
verbosity=unsafe_string2unsigned(cmdline.get_value("verbosity"));
6161

62-
compiler.ui_message_handler.set_verbosity(verbosity);
63-
ui_message_handler.set_verbosity(verbosity);
62+
compiler.set_message_handler(get_message_handler());
63+
message_handler.set_verbosity(verbosity);
6464

6565
debug() << "CodeWarrior mode" << eom;
6666

src/goto-cc/cw_mode.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Date: June 2006
1111
#ifndef CPROVER_GOTO_CC_CW_MODE_H
1212
#define CPROVER_GOTO_CC_CW_MODE_H
1313

14+
#include <util/cout_message.h>
15+
1416
#include "goto_cc_mode.h"
1517
#include "gcc_cmdline.h"
1618

@@ -21,13 +23,14 @@ class cw_modet:public goto_cc_modet
2123
virtual void help_mode();
2224

2325
cw_modet(gcc_cmdlinet &_gcc_cmdline, const std::string &_base_name):
24-
goto_cc_modet(_gcc_cmdline, _base_name),
26+
goto_cc_modet(_gcc_cmdline, _base_name, message_handler),
2527
cmdline(_gcc_cmdline)
2628
{
2729
}
2830

2931
protected:
3032
gcc_cmdlinet &cmdline;
33+
console_message_handlert message_handler;
3134
};
3235

3336
#endif // CPROVER_GOTO_CC_CW_MODE_H

src/goto-cc/gcc_mode.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ gcc_modet::gcc_modet(
121121
goto_cc_cmdlinet &_cmdline,
122122
const std::string &_base_name,
123123
bool _produce_hybrid_binary):
124-
goto_cc_modet(_cmdline, _base_name),
124+
goto_cc_modet(_cmdline, _base_name, gcc_message_handler),
125125
produce_hybrid_binary(_produce_hybrid_binary),
126126
act_as_ld(base_name=="ld" ||
127127
base_name.find("goto-ld")!=std::string::npos)
@@ -223,7 +223,7 @@ int gcc_modet::doit()
223223
if(cmdline.isset("verbosity"))
224224
verbosity=unsafe_string2unsigned(cmdline.get_value("verbosity"));
225225

226-
ui_message_handler.set_verbosity(verbosity);
226+
gcc_message_handler.set_verbosity(verbosity);
227227

228228
if(act_as_ld)
229229
{
@@ -303,7 +303,7 @@ int gcc_modet::doit()
303303

304304
// determine actions to be undertaken
305305
compilet compiler(cmdline);
306-
compiler.ui_message_handler.set_verbosity(verbosity);
306+
compiler.set_message_handler(get_message_handler());
307307

308308
if(act_as_ld)
309309
compiler.mode=compilet::LINK_LIBRARY;

src/goto-cc/gcc_mode.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@ Date: June 2006
1111
#ifndef CPROVER_GOTO_CC_GCC_MODE_H
1212
#define CPROVER_GOTO_CC_GCC_MODE_H
1313

14+
#include <util/cout_message.h>
15+
1416
#include "goto_cc_mode.h"
1517

1618
class gcc_modet:public goto_cc_modet
1719
{
1820
public:
19-
virtual int doit();
20-
virtual void help_mode();
21+
int doit() final;
22+
void help_mode() final;
2123

2224
gcc_modet(
2325
goto_cc_cmdlinet &_cmdline,
2426
const std::string &_base_name,
2527
bool _produce_hybrid_binary);
2628

2729
protected:
30+
gcc_message_handlert gcc_message_handler;
31+
2832
const bool produce_hybrid_binary;
2933

3034
const bool act_as_ld;

src/goto-cc/goto_cc_mode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ Function: goto_cc_modet::goto_cc_modet
3535

3636
goto_cc_modet::goto_cc_modet(
3737
goto_cc_cmdlinet &_cmdline,
38-
const std::string &_base_name):
39-
language_uit(_cmdline, ui_message_handler),
40-
ui_message_handler(_cmdline, "goto-cc " CBMC_VERSION),
41-
base_name(_base_name),
42-
cmdline(_cmdline)
38+
const std::string &_base_name,
39+
message_handlert &_message_handler):
40+
messaget(_message_handler),
41+
cmdline(_cmdline),
42+
base_name(_base_name)
4343
{
4444
register_languages();
4545
}

src/goto-cc/goto_cc_mode.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Date: June 2006
1515

1616
#include "goto_cc_cmdline.h"
1717

18-
class goto_cc_modet:public language_uit
18+
class goto_cc_modet:public messaget
1919
{
2020
public:
2121
virtual int main(int argc, const char **argv);
@@ -25,15 +25,15 @@ class goto_cc_modet:public language_uit
2525
virtual void usage_error();
2626

2727
goto_cc_modet(
28-
goto_cc_cmdlinet &_cmdline,
29-
const std::string &_base_name);
28+
goto_cc_cmdlinet &,
29+
const std::string &_base_name,
30+
message_handlert &);
3031
~goto_cc_modet();
3132

3233
protected:
33-
ui_message_handlert ui_message_handler;
34+
goto_cc_cmdlinet &cmdline;
3435
const std::string base_name;
3536
void register_languages();
36-
goto_cc_cmdlinet &cmdline;
3737
};
3838

3939
#endif // CPROVER_GOTO_CC_GOTO_CC_MODE_H

src/goto-cc/ms_cl_mode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ int ms_cl_modet::doit()
6969
if(cmdline.isset("verbosity"))
7070
verbosity=unsafe_string2unsigned(cmdline.get_value("verbosity"));
7171

72-
compiler.ui_message_handler.set_verbosity(verbosity);
73-
ui_message_handler.set_verbosity(verbosity);
72+
compiler.set_message_handler(get_message_handler());
73+
message_handler.set_verbosity(verbosity);
7474

7575
debug() << "Visual Studio mode" << eom;
7676

src/goto-cc/ms_cl_mode.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Date: June 2006
1111
#ifndef CPROVER_GOTO_CC_MS_CL_MODE_H
1212
#define CPROVER_GOTO_CC_MS_CL_MODE_H
1313

14+
#include <util/cout_message.h>
15+
1416
#include "goto_cc_mode.h"
1517
#include "ms_cl_cmdline.h"
1618

@@ -23,13 +25,14 @@ class ms_cl_modet:public goto_cc_modet
2325
ms_cl_modet(
2426
ms_cl_cmdlinet &_ms_cl_cmdline,
2527
const std::string &_base_name):
26-
goto_cc_modet(_ms_cl_cmdline, _base_name),
28+
goto_cc_modet(_ms_cl_cmdline, _base_name, message_handler),
2729
cmdline(_ms_cl_cmdline)
2830
{
2931
}
3032

3133
protected:
3234
ms_cl_cmdlinet &cmdline;
35+
console_message_handlert message_handler;
3336
};
3437

3538
#endif // CPROVER_GOTO_CC_MS_CL_MODE_H

src/util/cout_message.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,79 @@ void console_message_handlert::print(
135135
std::cerr << message << '\n' << std::flush;
136136
#endif
137137
}
138+
139+
/*******************************************************************\
140+
141+
Function: gcc_message_handlert::print
142+
143+
Inputs:
144+
145+
Outputs:
146+
147+
Purpose:
148+
149+
\*******************************************************************/
150+
151+
void gcc_message_handlert::print(
152+
unsigned level,
153+
const std::string &message,
154+
int sequence_number,
155+
const source_locationt &location)
156+
{
157+
const irep_idt file=location.get_file();
158+
const irep_idt line=location.get_line();
159+
const irep_idt column=location.get_column();
160+
const irep_idt function=location.get_function();
161+
162+
std::string dest;
163+
164+
if(!function.empty())
165+
{
166+
if(!file.empty())
167+
dest+=id2string(file)+":";
168+
if(dest!="") dest+=' ';
169+
dest+="In function '"+id2string(function)+"':\n";
170+
}
171+
172+
if(!line.empty())
173+
{
174+
if(!file.empty())
175+
dest+=id2string(file)+":";
176+
177+
dest+=id2string(line)+":";
178+
179+
if(column.empty())
180+
dest+="1: ";
181+
else
182+
dest+=id2string(column)+": ";
183+
184+
if(level==message_clientt::M_ERROR)
185+
dest+="error: ";
186+
else if(level==message_clientt::M_WARNING)
187+
dest+="warning: ";
188+
}
189+
190+
dest+=message;
191+
192+
print(level, dest);
193+
}
194+
195+
/*******************************************************************\
196+
197+
Function: gcc_message_handlert::print
198+
199+
Inputs:
200+
201+
Outputs:
202+
203+
Purpose:
204+
205+
\*******************************************************************/
206+
207+
void gcc_message_handlert::print(
208+
unsigned level,
209+
const std::string &message)
210+
{
211+
// gcc appears to send everything to cerr
212+
std::cerr << message << '\n' << std::flush;
213+
}

0 commit comments

Comments
 (0)