This is an archive of the discontinued LLVM Phabricator instance.

[clang-scan-deps] Improve string/character literal skipping
ClosedPublic

Authored by arphaman on Oct 3 2019, 5:42 PM.

Details

Summary

The existing string/character literal skipping code in the dependency directives source minimizer has two issues:

  • It doesn't stop the scanning when a newline is reached before the terminating character, unlike the lexer which considers the token to be done (even if it's invalid) at the end of the line.
  • It doesn't support whitespace between '\' and the newline when looking if the '\' is used as a line continuation character.

Diff Detail

Event Timeline

arphaman created this revision.Oct 3 2019, 5:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2019, 5:42 PM
kousikk added inline comments.Oct 3 2019, 7:39 PM
clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
205

Should you also check if the character right after a backslash is equal to Terminator and if it is, continue on without terminating? The case I'm thinking of is:

#define FOO "FOO \"doublequote\""

The testcase would be something like:

StringRef Source = "#define FOO \"FOO \\\"doublequote\\\"\"
... do rest
dexonsmith accepted this revision.Oct 3 2019, 11:55 PM

LGTM, with a few nitpicks about unnecessary nesting.

clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
205

Invert condition with early continue?

206

Should you also check if the character right after a backslash is equal to Terminator and if it is, continue on without terminating?

@kousikk, that was handled before this patch. This ++First combined with the one in the loop increment handles skipping over an escaped terminator.

208

Invert condition with early continue?

215

Is this continue needed?

This revision is now accepted and ready to land.Oct 3 2019, 11:55 PM
kousikk accepted this revision.Oct 4 2019, 6:01 AM
kousikk marked an inline comment as done.
kousikk added inline comments.
clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
206

Ah makes sense, thanks.

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