Skip to content

Commit

Permalink
Fix dangling help message.
Browse files Browse the repository at this point in the history
An ephemeral string in a flag help message ends up being assigned
to a string_view which holds the reference to that temporary.

Instead, keep the generated help message backed by storage, so that
it can be safely passed to a string_view.

#xls-build-gardener

PiperOrigin-RevId: 683838862
  • Loading branch information
hzeller authored and copybara-github committed Oct 9, 2024
1 parent 401cbce commit e6932ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions xls/tools/opt_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ ABSL_FLAG(
"they have fewer than the given number of cases. This optimization is "
"skipped for selects with more cases, since it can sometimes reduce output "
"quality by replacing MUX trees with separate equality checks.");
ABSL_FLAG(int64_t, opt_level, xls::kMaxOptLevel,
absl::StrFormat("Optimization level. Ranges from 1 to %d.",
xls::kMaxOptLevel));
ABSL_FLAG(int64_t, opt_level, xls::kMaxOptLevel, []() -> const std::string& {
static const std::string kDescription = absl::StrFormat(
"Optimization level. Ranges from 1 to %d.", xls::kMaxOptLevel);
return kDescription;
}());
ABSL_FLAG(bool, inline_procs, false,
"Whether to inline all procs by calling the proc inlining pass.");
ABSL_FLAG(std::string, ram_rewrites_pb, "",
Expand Down
8 changes: 5 additions & 3 deletions xls/tools/scheduling_options_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
#include "xls/tools/scheduling_options_flags.pb.h"

// LINT.IfChange
ABSL_FLAG(int64_t, opt_level, xls::kMaxOptLevel,
absl::StrFormat("Optimization level. Ranges from 1 to %d.",
xls::kMaxOptLevel));
ABSL_FLAG(int64_t, opt_level, xls::kMaxOptLevel, []() -> const std::string& {
static const std::string kDescription = absl::StrFormat(
"Optimization level. Ranges from 1 to %d.", xls::kMaxOptLevel);
return kDescription;
}());
ABSL_FLAG(int64_t, clock_period_ps, 0,
"Target clock period, in picoseconds. See "
"https://google.github.io/xls/scheduling for details.");
Expand Down

0 comments on commit e6932ec

Please sign in to comment.