https://github.com/hnakamura5 created https://github.com/llvm/llvm-project/pull/155837
Fixes https://github.com/llvm/llvm-project/issues/154634. Allow inserting space before DAGArg's opener paren when nested. >From 2cc33a8a0d2cb266a52483c6bb5bcc2e95564db9 Mon Sep 17 00:00:00 2001 From: hnakamura5 <k.nakamura.hirof...@gmail.com> Date: Thu, 28 Aug 2025 22:28:56 +0900 Subject: [PATCH] [clang-format] Fix TableGen nested DAGArg format --- clang/lib/Format/TokenAnnotator.cpp | 13 ++++++++++++- clang/unittests/Format/FormatTestTableGen.cpp | 11 +++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index a220de54f46bf..997fcfc2159dc 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1045,6 +1045,14 @@ class AnnotatingParser { } } // Parse the [DagArgList] part + return parseTableGenDAGArgList(Opener, BreakInside); + } + + // DagArgList ::= "," DagArg [DagArgList] + // This parses SimpleValue 6's [DagArgList] part. + bool parseTableGenDAGArgList(FormatToken *Opener, bool BreakInside) { + ScopedContextCreator ContextCreator(*this, tok::l_paren, 1); + Contexts.back().IsTableGenDAGArgList = true; bool FirstDAGArgListElm = true; while (CurrentToken) { if (!FirstDAGArgListElm && CurrentToken->is(tok::comma)) { @@ -1101,6 +1109,9 @@ class AnnotatingParser { // SimpleValue6 ::= "(" DagArg [DagArgList] ")" if (Tok->is(tok::l_paren)) { Tok->setType(TT_TableGenDAGArgOpener); + // Nested DAGArg requires space before '(' as separator. + if (Contexts.back().IsTableGenDAGArgList) + Tok->SpacesRequiredBefore = 1; return parseTableGenDAGArgAndList(Tok); } // SimpleValue 9: Bang operator @@ -2138,7 +2149,7 @@ class AnnotatingParser { // Whether the braces may mean concatenation instead of structure or array // literal. bool VerilogMayBeConcatenation = false; - bool IsTableGenDAGArg = false; + bool IsTableGenDAGArgList = false; bool IsTableGenBangOpe = false; bool IsTableGenCondOpe = false; enum { diff --git a/clang/unittests/Format/FormatTestTableGen.cpp b/clang/unittests/Format/FormatTestTableGen.cpp index 1c3d187de393c..33acd2435d289 100644 --- a/clang/unittests/Format/FormatTestTableGen.cpp +++ b/clang/unittests/Format/FormatTestTableGen.cpp @@ -185,11 +185,18 @@ TEST_F(FormatTestTableGen, SimpleValue6) { " i32:$dst6, // dst6\n" " i32:$dst7 // dst7\n" " );\n" - " let DAGArgBang = (!cast<SomeType>(\"Some\") i32:$src1,\n" - " i32:$src2);\n" + " let DAGArgBang =\n" + " (!cast<SomeType>(\"Some\") i32:$src1, i32:$src2);\n" + " let NestedDAGArg = ((DAGArg1 (v111 v112, v113), v12) v2,\n" + " (DAGArg3 (v31 v32)));\n" "}"); } +TEST_F(FormatTestTableGen, SimpleValue6_NestedInPat) { + verifyFormat("def : Pat<(vec.vt (avg (vec.vt V128:$l), (vec.vt V128:$r))),\n" + " (inst $l, $r)>;"); +} + TEST_F(FormatTestTableGen, SimpleValue7) { verifyFormat("def SimpleValue7 { let Identifier = SimpleValue; }"); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits