This is an archive of the discontinued LLVM Phabricator instance.

[clang-scan-deps] Allow continuation line backslashes followed by whitespace in the dependency source minimizer
ClosedPublic

Authored by arphaman on Sep 25 2019, 2:34 PM.

Details

Summary

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.

Diff Detail

Event Timeline

arphaman created this revision.Sep 25 2019, 2:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 25 2019, 2:34 PM
dexonsmith accepted this revision.Sep 25 2019, 3:12 PM

The code looks correct. I have some nitpicks about how the functions are named, but you don't need to go with my suggestions specifically.

clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
247–248

I don't love this name change, since the idea of the function is to take a "first, last" half-open range and reverse "last" back to exclude the spaces. "UntilFirstSpace" suggests that it would stop early and make the half-open range include a space.

Of course it's all a bit weird because it's not returning a range, just the end of it. So the intent of both of these functions is to trim the trailing whitespace, it's just this one points at the beginning of the whitespace to serve as the end of the range, and the other one points at the last thing before the trailing whitespace. Perhaps we can be more explicit about what precisely is being returned, instead of describing intent.

What about findFirstTrailingSpace?

258–264

What about findLastNonSpace?

This revision is now accepted and ready to land.Sep 25 2019, 3:12 PM
dexonsmith added inline comments.Sep 25 2019, 3:17 PM
clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
247–248

You might also reimplement this in terms of the other for clarity:

static const char *findFirstTrailingSpace(const char *First,
                                          const char *Last) {
  const char *LastNonSpace = findLastNonSpace(First, Last);
  if (Last == LastNonSpace)
    return Last;
  assert(isHorizontalWhitespace(LastNonSpace[1]));
  return LastNonSpace + 1;
}

... unless you think that will hurt performance.

This revision was automatically updated to reflect the committed changes.
arphaman marked 3 inline comments as done.