[clang] [clang][dep-scan] Resolve lexer crash from a permutation of invalid tokens (PR #142452)
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 5 14:32:18 PDT 2025
================
@@ -503,6 +503,10 @@ bool Scanner::lexModuleDirectiveBody(DirectiveKind Kind, const char *&First,
diag::err_dep_source_scanner_missing_semi_after_at_import);
if (Tok.is(tok::semi))
break;
+ if (Tok.is(tok::hash) || Tok.is(tok::at))
+ return reportError(
----------------
akyrtzi wrote:
I think this should work fine for the test case:
```
@@ -496,7 +496,12 @@ bool Scanner::lexModuleDirectiveBody(DirectiveKind Kind, const char *&First,
const char *const End) {
const char *DirectiveLoc = Input.data() + CurDirToks.front().Offset;
for (;;) {
+ const char *PriorFirst = First;
const dependency_directives_scan::Token &Tok = lexToken(First, End);
+ if (Tok.is(tok::hash) && Tok.Flags & clang::Token::StartOfLine) {
+ First = PriorFirst;
+ return false;
+ }
if (Tok.is(tok::eof))
return reportError(
DirectiveLoc,
```
https://github.com/llvm/llvm-project/pull/142452
More information about the cfe-commits
mailing list