This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
akyrtzi marked an inline comment as done.
Closed by commit rGed6d09dd4ead: [Lex] For dependency directive lexing, angled 
includes in `__has_include`… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142143/new/

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,46 @@
+// 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
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | 
FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+    "directory": "DIR",
+    "command": "clang -fsyntax-only DIR/t.c -I DIR",
+    "file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+    "directory": "DIR",
+    "command": "clang -fsyntax-only DIR/error.c",
+    "file": "DIR/error.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
+
+//--- error.c
+#if __has_include(<something/something.h)
+#define MAC
+#endif
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()) {


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===================================================================
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// 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
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+    "directory": "DIR",
+    "command": "clang -fsyntax-only DIR/t.c -I DIR",
+    "file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+    "directory": "DIR",
+    "command": "clang -fsyntax-only DIR/error.c",
+    "file": "DIR/error.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
+
+//--- error.c
+#if __has_include(<something/something.h)
+#define MAC
+#endif
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()) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to