Skip to content

Commit 253ff32

Browse files
authored
[clang-format] Stop crashing when formatting Verilog (#112043)
The part of the code for parsing Verilog module instantiations dereferenced a pointer without checking for null pointer. The pointer may be null if the input is not complete and a line starts with a comma.
1 parent 9c64b5e commit 253ff32

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,8 @@ class AnnotatingParser {
15511551
// Case D.
15521552
if (Keywords.isVerilogIdentifier(*Prev) && PrevPrev->is(tok::comma)) {
15531553
const FormatToken *PrevParen = PrevPrev->getPreviousNonComment();
1554-
if (PrevParen->is(tok::r_paren) && PrevParen->MatchingParen &&
1554+
if (PrevParen && PrevParen->is(tok::r_paren) &&
1555+
PrevParen->MatchingParen &&
15551556
PrevParen->MatchingParen->is(TT_VerilogInstancePortLParen)) {
15561557
return true;
15571558
}

clang/unittests/Format/FormatTestVerilog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ TEST_F(FormatTestVerilog, Instantiation) {
964964
" .qbar(out1),\n"
965965
" .clear(in1),\n"
966966
" .preset(in2));");
967+
verifyNoCrash(", ff1();");
967968
// With breaking between instance ports disabled.
968969
auto Style = getDefaultStyle();
969970
Style.VerilogBreakBetweenInstancePorts = false;

0 commit comments

Comments
 (0)