Skip to content

[Support] Do not ignore unterminated open { in formatv #104688

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 1 commit into from
Aug 19, 2024
Merged
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
13 changes: 8 additions & 5 deletions llvm/lib/Support/FormatVariadic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,18 @@ formatv_object_base::splitLiteralAndReplacement(StringRef Fmt) {
StringRef Right = Fmt.drop_front(NumEscapedBraces * 2);
return std::make_pair(ReplacementItem{Middle}, Right);
}
// An unterminated open brace is undefined. We treat the rest of the string
// as a literal replacement, but we assert to indicate that this is
// undefined and that we consider it an error.
// An unterminated open brace is undefined. Assert to indicate that this is
// undefined and that we consider it an error. When asserts are disabled,
// build a replacement item with an error message.
std::size_t BC = Fmt.find_first_of('}');
if (BC == StringRef::npos) {
assert(
false &&
"Unterminated brace sequence. Escape with {{ for a literal brace.");
return std::make_pair(ReplacementItem{Fmt}, StringRef());
"Unterminated brace sequence. Escape with {{ for a literal brace.");
return std::make_pair(
ReplacementItem{"Unterminated brace sequence. Escape with {{ for a "
"literal brace."},
StringRef());
}

// Even if there is a closing brace, if there is another open brace before
Expand Down
Loading