Skip to content

Commit 57af742

Browse files
committed
goto-cc: also use the linker when processing multiple source files
The linker is able to do some type sanitisation across translation units, and there is no reason behaviour should be different whether we link previously compiled object files or a set of source files.
1 parent b3cc3e9 commit 57af742

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/goto-cc/compile.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Date: June 2006
3434

3535
#include <goto-programs/goto_convert.h>
3636
#include <goto-programs/goto_convert_functions.h>
37+
#include <goto-programs/link_goto_model.h>
3738
#include <goto-programs/read_goto_binary.h>
3839
#include <goto-programs/write_goto_binary.h>
3940

@@ -359,9 +360,9 @@ bool compilet::compile()
359360
if(echo_file_name)
360361
std::cout << get_base_name(file_name, false) << '\n' << std::flush;
361362

362-
bool r=parse_source(file_name); // don't break the program!
363+
auto file_goto_model = parse_source(file_name);
363364

364-
if(r)
365+
if(!file_goto_model.has_value())
365366
{
366367
const std::string &debug_outfile=
367368
cmdline.get_value("print-rejected-preprocessed-source");
@@ -381,7 +382,7 @@ bool compilet::compile()
381382
// output an object file for every source file
382383

383384
// "compile" functions
384-
convert_symbols(goto_model.goto_functions);
385+
convert_symbols(file_goto_model->goto_functions);
385386

386387
std::string cfn;
387388

@@ -398,14 +399,14 @@ bool compilet::compile()
398399
else
399400
cfn = output_file_object;
400401

401-
if(write_bin_object_file(cfn, goto_model))
402+
if(write_bin_object_file(cfn, *file_goto_model))
402403
return true;
403404

404-
if(add_written_cprover_symbols(goto_model.symbol_table))
405+
if(add_written_cprover_symbols(file_goto_model->symbol_table))
405406
return true;
406-
407-
goto_model.clear(); // clean symbol table for next source file.
408407
}
408+
else
409+
link_goto_model(goto_model, *file_goto_model, get_message_handler());
409410
}
410411

411412
return false;
@@ -579,30 +580,31 @@ bool compilet::write_bin_object_file(
579580
return false;
580581
}
581582

582-
/// parses a source file
583-
/// \return true on error, false otherwise
584-
bool compilet::parse_source(const std::string &file_name)
583+
/// Parses and type checks a source file located at \p file_name.
584+
/// \return A goto model if, and only if, parsing and type checking succeeded.
585+
optionalt<goto_modelt> compilet::parse_source(const std::string &file_name)
585586
{
586587
language_filest language_files;
587588
language_files.set_message_handler(get_message_handler());
588589

589590
if(parse(file_name, language_files))
590-
return true;
591+
return {};
591592

592593
// we just typecheck one file here
593-
if(language_files.typecheck(goto_model.symbol_table))
594+
goto_modelt file_goto_model;
595+
if(language_files.typecheck(file_goto_model.symbol_table))
594596
{
595597
error() << "CONVERSION ERROR" << eom;
596-
return true;
598+
return {};
597599
}
598600

599-
if(language_files.final(goto_model.symbol_table))
601+
if(language_files.final(file_goto_model.symbol_table))
600602
{
601603
error() << "CONVERSION ERROR" << eom;
602-
return true;
604+
return {};
603605
}
604606

605-
return false;
607+
return std::move(file_goto_model);
606608
}
607609

608610
/// constructor

src/goto-cc/compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class compilet : public messaget
7171
bool compile();
7272
bool link();
7373

74-
bool parse_source(const std::string &);
74+
optionalt<goto_modelt> parse_source(const std::string &);
7575

7676
bool write_bin_object_file(const std::string &, const goto_modelt &);
7777

0 commit comments

Comments
 (0)