aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorsstwcw <su3e8a96kzlver@posteo.net>2024-11-13 05:37:04 +0000
committersstwcw <su3e8a96kzlver@posteo.net>2024-11-20 04:49:58 +0000
commit0ff8b79160509b25fd913ffa320b9dab5b87b55e (patch)
treef835a3cabe2942b8798c553cb901e9e1fdd1fb72 /clang/lib/Format/UnwrappedLineParser.cpp
parent27d25d1c12a34d0cfd47416e77cd83b7b768f1e7 (diff)
downloadllvm-0ff8b79160509b25fd913ffa320b9dab5b87b55e.zip
llvm-0ff8b79160509b25fd913ffa320b9dab5b87b55e.tar.gz
llvm-0ff8b79160509b25fd913ffa320b9dab5b87b55e.tar.bz2
[clang-format] Stop crashing on slightly off Verilog module headers (#116000)
This piece of code made the program crash. ```Verilog function pkg::t get (int t = 2, int f = 2); ``` The way the code is supposed to be parsed is that UnwrappedLineParser should identify the function header, and then TokenAnnotator should recognize the result. But the code in UnwrappedLineParser would mistakenly not recognize it due to the `::`. Then TokenAnnotator would recognize the comma both as TT_VerilogInstancePortComma and TT_VerilogTypeComma. The code for annotating the instance port comma used `setFinalizedType`. The program would crash when it tried to set it to another type. The code in UnwrappedLineParser now recognizes the `::` token. The are other cases in which TokenAnnotator would recognize the comma as both of those types, for example if the `function` keyword is removed. The type is now set using `setType` instead so that the program does not crash. The developer no longer knows why he used `setFinalizedType` back then.
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 5f1dd38..c182aaf 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4441,7 +4441,8 @@ unsigned UnwrappedLineParser::parseVerilogHierarchyHeader() {
Prev->setFinalizedType(TT_VerilogDimensionedTypeName);
parseSquare();
} else if (Keywords.isVerilogIdentifier(*FormatTok) ||
- FormatTok->isOneOf(Keywords.kw_automatic, tok::kw_static)) {
+ FormatTok->isOneOf(tok::hash, tok::hashhash, tok::coloncolon,
+ Keywords.kw_automatic, tok::kw_static)) {
nextToken();
} else {
break;