[llvm] [Support] Do not ignore unterminated open { in formatv (PR #104688)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 17 17:11:14 PDT 2024


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/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 behvaior indentical between assert and release builds and also help catch the error more convienent (as several uses of this function are in TableGen and its if often built in release mode even in debug builds, using

>From 62529b4ee52fb879aa36a4aadb0f812f3d33a1eb 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 ignoring the error, replace that string with another
to indicate the error, and remove the assert as well.
- This will make the error behvaior indentical between assert and
  release builds and also help catch the error more convienent (as
several uses of this function are in TableGen and its if often built in
release mode even in debug builds, using
---
 llvm/lib/Support/FormatVariadic.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Support/FormatVariadic.cpp b/llvm/lib/Support/FormatVariadic.cpp
index 3c07a80a00ae6d..5e940c0859d8af 100644
--- a/llvm/lib/Support/FormatVariadic.cpp
+++ b/llvm/lib/Support/FormatVariadic.cpp
@@ -112,10 +112,8 @@ formatv_object_base::splitLiteralAndReplacement(StringRef Fmt) {
     // undefined and that we consider it an error.
     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());
+      return std::make_pair(ReplacementItem{"Unterminated open {"},
+                            StringRef());
     }
 
     // Even if there is a closing brace, if there is another open brace before



More information about the llvm-commits mailing list