[clang] c1ec5be - [clang-format] Fix a TableGen crash on comment after l_paren (#124380)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 25 18:31:45 PST 2025


Author: Owen Pan
Date: 2025-01-25T18:31:42-08:00
New Revision: c1ec5beb4ab36c2c4d99ed6d735d217e74364771

URL: https://github.com/llvm/llvm-project/commit/c1ec5beb4ab36c2c4d99ed6d735d217e74364771
DIFF: https://github.com/llvm/llvm-project/commit/c1ec5beb4ab36c2c4d99ed6d735d217e74364771.diff

LOG: [clang-format] Fix a TableGen crash on comment after l_paren (#124380)

Fixes #124248.

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTestTableGen.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index bc41d43d1438c5..655766178fbb0e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1115,7 +1115,7 @@ class AnnotatingParser {
       }
       if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
         return false;
-      skipToNextNonComment();
+      next();
       // FIXME: Hack using inheritance to child context
       Contexts.back().IsTableGenBangOpe = true;
       bool Result = parseParens();
@@ -1124,12 +1124,10 @@ class AnnotatingParser {
     }
     // SimpleValue 9: Cond operator
     if (Tok->is(TT_TableGenCondOperator)) {
-      Tok = CurrentToken;
-      skipToNextNonComment();
-      if (!Tok || Tok->isNot(tok::l_paren))
+      if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
         return false;
-      bool Result = parseParens();
-      return Result;
+      next();
+      return parseParens();
     }
     // We have to check identifier at the last because the kind of bang/cond
     // operators are also identifier.

diff  --git a/clang/unittests/Format/FormatTestTableGen.cpp b/clang/unittests/Format/FormatTestTableGen.cpp
index 7771f6a109a9ac..92377c31f2e911 100644
--- a/clang/unittests/Format/FormatTestTableGen.cpp
+++ b/clang/unittests/Format/FormatTestTableGen.cpp
@@ -101,6 +101,9 @@ TEST_F(FormatTestTableGen, BangOperators) {
                "                                  \"zerozero\",\n"
                "                                  true:  // default\n"
                "                                  \"positivepositive\");\n"
+               "  let CondOpe3WithCommentAfterLParen = !cond(\n"
+               "      // comment\n"
+               "      !eq(/* comment */ x, 0): \"zero\");\n"
                "}");
 }
 


        


More information about the cfe-commits mailing list