[llvm] [TableGen] Add PrintError family overload that take a print function (PR #107333)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 08:23:02 PDT 2024


================
@@ -1600,18 +1601,13 @@ static TreePatternNode &getOperandNum(unsigned OpNo, TreePatternNode &N,
     return N;
   }
 
-  OpNo -= NumResults;
-
-  if (OpNo >= N.getNumChildren()) {
-    std::string S;
-    raw_string_ostream OS(S);
-    OS << "Invalid operand number in type constraint " << (OpNo + NumResults)
-       << " ";
-    N.print(OS);
-    PrintFatalError(S);
+  if (OpNo - NumResults >= N.getNumChildren()) {
+    PrintFatalError([&N, OpNo](raw_ostream &OS) {
+      OS << formatv("Invalid operand number {0} in type constraint ", OpNo);
----------------
jurahul wrote:

AFAIK it does not. It splits the format string into fragments and prints them one-by-one. Though in this case, may be what you suggested is better (in the sense what we are printing is relatively simple and does not warrant use of formatv). I'll change it.

https://github.com/llvm/llvm-project/pull/107333


More information about the llvm-commits mailing list