r369988 - [clang-scan-deps] Minimizer: Correctly skip over double slashes in angle bracket #include
Alexandre Ganea via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 26 16:28:05 PDT 2019
Author: aganea
Date: Mon Aug 26 16:28:05 2019
New Revision: 369988
URL: http://llvm.org/viewvc/llvm-project?rev=369988&view=rev
Log:
[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>
Differential Revision: https://reviews.llvm.org/D66550
Added:
cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_include.c
Modified:
cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
Modified: cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp?rev=369988&r1=369987&r2=369988&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp (original)
+++ cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp Mon Aug 26 16:28:05 2019
@@ -186,8 +186,8 @@ static void skipRawString(const char *&F
}
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)
@@ -363,7 +363,8 @@ void Minimizer::printToNewline(const cha
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
Added: cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_include.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_include.c?rev=369988&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_include.c (added)
+++ cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_include.c Mon Aug 26 16:28:05 2019
@@ -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>
More information about the cfe-commits
mailing list