Skip to content

Commit e0388e0

Browse files
authored
[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.
1 parent 8fb28e4 commit e0388e0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,16 @@ ContinuationIndenter::createBreakableToken(const FormatToken &Current,
22702270
if (State.Stack.back().IsInsideObjCArrayLiteral)
22712271
return nullptr;
22722272

2273+
// The "DPI"/"DPI-C" in SystemVerilog direct programming interface
2274+
// imports/exports cannot be split, e.g.
2275+
// `import "DPI" function foo();`
2276+
// FIXME: make this use same infra as C++ import checks
2277+
if (Style.isVerilog() && Current.Previous &&
2278+
Current.Previous->isOneOf(tok::kw_export, Keywords.kw_import)) {
2279+
return nullptr;
2280+
}
22732281
StringRef Text = Current.TokenText;
2282+
22742283
// We need this to address the case where there is an unbreakable tail only
22752284
// if certain other formatting decisions have been taken. The
22762285
// UnbreakableTailLength of Current is an overapproximation in that case and

clang/unittests/Format/FormatTestVerilog.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,15 @@ TEST_F(FormatTestVerilog, StringLiteral) {
12531253
"xxxx"});)",
12541254
R"(x({"xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx ", "xxxx"});)",
12551255
getStyleWithColumns(getDefaultStyle(), 23));
1256+
// import/export "DPI"/"DPI-C" cannot be split.
1257+
verifyFormat(R"(import
1258+
"DPI-C" function void foo
1259+
();)",
1260+
R"(import "DPI-C" function void foo();)",
1261+
getStyleWithColumns(getDefaultStyle(), 23));
1262+
verifyFormat(R"(export "DPI-C" function foo;)",
1263+
R"(export "DPI-C" function foo;)",
1264+
getStyleWithColumns(getDefaultStyle(), 23));
12561265
// These kinds of strings don't exist in Verilog.
12571266
verifyNoCrash(R"(x(@"xxxxxxxxxxxxxxxx xxxx");)",
12581267
getStyleWithColumns(getDefaultStyle(), 23));

0 commit comments

Comments
 (0)