Skip to content

Commit 8ffb656

Browse files
authored
Merge pull request #3230 from diffblue/goto-cc-show-error-line
goto-cc: show error line
2 parents 8a398ee + 3a1b47f commit 8ffb656

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CORE
22
const-array.c
33
^.*: .* is constant$
4+
^ array\[1\] = 2;$
45
^EXIT=(1|64)$
56
^SIGNAL=0$
67
--

regression/ansi-c/const1/const-member.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ CORE
22
const-member.c
33

44
^.*: .* is constant$
5+
^ const_struct_ptr->field = 123;$
56
^EXIT=(1|64)$
67
^SIGNAL=0$
78
--

src/util/cout_message.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "cout_message.h"
1010

11+
#include <fstream>
1112
#include <iostream>
1213

1314
#ifdef _WIN32
@@ -185,6 +186,26 @@ void gcc_message_handlert::print(
185186
dest+=message;
186187

187188
print(level, dest);
189+
190+
const auto file_name = location.full_path();
191+
if(file_name.has_value() && !line.empty())
192+
{
193+
#ifdef _WIN32
194+
std::ifstream in(widen(file_name.value()));
195+
#else
196+
std::ifstream in(file_name.value());
197+
#endif
198+
if(in)
199+
{
200+
const auto line_number = std::stoull(id2string(line));
201+
std::string line;
202+
for(std::size_t l = 0; l < line_number; l++)
203+
std::getline(in, line);
204+
205+
if(in)
206+
print(level, " " + line); // gcc adds a space, clang doesn't
207+
}
208+
}
188209
}
189210

190211
void gcc_message_handlert::print(

src/util/source_location.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ void source_locationt::merge(const source_locationt &from)
7171
}
7272
}
7373

74+
/// Get a path to the file, including working directory.
75+
/// \return Full path unless the file name is empty or refers
76+
/// to a built-in, in which case {} is returned.
77+
optionalt<std::string> source_locationt::full_path() const
78+
{
79+
const auto file = id2string(get_file());
80+
81+
if(file.empty() || is_built_in(file))
82+
return {};
83+
84+
return concat_dir_file(id2string(get_working_directory()), file);
85+
}
86+
7487
std::ostream &operator << (
7588
std::ostream &out,
7689
const source_locationt &source_location)

src/util/source_location.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212

1313
#include "invariant.h"
1414
#include "irep.h"
15+
#include "optional.h"
1516
#include "prefix.h"
1617

1718
#include <string>
@@ -185,6 +186,8 @@ class source_locationt:public irept
185186
return static_cast<const source_locationt &>(get_nil_irep());
186187
}
187188

189+
optionalt<std::string> full_path() const;
190+
188191
protected:
189192
std::string as_string(bool print_cwd) const;
190193
};

0 commit comments

Comments
 (0)