[PATCH] D128772: [Lex] Make sure to notify `MultipleIncludeOpt` for "read tokens" during fast dependency directive lexing

Argyrios Kyrtzidis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 29 15:51:06 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc68b8c84eb17: [Lex] Make sure to notify `MultipleIncludeOpt` for "read tokens" during fast… (authored by akyrtzi).

Changed prior to commit:
  https://reviews.llvm.org/D128772?vs=440813&id=441191#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128772

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/ClangScanDeps/more-content-after-headerguard.c


Index: clang/test/ClangScanDeps/more-content-after-headerguard.c
===================================================================
--- /dev/null
+++ clang/test/ClangScanDeps/more-content-after-headerguard.c
@@ -0,0 +1,47 @@
+// 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: top.h
+// CHECK: n1.h
+// CHECK: n2.h
+// CHECK: n3.h
+
+//--- cdb.json.template
+[
+  {
+    "directory": "DIR",
+    "command": "clang -fsyntax-only DIR/t.c",
+    "file": "DIR/t.c"
+  }
+]
+
+//--- t.c
+
+#include "top.h"
+#define INCLUDE_N3
+#include "top.h"
+
+//--- top.h
+#ifndef _TOP_H_
+#define _TOP_H_
+
+#include "n1.h"
+
+#endif
+
+// More stuff after following '#endif', should invalidate the macro guard optimization,
+// and allow `top.h` to get re-included.
+#include "n2.h"
+
+//--- n1.h
+
+//--- n2.h
+#ifdef INCLUDE_N3
+#include "n3.h"
+#endif
+
+//--- n3.h
Index: clang/lib/Lex/Lexer.cpp
===================================================================
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -4248,6 +4248,10 @@
 
   const dependency_directives_scan::Token &DDTok =
       DepDirectives.front().Tokens[NextDepDirectiveTokenIndex++];
+  if (NextDepDirectiveTokenIndex > 1 || DDTok.Kind != tok::hash) {
+    // Read something other than a preprocessor directive hash.
+    MIOpt.ReadToken();
+  }
 
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128772.441191.patch
Type: text/x-patch
Size: 1554 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220629/e4660485/attachment.bin>


More information about the cfe-commits mailing list