diff options
author | sstwcw <su3e8a96kzlver@posteo.net> | 2025-04-10 12:52:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-10 12:52:02 +0000 |
commit | f7617f7f909102080f1a0cee46f8ca75ec8d14ff (patch) | |
tree | 29c86efc4c2f825d09bdabde1a3e9ba04cec0d36 /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | ed858220276dd11f6c2d7a5d3e357c211f9c6190 (diff) | |
download | llvm-f7617f7f909102080f1a0cee46f8ca75ec8d14ff.zip llvm-f7617f7f909102080f1a0cee46f8ca75ec8d14ff.tar.gz llvm-f7617f7f909102080f1a0cee46f8ca75ec8d14ff.tar.bz2 |
[clang-format] Recognize TableGen paste operator on separate line (#133722)
Formatting this piece of code made the program crash.
```
class TypedVecListRegOperand<RegisterClass Reg, int lanes, string eltsize>
: RegisterOperand<Reg, "printTypedVectorList<" # lanes # ", '"
# eltsize # "'>">;
```
The line starting with the `#` was treated as a separate preprocessor
directive line. Then the code dereferenced a null pointer when it tried
to continue parsing the first line that did not end in a semicolon.
Now the 2 problems are fixed.
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index b49e80b..60f4f30 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -4842,9 +4842,16 @@ void UnwrappedLineParser::readToken(int LevelDifference) { PreviousWasComment = FormatTok->is(tok::comment); while (!Line->InPPDirective && FormatTok->is(tok::hash) && - (!Style.isVerilog() || - Keywords.isVerilogPPDirective(*Tokens->peekNextToken())) && FirstNonCommentOnLine) { + // In Verilog, the backtick is used for macro invocations. In TableGen, + // the single hash is used for the paste operator. + const auto *Next = Tokens->peekNextToken(); + if ((Style.isVerilog() && !Keywords.isVerilogPPDirective(*Next)) || + (Style.isTableGen() && + !Next->isOneOf(tok::kw_else, tok::pp_define, tok::pp_ifdef, + tok::pp_ifndef, tok::pp_endif))) { + break; + } distributeComments(Comments, FormatTok); Comments.clear(); // If there is an unfinished unwrapped line, we flush the preprocessor |