summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-01-23 19:37:25 +0000
committerDaniel Jasper <djasper@google.com>2015-01-23 19:37:25 +0000
commitd1c13736e0132718b550824ffb05764679d17eb4 (patch)
tree551e6767970f5e23e475acff8dfc22359cadd08a /clang/lib/Format
parent9a36b3e147a0fb0ed087841459730e420a1c30e8 (diff)
downloadbcm5719-llvm-d1c13736e0132718b550824ffb05764679d17eb4.tar.gz
bcm5719-llvm-d1c13736e0132718b550824ffb05764679d17eb4.zip
clang-format: Fix another crasher caused by incomplete macro code.
We did't properly mark all of an AnnotatedLine's children as finalized and thus would reformat the same tokens in different branches of #if/#else sequences leading to invalid replacements. llvm-svn: 226930
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index ca66e735164..6c4aadc0f1c 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -309,6 +309,15 @@ private:
ContinuationIndenter *Indenter;
};
+
+static void markFinalized(FormatToken *Tok) {
+ for (; Tok; Tok = Tok->Next) {
+ Tok->Finalized = true;
+ for (AnnotatedLine *Child : Tok->Children)
+ markFinalized(Child->First);
+ }
+}
+
} // namespace
unsigned
@@ -442,11 +451,8 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines,
}
}
}
- if (!DryRun) {
- for (FormatToken *Tok = TheLine.First; Tok; Tok = Tok->Next) {
- Tok->Finalized = true;
- }
- }
+ if (!DryRun)
+ markFinalized(TheLine.First);
PreviousLine = *I;
}
PenaltyCache[CacheKey] = Penalty;
OpenPOWER on IntegriCloud