[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals
Argyrios Kyrtzidis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 19 10:42:25 PST 2023
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
rdar://104386604
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D142143
Files:
clang/lib/Lex/Lexer.cpp
clang/test/ClangScanDeps/depscan-lex-has-include.c
Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===================================================================
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,28 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+
+// CHECK: t.c
+// CHECK: something.h
+
+//--- cdb.json.template
+[
+ {
+ "directory": "DIR",
+ "command": "clang -fsyntax-only DIR/t.c -I DIR",
+ "file": "DIR/t.c"
+ }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include(<something/something.h>)
+#include <something/something.h>
+#endif
+
+//--- something/something.h
Index: clang/lib/Lex/Lexer.cpp
===================================================================
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -4408,6 +4408,22 @@
MIOpt.ReadToken();
}
+ if (ParsingFilename && DDTok.is(tok::less)) {
+ BufferPtr = BufferStart + DDTok.Offset;
+ LexAngledStringLiteral(Result, BufferPtr + 1);
+ if (Result.isNot(tok::header_name))
+ return true;
+ // Advance the index of lexed tokens.
+ while (true) {
+ const dependency_directives_scan::Token &NextTok =
+ DepDirectives.front().Tokens[NextDepDirectiveTokenIndex];
+ if (BufferStart + NextTok.Offset >= BufferPtr)
+ break;
+ ++NextDepDirectiveTokenIndex;
+ }
+ return true;
+ }
+
const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
if (Result.is(tok::hash) && Result.isAtStartOfLine()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142143.490590.patch
Type: text/x-patch
Size: 1683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230119/cb639e20/attachment-0001.bin>
More information about the cfe-commits
mailing list