diff options
author | Alexandre Ganea <alexandre.ganea@ubisoft.com> | 2019-08-26 23:28:05 +0000 |
---|---|---|
committer | Alexandre Ganea <alexandre.ganea@ubisoft.com> | 2019-08-26 23:28:05 +0000 |
commit | 6137cecf87cc29e924d0bfb9f8f4bbe98b7c0f2b (patch) | |
tree | 5ff589822bdf3719f1a70ea91c9d6b664d0e6216 | |
parent | ba7e191e434f6a0988e67ff3fa02b7756684c74f (diff) | |
download | bcm5719-llvm-6137cecf87cc29e924d0bfb9f8f4bbe98b7c0f2b.tar.gz bcm5719-llvm-6137cecf87cc29e924d0bfb9f8f4bbe98b7c0f2b.zip |
[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
llvm-svn: 369988
-rw-r--r-- | clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp | 7 | ||||
-rw-r--r-- | clang/test/Lexer/minimize_source_to_dependency_directives_include.c | 8 |
2 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp index 396d49bcdaf..265a6e44e33 100644 --- a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp +++ b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp @@ -186,8 +186,8 @@ static void skipRawString(const char *&First, const char *const End) { } 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 char *&First, const char *const End) { 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 diff --git a/clang/test/Lexer/minimize_source_to_dependency_directives_include.c b/clang/test/Lexer/minimize_source_to_dependency_directives_include.c new file mode 100644 index 00000000000..678753dd455 --- /dev/null +++ b/clang/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>
|