[clang] a4e8604 - [clang-format] Recognize the signed modifier for Verilog struct (#219694)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 8 06:27:23 PDT 2026


Author: sstwcw
Date: 2026-09-08T13:27:18Z
New Revision: a4e8604a2da580de80debb6a15c9c6d7379a68d5

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

LOG: [clang-format] Recognize the signed modifier for Verilog struct (#219694)

after

```SystemVerilog
struct packed signed {
  int a;
} pack1;
```

before

```SystemVerilog
struct packed signed { int a; }
pack1;
```

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp
    clang/unittests/Format/FormatTestVerilog.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index f2ea03b86aae4..ac3eb6fa5bcf5 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4155,7 +4155,9 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr, bool IsJavaRecord) {
                             tok::kw_alignas, tok::l_square) ||
          FormatTok->isAttribute() ||
          ((Style.isJava() || Style.isJavaScript()) &&
-          FormatTok->isOneOf(tok::period, tok::comma))) {
+          FormatTok->isOneOf(tok::period, tok::comma)) ||
+         (Style.isVerilog() &&
+          FormatTok->isOneOf(tok::kw_signed, tok::kw_unsigned))) {
     if (Style.isJavaScript() &&
         FormatTok->isOneOf(Keywords.kw_extends, Keywords.kw_implements)) {
       JSPastExtendsOrImplements = true;

diff  --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp
index 9b92d3e19204d..9baa3210dbd82 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -1412,6 +1412,27 @@ TEST_F(FormatTestVerilog, StringLiteral) {
                  getStyleWithColumns(getDefaultStyle(), 29));
 }
 
+TEST_F(FormatTestVerilog, Struct) {
+  verifyFormat("struct packed signed {\n"
+               "  int a;\n"
+               "} pack1;");
+  verifyFormat("struct packed {\n"
+               "  int a;\n"
+               "} pack1;");
+  verifyFormat("struct {\n"
+               "  int a;\n"
+               "} pack1;");
+  verifyFormat("typedef struct packed signed {\n"
+               "  bit [3 : 0] GFC;\n"
+               "} s_atmcell;");
+  verifyFormat("typedef struct {\n"
+               "  bit [3 : 0] GFC;\n"
+               "} s_atmcell;");
+  verifyFormat("typedef struct packed {\n"
+               "  bit [3 : 0] GFC;\n"
+               "} s_atmcell;");
+}
+
 TEST_F(FormatTestVerilog, StructLiteral) {
   verifyFormat("c = '{0, 0.0};");
   verifyFormat("c = '{'{1, 1.0}, '{2, 2.0}};");


        


More information about the cfe-commits mailing list