[llvm] [Support] Do not ignore unterminated open { in formatv (PR #104688)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 18 05:45:22 PDT 2024
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/104688
>From 602f080da145906a76c507277ea3a76fd16baab5 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Sat, 17 Aug 2024 17:04:26 -0700
Subject: [PATCH] [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.
---
llvm/lib/Support/FormatVariadic.cpp | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Support/FormatVariadic.cpp b/llvm/lib/Support/FormatVariadic.cpp
index 3c07a80a00ae6d..f23a948e6c52bd 100644
--- a/llvm/lib/Support/FormatVariadic.cpp
+++ b/llvm/lib/Support/FormatVariadic.cpp
@@ -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,
+ // built 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
More information about the llvm-commits
mailing list