summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2019-09-26 19:28:51 +0000
committerAlex Lorenz <arphaman@gmail.com>2019-09-26 19:28:51 +0000
commit15d5f5dd350e9ba811171968e647a80f84776888 (patch)
tree25d38b5546e2a988932f2a356fbcb0c32b3dbddc /clang/lib
parentf1a5a93157b4658c7961b57960e407001dae6965 (diff)
downloadbcm5719-llvm-15d5f5dd350e9ba811171968e647a80f84776888.tar.gz
bcm5719-llvm-15d5f5dd350e9ba811171968e647a80f84776888.zip
[clang-scan-deps] Allow continuation line backslashes followed by whitespace
in the dependency source minimizer Clang allows continuations that have whitespace between the backslash and the newline. This patch ensures that the dependency source minimizer can handle the whitespace between the backslash and the newline when looking for a line continuation. Differential Revision: https://reviews.llvm.org/D68052 llvm-svn: 373007
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
index 2a3c88251bc..2ffbcfb7e67 100644
--- a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -244,14 +244,20 @@ static void skipToNewlineRaw(const char *&First, const char *const End) {
}
}
-static const char *reverseOverSpaces(const char *First, const char *Last) {
+static const char *findLastNonSpace(const char *First, const char *Last) {
assert(First <= Last);
- const char *PrevLast = Last;
- while (First != Last && isHorizontalWhitespace(Last[-1])) {
- PrevLast = Last;
+ while (First != Last && isHorizontalWhitespace(Last[-1]))
--Last;
- }
- return PrevLast;
+ return Last;
+}
+
+static const char *findFirstTrailingSpace(const char *First,
+ const char *Last) {
+ const char *LastNonSpace = findLastNonSpace(First, Last);
+ if (Last == LastNonSpace)
+ return Last;
+ assert(isHorizontalWhitespace(LastNonSpace[0]));
+ return LastNonSpace + 1;
}
static void skipLineComment(const char *&First, const char *const End) {
@@ -385,7 +391,7 @@ void Minimizer::printToNewline(const char *&First, const char *const End) {
}
// Deal with "//..." and "/*...*/".
- append(First, reverseOverSpaces(First, Last));
+ append(First, findFirstTrailingSpace(First, Last));
First = Last;
if (Last[1] == '/') {
@@ -400,15 +406,20 @@ void Minimizer::printToNewline(const char *&First, const char *const End) {
} while (Last != End && !isVerticalWhitespace(*Last));
// Print out the string.
- if (Last == End || Last == First || Last[-1] != '\\') {
- append(First, reverseOverSpaces(First, Last));
+ const char *LastBeforeTrailingSpace = findLastNonSpace(First, Last);
+ if (Last == End || LastBeforeTrailingSpace == First ||
+ LastBeforeTrailingSpace[-1] != '\\') {
+ append(First, LastBeforeTrailingSpace);
First = Last;
skipNewline(First, End);
return;
}
- // Print up to the backslash, backing up over spaces.
- append(First, reverseOverSpaces(First, Last - 1));
+ // Print up to the backslash, backing up over spaces. Preserve at least one
+ // space, as the space matters when tokens are separated by a line
+ // continuation.
+ append(First, findFirstTrailingSpace(
+ First, LastBeforeTrailingSpace - 1));
First = Last;
skipNewline(First, End);
OpenPOWER on IntegriCloud