Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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