Skip to content

Commit a1ed821

Browse files
committed
[TableGen] Simplify prepSkipToLineEnd for preprocessing
The MemoryBuffer is created using `RequiresNullTerminator`, so we can safely skip the `CurPtr != CurBuf.end()` check. The redundant check causes a cppcheck report. In addition, elsewhere, including `*CurPtr == '#'` below, makes the null terminator assumption as well. Close llvm#81120
1 parent ab4a793 commit a1ed821

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

llvm/lib/TableGen/TGLexer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ bool TGLexer::prepSkipRegion(bool MustNeverBeFalse) {
849849

850850
do {
851851
// Skip all symbols to the line end.
852-
prepSkipToLineEnd();
852+
while (*CurPtr != '\n')
853+
++CurPtr;
853854

854855
// Find the first non-whitespace symbol in the next line(s).
855856
if (!prepSkipLineBegin())
@@ -1032,11 +1033,6 @@ bool TGLexer::prepSkipDirectiveEnd() {
10321033
return true;
10331034
}
10341035

1035-
void TGLexer::prepSkipToLineEnd() {
1036-
while (*CurPtr != '\n' && *CurPtr != '\r' && CurPtr != CurBuf.end())
1037-
++CurPtr;
1038-
}
1039-
10401036
bool TGLexer::prepIsProcessingEnabled() {
10411037
for (const PreprocessorControlDesc &I :
10421038
llvm::reverse(*PrepIncludeStack.back()))

llvm/lib/TableGen/TGLexer.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,6 @@ class TGLexer {
467467
// directive.
468468
bool prepSkipDirectiveEnd();
469469

470-
// Skip all symbols to the end of the line/file.
471-
// The method adjusts CurPtr, so that it points to either new line
472-
// symbol in the current line or the buffer end.
473-
void prepSkipToLineEnd();
474-
475470
// Return true, if the current preprocessor control stack is such that
476471
// we should allow lexer to process the next token, false - otherwise.
477472
//

0 commit comments

Comments
 (0)