Skip to content

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented Jul 2, 2025

Adopt ArrayRef::consume_front() in PrintMessage, and convert the loop in that function to a range for loop.

Adopt `ArrayRef::consume_front()` in `PrintMessage`, and convert the
loop in that function to a range for loop.
@jurahul jurahul marked this pull request as ready for review July 2, 2025 22:19
@jurahul jurahul requested a review from kuhar July 2, 2025 22:19
@jurahul jurahul requested a review from mshockwave July 2, 2025 22:19
@llvmbot
Copy link
Member

llvmbot commented Jul 2, 2025

@llvm/pr-subscribers-tablegen

Author: Rahul Joshi (jurahul)

Changes

Adopt ArrayRef::consume_front() in PrintMessage, and convert the loop in that function to a range for loop.


Full diff: https://github.com/llvm/llvm-project/pull/146775.diff

1 Files Affected:

  • (modified) llvm/lib/TableGen/Error.cpp (+6-6)
diff --git a/llvm/lib/TableGen/Error.cpp b/llvm/lib/TableGen/Error.cpp
index 91423664a84cc..de0c4c971efeb 100644
--- a/llvm/lib/TableGen/Error.cpp
+++ b/llvm/lib/TableGen/Error.cpp
@@ -24,7 +24,7 @@ namespace llvm {
 SourceMgr SrcMgr;
 unsigned ErrorsPrinted = 0;
 
-static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
+static void PrintMessage(ArrayRef<SMLoc> Locs, SourceMgr::DiagKind Kind,
                          const Twine &Msg) {
   // Count the total number of errors printed.
   // This is used to exit with an error code if there were any errors.
@@ -32,11 +32,11 @@ static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
     ++ErrorsPrinted;
 
   SMLoc NullLoc;
-  if (Loc.empty())
-    Loc = NullLoc;
-  SrcMgr.PrintMessage(Loc.front(), Kind, Msg);
-  for (unsigned i = 1; i < Loc.size(); ++i)
-    SrcMgr.PrintMessage(Loc[i], SourceMgr::DK_Note,
+  if (Locs.empty())
+    Locs = NullLoc;
+  SrcMgr.PrintMessage(Locs.consume_front(), Kind, Msg);
+  for (SMLoc Loc : Locs)
+    SrcMgr.PrintMessage(Loc, SourceMgr::DK_Note,
                         "instantiated from multiclass");
 }
 

Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jurahul jurahul merged commit 9382a95 into llvm:main Jul 3, 2025
13 checks passed
@jurahul jurahul deleted the adopt_consume_front_tablegen_error branch July 3, 2025 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants