Currently, the -E output from clang does not produce the correct indentation on
the first line. This is because MoveToLine returns false, and when this
happens, the regular process for producing initial indentation is skipped. This
patch makes sure this does not happen on the first line -- it is not clear to
me whether there are other circumstances where the current logic could be
problematic.
It looks like calling SourceManager::getPresumedLoc is a relatively expensive
operation, so however this is fixed, I assume that we want to minimize calls to
that function.
Please review.
Thanks again,
Hal
--
Hal Finkel
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp
index 02da71b..4b5dab9 100644
--- a/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -139,10 +139,13 @@ public:
diag::Mapping Map, StringRef Str);
bool HandleFirstTokOnLine(Token &Tok);
- bool MoveToLine(SourceLocation Loc) {
+ bool MoveToLine(SourceLocation Loc, bool *FirstLine = 0) {
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
- if (PLoc.isInvalid())
+ if (PLoc.isInvalid()) {
+ if (FirstLine) *FirstLine = false;
return false;
+ }
+ if (FirstLine) *FirstLine = PLoc.getLine() == 1;
return MoveToLine(PLoc.getLine());
}
bool MoveToLine(unsigned LineNo);
@@ -433,8 +436,11 @@ PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
bool PrintPPOutputPPCallbacks::HandleFirstTokOnLine(Token &Tok) {
// Figure out what line we went to and insert the appropriate number of
// newline characters.
- if (!MoveToLine(Tok.getLocation()))
- return false;
+ bool FirstLine;
+ if (!MoveToLine(Tok.getLocation(), &FirstLine)) {
+ if (!FirstLine)
+ return false;
+ }
// Print out space characters so that the first token on a line is
// indented for easy reading.
diff --git a/test/Preprocessor/first-line-indent.c b/test/Preprocessor/first-line-indent.c
index 8038b9d..2b2a30e 100644
--- a/test/Preprocessor/first-line-indent.c
+++ b/test/Preprocessor/first-line-indent.c
@@ -2,6 +2,6 @@
// RUN: %clang_cc1 -E %s | FileCheck -strict-whitespace %s
bar
-// CHECK: [ ]{7}foo
-// CHECK: [ ]{7}bar
+// CHECK: {{ }}foo
+// CHECK: {{ }}bar
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits