[llvm] a1ed821 - [TableGen] Simplify prepSkipToLineEnd for preprocessing
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 8 10:56:05 PST 2024
Author: Fangrui Song
Date: 2024-02-08T10:56:00-08:00
New Revision: a1ed821b49d9a189c3a0a11228c0de517020feca
URL: https://github.com/llvm/llvm-project/commit/a1ed821b49d9a189c3a0a11228c0de517020feca
DIFF: https://github.com/llvm/llvm-project/commit/a1ed821b49d9a189c3a0a11228c0de517020feca.diff
LOG: [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 #81120
Added:
Modified:
llvm/lib/TableGen/TGLexer.cpp
llvm/lib/TableGen/TGLexer.h
Removed:
################################################################################
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index 545643234f699..99d866a23a68b 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -849,7 +849,8 @@ bool TGLexer::prepSkipRegion(bool MustNeverBeFalse) {
do {
// Skip all symbols to the line end.
- prepSkipToLineEnd();
+ while (*CurPtr != '\n')
+ ++CurPtr;
// Find the first non-whitespace symbol in the next line(s).
if (!prepSkipLineBegin())
@@ -1032,11 +1033,6 @@ bool TGLexer::prepSkipDirectiveEnd() {
return true;
}
-void TGLexer::prepSkipToLineEnd() {
- while (*CurPtr != '\n' && *CurPtr != '\r' && CurPtr != CurBuf.end())
- ++CurPtr;
-}
-
bool TGLexer::prepIsProcessingEnabled() {
for (const PreprocessorControlDesc &I :
llvm::reverse(*PrepIncludeStack.back()))
diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h
index 25dcd9fbadef7..9adc03ccc72b8 100644
--- a/llvm/lib/TableGen/TGLexer.h
+++ b/llvm/lib/TableGen/TGLexer.h
@@ -467,11 +467,6 @@ class TGLexer {
// directive.
bool prepSkipDirectiveEnd();
- // Skip all symbols to the end of the line/file.
- // The method adjusts CurPtr, so that it points to either new line
- // symbol in the current line or the buffer end.
- void prepSkipToLineEnd();
-
// Return true, if the current preprocessor control stack is such that
// we should allow lexer to process the next token, false - otherwise.
//
More information about the llvm-commits
mailing list