diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index deb3e554fdc12..68103c45b0b94 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 945e06143ccc3..4c0a065daadd9 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));