Skip to content

Commit 602f080

Browse files
committed
[Support] Do not ignore unterminated open { in formatv
- When an unterminated open { is detected in the format string, instead of asserting and then ignoring the error, replace that string with another to indicate the error. - This will cause release builds to fail as well in some way, and help debug malformed format strings better in LLVM_OPTIMIZED_TABLEGEN=ON builds.
1 parent e9e3a18 commit 602f080

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+
// built 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)