Skip to content

Commit

Permalink
Remember normalized paths when checking for duplicate files in driver.
Browse files Browse the repository at this point in the history
While we ignore duplicate files it was still possible to erroneously add
the same file multiple times to a compilation. Catch this trivial case.
  • Loading branch information
bbannier committed Jul 31, 2024
1 parent 4bbc2c7 commit 3985ae7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions hilti/toolchain/src/compiler/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <exception>
#include <fstream>
#include <iostream>
#include <system_error>
#include <utility>

#include <hilti/rt/libhilti.h>
Expand Down Expand Up @@ -552,7 +553,15 @@ Result<void*> Driver::_symbol(const std::string& symbol) {
}

Result<Nothing> Driver::addInput(const hilti::rt::filesystem::path& path) {
if ( _processed_paths.find(path.native()) != _processed_paths.end() )
auto path_normalized = path.lexically_normal();
if ( path_normalized.is_relative() ) {
std::error_code ec;
path_normalized = rt::filesystem::absolute(path_normalized, ec);
if ( ec )
return result::Error(fmt("could not compute absolute path for %s", path_normalized));
}

if ( _processed_paths.count(path_normalized.native()) )
return Nothing();

// Calling hook before stage check so that it can execute initialize()
Expand Down Expand Up @@ -595,7 +604,6 @@ Result<Nothing> Driver::addInput(const hilti::rt::filesystem::path& path) {

HILTI_DEBUG(logging::debug::Driver, fmt("adding external C++ file %s", path));
_external_cxxs.push_back(path);
return Nothing();
}

else if ( path.extension() == ".hlto" ) {
Expand All @@ -612,9 +620,10 @@ Result<Nothing> Driver::addInput(const hilti::rt::filesystem::path& path) {
}
}

_processed_paths.insert(path);
else
return error("unsupported file type", path);

_processed_paths.insert(path.native());
_processed_paths.insert(path_normalized.native());

return Nothing();
}
Expand Down

0 comments on commit 3985ae7

Please sign in to comment.