[PATCH] D66550: [clang-scan-deps] Minimizer: Correctly skip over double slashes in angle bracket #include

Alexandre Ganea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 21 13:28:30 PDT 2019


aganea created this revision.
aganea added reviewers: arphaman, dexonsmith, Bigcheese.
aganea added a project: clang.
Herald added a subscriber: tschuett.
aganea retitled this revision from "[clang-scan-deps] Correctly skip over double slashes in angle bracket #include" to "[clang-scan-deps] Minimizer: Correctly skip over double slashes in angle bracket #include".

Previously, double slashes (//) occurring in angle brackets `#include` were incorrectly interpreted as comments. eg. `#include <dir//file.h>`


Repository:
  rC Clang

https://reviews.llvm.org/D66550

Files:
  lib/Lex/DependencyDirectivesSourceMinimizer.cpp
  test/Lexer/minimize_source_to_dependency_directives_include.c


Index: test/Lexer/minimize_source_to_dependency_directives_include.c
===================================================================
--- test/Lexer/minimize_source_to_dependency_directives_include.c
+++ test/Lexer/minimize_source_to_dependency_directives_include.c
@@ -0,0 +1,8 @@
+// Test double slashes in #include directive along with angle brackets. Previously, this was interpreted as comments.
+// RUN: %clang_cc1 -DTEST -print-dependency-directives-minimized-source %s 2>&1 | FileCheck %s
+
+#include "a//b.h"
+#include <a//b.h>
+
+// CHECK: #include "a//b.h"
+// CHECK: #include <a//b.h>
Index: lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===================================================================
--- lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -186,8 +186,8 @@
 }
 
 static void skipString(const char *&First, const char *const End) {
-  assert(*First == '\'' || *First == '"');
-  const char Terminator = *First;
+  assert(*First == '\'' || *First == '"' || *First == '<');
+  const char Terminator = *First == '<' ? '>' : *First;
   for (++First; First != End && *First != Terminator; ++First)
     if (*First == '\\')
       if (++First == End)
@@ -344,7 +344,8 @@
     const char *Last = First;
     do {
       // Iterate over strings correctly to avoid comments and newlines.
-      if (*Last == '"' || *Last == '\'') {
+      if (*Last == '"' || *Last == '\'' ||
+          (*Last == '<' && top() == pp_include)) {
         if (LLVM_UNLIKELY(isRawStringLiteral(First, Last)))
           skipRawString(Last, End);
         else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66550.216461.patch
Type: text/x-patch
Size: 1628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190821/1c6e231d/attachment.bin>


More information about the cfe-commits mailing list