[clang] e0388e0 - [clang-format] Don't split "DPI"/"DPI-C" in Verilog imports (#66951)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 21 11:21:25 PDT 2023


Author: Arthur Eubanks
Date: 2023-09-21T11:21:20-07:00
New Revision: e0388e0e061d2499aa654c28a3c4a5a27f7d7a28

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

LOG: [clang-format] Don't split "DPI"/"DPI-C" in Verilog imports (#66951)

The spec doesn't allow splitting these strings and we're seeing compile
issues with splitting it.

String splitting was enabled for Verilog in
https://reviews.llvm.org/D154093.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index deb3e554fdc124b..68103c45b0b9463 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -2270,7 +2270,16 @@ ContinuationIndenter::createBreakableToken(const FormatToken &Current,
     if (State.Stack.back().IsInsideObjCArrayLiteral)
       return nullptr;
 
+    // The "DPI"/"DPI-C" in SystemVerilog direct programming interface
+    // imports/exports cannot be split, e.g.
+    // `import "DPI" function foo();`
+    // FIXME: make this use same infra as C++ import checks
+    if (Style.isVerilog() && Current.Previous &&
+        Current.Previous->isOneOf(tok::kw_export, Keywords.kw_import)) {
+      return nullptr;
+    }
     StringRef Text = Current.TokenText;
+
     // We need this to address the case where there is an unbreakable tail only
     // if certain other formatting decisions have been taken. The
     // UnbreakableTailLength of Current is an overapproximation in that case and

diff  --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp
index 945e06143ccc3f1..4c0a065daadd9ad 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -1253,6 +1253,15 @@ TEST_F(FormatTestVerilog, StringLiteral) {
    "xxxx"});)",
                R"(x({"xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx ", "xxxx"});)",
                getStyleWithColumns(getDefaultStyle(), 23));
+  // import/export "DPI"/"DPI-C" cannot be split.
+  verifyFormat(R"(import
+    "DPI-C" function void foo
+    ();)",
+               R"(import "DPI-C" function void foo();)",
+               getStyleWithColumns(getDefaultStyle(), 23));
+  verifyFormat(R"(export "DPI-C" function foo;)",
+               R"(export "DPI-C" function foo;)",
+               getStyleWithColumns(getDefaultStyle(), 23));
   // These kinds of strings don't exist in Verilog.
   verifyNoCrash(R"(x(@"xxxxxxxxxxxxxxxx xxxx");)",
                 getStyleWithColumns(getDefaultStyle(), 23));


        


More information about the cfe-commits mailing list