Skip to content

Commit

Permalink
[clang-format] Don't split "DPI"/"DPI-C" in Verilog imports (#66951)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aeubanks authored Sep 21, 2023
1 parent 8fb28e4 commit e0388e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions clang/unittests/Format/FormatTestVerilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit e0388e0

Please sign in to comment.