aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/PrintPreprocessedOutput.cpp
diff options
context:
space:
mode:
authorMichael Kruse <llvm-project@meinersbur.de>2021-11-05 00:03:26 -0500
committerMichael Kruse <llvm-project@meinersbur.de>2021-11-05 00:43:40 -0500
commit1606022fab2d90ed8ee6d15800ec1c2c293db20e (patch)
tree2a14e5c7176d5cb570d597efa9218e4b24c6e6cb /clang/lib/Frontend/PrintPreprocessedOutput.cpp
parent8f099d17a1bee857ada3c5af032cfcb559252024 (diff)
downloadllvm-1606022fab2d90ed8ee6d15800ec1c2c293db20e.zip
llvm-1606022fab2d90ed8ee6d15800ec1c2c293db20e.tar.gz
llvm-1606022fab2d90ed8ee6d15800ec1c2c293db20e.tar.bz2
[Preprocessor] Fix newline before/after _Pragma.
The PragmaAssumeNonNullHandler (and maybe others) passes an invalid SourceLocation to its callback, hence PrintPreprocessedOutput does not know how many lines to insert between the previous token and the pragma and does nothing. With this patch we instead assume that the unknown token is on the same line as the previous such that we can call the procedure that also emits semantically significant whitespace. Fixes bug reported here: https://reviews.llvm.org/D104601#3105044
Diffstat (limited to 'clang/lib/Frontend/PrintPreprocessedOutput.cpp')
-rw-r--r--clang/lib/Frontend/PrintPreprocessedOutput.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index fadf0c0..45df86e 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -188,19 +188,17 @@ public:
/// @return Whether column adjustments are necessary.
bool MoveToLine(const Token &Tok, bool RequireStartOfLine) {
PresumedLoc PLoc = SM.getPresumedLoc(Tok.getLocation());
- if (PLoc.isInvalid())
- return false;
+ unsigned TargetLine = PLoc.isValid() ? PLoc.getLine() : CurLine;
bool IsFirstInFile = Tok.isAtStartOfLine() && PLoc.getLine() == 1;
- return MoveToLine(PLoc.getLine(), RequireStartOfLine) || IsFirstInFile;
+ return MoveToLine(TargetLine, RequireStartOfLine) || IsFirstInFile;
}
/// Move to the line of the provided source location. Returns true if a new
/// line was inserted.
bool MoveToLine(SourceLocation Loc, bool RequireStartOfLine) {
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
- if (PLoc.isInvalid())
- return false;
- return MoveToLine(PLoc.getLine(), RequireStartOfLine);
+ unsigned TargetLine = PLoc.isValid() ? PLoc.getLine() : CurLine;
+ return MoveToLine(TargetLine, RequireStartOfLine);
}
bool MoveToLine(unsigned LineNo, bool RequireStartOfLine);