Skip to content

Commit f5664f5

Browse files
authored
[Support] Do not ignore unterminated open { in formatv (#104688)
- When an unterminated open { is detected in the format string, instead of asserting and ignoring the error, replace that string with another to indicate the error, and remove the assert as well. - This will make the error evident in both assert and release builds and make observing the error more convenient (as several uses of this function are in TableGen and it is often built in release mode even in debug builds)
1 parent c478139 commit f5664f5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

llvm/lib/Support/FormatVariadic.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,18 @@ formatv_object_base::splitLiteralAndReplacement(StringRef Fmt) {
107107
StringRef Right = Fmt.drop_front(NumEscapedBraces * 2);
108108
return std::make_pair(ReplacementItem{Middle}, Right);
109109
}
110-
// An unterminated open brace is undefined. We treat the rest of the string
111-
// as a literal replacement, but we assert to indicate that this is
112-
// undefined and that we consider it an error.
110+
// An unterminated open brace is undefined. Assert to indicate that this is
111+
// undefined and that we consider it an error. When asserts are disabled,
112+
// build a replacement item with an error message.
113113
std::size_t BC = Fmt.find_first_of('}');
114114
if (BC == StringRef::npos) {
115115
assert(
116116
false &&
117-
"Unterminated brace sequence. Escape with {{ for a literal brace.");
118-
return std::make_pair(ReplacementItem{Fmt}, StringRef());
117+
"Unterminated brace sequence. Escape with {{ for a literal brace.");
118+
return std::make_pair(
119+
ReplacementItem{"Unterminated brace sequence. Escape with {{ for a "
120+
"literal brace."},
121+
StringRef());
119122
}
120123

121124
// Even if there is a closing brace, if there is another open brace before

0 commit comments

Comments
 (0)