| Issue |
71327
|
| Summary |
clang-tidy 15.0.3 SEGFAULT during token parsing on macos-12
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
CramBL
|
No idea what's happening here but the clang-tidy crash says `Error running '/Users/runner/llvm/bin/clang-tidy': PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.` so here I am.
## Stack dump + link to CI
The crash happens on macos-12 in CI and not in any Ubuntu or Windows builds, link to macos job:
https://github.com/CramBL/mtgo-collection-manager/actions/runs/6763154657/job/18379945737.
Stack dump is too large for an issue so here's a link: [raw log - ctrl+f PLEASE takes you to the stack dump](https://pipelinesghubeus25.actions.githubusercontent.com/tygirYM1qxOzrhqLVBX7sg5gMMFN1q1EARz4vRefpCXmMUNl7m/_apis/pipelines/1/runs/1662/signedlogcontent/13?urlExpires=2023-11-05T19%3A10%3A44.0884746Z&urlSigningMethod=HMACV1&urlSignature=DLul%2F7L%2Fd%2BXXOL3ucXYKQznn7VdsfzrrQfaBn0Kd3cU%3D)
## More context
There's several CI runs where the same thing happens.
It appears to happen while clang-tidy is parsing this function `io_util::save_with_timestamp`. [Here's the implementation of that function as of the CI run that produced the logs linked to above](https://github.com/CramBL/mtgo-collection-manager/blob/save-card-price-history/mtgoparser/include/mtgoparser/io.hpp#L91).
Here's a version of that function without preprocessor macros that produced the same clang-tidy crash:
```c++
[[nodiscard]] inline auto save_with_timestamp(const auto &buf, const fs::path &fpath, const auto &ext)
-> outcome::result<fs::path, std::string>
{
try {
// If the path is not to the current directory
if (fpath.has_parent_path()) {
// Create directories if they don't exist
fs::create_directories(fpath.parent_path());
}
// Get the current time
const auto now = std::chrono::system_clock::now();
// Convert to a timestamp in UTC and %Y-%m-%dT%H:%M:%SZ which is ISO 8601
// using formatter: https://en.cppreference.com/w/cpp/chrono/system_clock/formatter
std::string tmp_iso8601_timestamp = std::vformat("{:%FT%TZ}", std::make_format_args(now));
// It has sub-second precision, so remove the decimal point and everything after it, then add a 'Z' to indicate UTC
std::string now_utc_iso8601_timestamp = tmp_iso8601_timestamp.substr(0, tmp_iso8601_timestamp.find('.')) + 'Z';
// Erase-remove idiom to remove colons from timestamp as they are not allowed in Windows file names
now_utc_iso8601_timestamp.erase(
std::remove(now_utc_iso8601_timestamp.begin(), now_utc_iso8601_timestamp.end(), ':'),
now_utc_iso8601_timestamp.end());
std::string final_fname = fmt::format("{}_{}.{}", fpath.stem().string(), now_utc_iso8601_timestamp, ext);
fs::path fpath_with_time =
fpath.has_parent_path() ? fpath.parent_path() / final_fname : boost::implicit_cast<fs::path>(final_fname);
// Open the file
std::ofstream file(fpath_with_time, std::ios::binary | std::ios::out);
if (file.bad()) {
return outcome::failure(fmt::format("Bad operation during opening of file: {}", fpath_with_time.string()));
}
if (file.is_open()) {
// Write the buffer to the file
file.write(buf.data(), static_cast<std::streamsize>(buf.size()));
// Close the file
file.close();
} else {
return outcome::failure(fmt::format("Expected file to be open: {}", fpath_with_time.string()));
}
// Return the file name
return outcome::success(fpath_with_time);
} catch (const std::exception &e) {
return outcome::failure(fmt::format("Failed to save file from path: {}, err: {}", fpath.string(), e.what()));
}
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs