mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-03 19:32:35 +00:00
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
This commit is contained in:
parent
9a36b3e147
commit
d1c13736e0
@ -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;
|
||||
|
@ -2614,6 +2614,7 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
|
||||
verifyNoCrash("#if a\na(\n#else\n#endif\n{a");
|
||||
verifyNoCrash("a={0,1\n#if a\n#else\n;\n#endif\n}");
|
||||
verifyNoCrash("#if a\na(\n#else\n#endif\n) a {a,b,c,d,f,g};");
|
||||
verifyNoCrash("#ifdef A\n a(\n #else\n #endif\n) = []() { \n)}");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {
|
||||
|
Loading…
Reference in New Issue
Block a user