Skip to content

Commit dcb9078

Browse files
authored
[clang][index] Skip over #include UNDEF_IDENT in single-file-parse mode (#135218)
In the 'single-file-parse' mode, seeing `#include UNDEFINED_IDENTIFIER` should not be treated as an error. The identifier might be defined in a header that we decided to skip, resulting in a nonsensical diagnostic from the user point of view.
1 parent 72436b3 commit dcb9078

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clang/lib/Lex/PPDirectives.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,15 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
20732073
return;
20742074

20752075
if (FilenameTok.isNot(tok::header_name)) {
2076+
if (FilenameTok.is(tok::identifier) && PPOpts.SingleFileParseMode) {
2077+
// If we saw #include IDENTIFIER and lexing didn't turn in into a header
2078+
// name, it was undefined. In 'single-file-parse' mode, just skip the
2079+
// directive without emitting diagnostics - the identifier might be
2080+
// normally defined in previously-skipped include directive.
2081+
DiscardUntilEndOfDirective();
2082+
return;
2083+
}
2084+
20762085
Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
20772086
if (FilenameTok.isNot(tok::eod))
20782087
DiscardUntilEndOfDirective();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: split-file %s %t
2+
// RUN: c-index-test -single-file-parse %t/tu.c 2>&1 | FileCheck --allow-empty %t/tu.c
3+
4+
//--- header1.h
5+
#define HEADER2_H "header2.h"
6+
//--- header2.h
7+
//--- tu.c
8+
#include "header1.h"
9+
// CHECK-NOT: tu.c:[[@LINE+1]]:10: error: expected "FILENAME" or <FILENAME>
10+
#include HEADER2_H

0 commit comments

Comments
 (0)