Previously, if a header file and a source file used different end of line (EOL) forms, preprocessed output generated with the -frewrite-includes option would, in some cases, generate line control directives with the wrong line number due to an error in how source file lines were counted.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/Frontend/Rewrite/InclusionRewriter.cpp | ||
---|---|---|
292–303 | The issue here was that, when the last line of TextToWrite was not empty and did not end with LocalEOL, Line would be incremented at line 298 despite no EOL sequence being written at either line 300 or line 303. The rewrite avoids use of StringRef::split() so as to avoid the ambiguity created when Rest ends with LocalEOL (Rest ends up empty regardless). I think this simplifies the code by removing the need for differentiated handling of EnsureNewLine in each of the branches of the if statement. |
Thanks Tom
I think this looks reasonable but given the subtlety a comment in the code may be useful
+ a release note to indicate the fixed issue
Addressed Corentin's review feedback. Thank you, Corentin! I'm going to remember to update the release notes doc all on my own one of these days, I'm sure of it! :)
The issue here was that, when the last line of TextToWrite was not empty and did not end with LocalEOL, Line would be incremented at line 298 despite no EOL sequence being written at either line 300 or line 303.
The rewrite avoids use of StringRef::split() so as to avoid the ambiguity created when Rest ends with LocalEOL (Rest ends up empty regardless). I think this simplifies the code by removing the need for differentiated handling of EnsureNewLine in each of the branches of the if statement.