/// @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);
--- /dev/null
+// RUN: %clang_cc1 -E -o - %s | FileCheck %s
+// RUN: %clang_cc1 -E -P -o - %s | FileCheck %s
+// RUN: %clang_cc1 -E -fminimize-whitespace -o - %s | FileCheck %s
+// RUN: %clang_cc1 -E -fminimize-whitespace -P -o - %s | FileCheck %s
+
+// The PragmaAssumeNonNullHandler (and maybe others) passes an invalid
+// SourceLocation when inside a _Pragma. Ensure we still emit semantic
+// newlines.
+// See report at https://reviews.llvm.org/D104601#3105044
+
+_Pragma("clang assume_nonnull begin") test _Pragma("clang assume_nonnull end")
+
+// CHECK: {{^}}#pragma clang assume_nonnull begin{{$}}
+// CHECK: test
+// CHECK: {{^}}#pragma clang assume_nonnull end{{$}}