Skip to content

goto-cc: show error line #3230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions regression/ansi-c/const1/const-array.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CORE
const-array.c
^.*: .* is constant$
^ array\[1\] = 2;$
^EXIT=(1|64)$
^SIGNAL=0$
--
1 change: 1 addition & 0 deletions regression/ansi-c/const1/const-member.desc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CORE
const-member.c

^.*: .* is constant$
^ const_struct_ptr->field = 123;$
^EXIT=(1|64)$
^SIGNAL=0$
--
21 changes: 21 additions & 0 deletions src/util/cout_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Author: Daniel Kroening, [email protected]

#include "cout_message.h"

#include <fstream>
#include <iostream>

#ifdef _WIN32
Expand Down Expand Up @@ -185,6 +186,26 @@ void gcc_message_handlert::print(
dest+=message;

print(level, dest);

const auto file_name = location.full_path();
if(file_name.has_value() && !line.empty())
{
#ifdef _WIN32
std::ifstream in(widen(file_name.value()));
#else
std::ifstream in(file_name.value());
#endif
if(in)
{
const auto line_number = std::stoull(id2string(line));
std::string line;
for(std::size_t l = 0; l < line_number; l++)
std::getline(in, line);

if(in)
print(level, " " + line); // gcc adds a space, clang doesn't
}
}
}

void gcc_message_handlert::print(
Expand Down
13 changes: 13 additions & 0 deletions src/util/source_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ void source_locationt::merge(const source_locationt &from)
}
}

/// Get a path to the file, including working directory.
/// \return Full path unless the file name is empty or refers
/// to a built-in, in which case {} is returned.
optionalt<std::string> source_locationt::full_path() const
{
const auto file = id2string(get_file());

if(file.empty() || is_built_in(file))
return {};

return concat_dir_file(id2string(get_working_directory()), file);
}

std::ostream &operator << (
std::ostream &out,
const source_locationt &source_location)
Expand Down
3 changes: 3 additions & 0 deletions src/util/source_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]

#include "invariant.h"
#include "irep.h"
#include "optional.h"
#include "prefix.h"

#include <string>
Expand Down Expand Up @@ -185,6 +186,8 @@ class source_locationt:public irept
return static_cast<const source_locationt &>(get_nil_irep());
}

optionalt<std::string> full_path() const;

protected:
std::string as_string(bool print_cwd) const;
};
Expand Down