summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-03-13 13:32:11 +0000
committerDaniel Jasper <djasper@google.com>2015-03-13 13:32:11 +0000
commit9ecb0e96b8414ef95d747f659a32d85b68998cec (patch)
tree17bfcfc39cbe629a5c87108abc6c02510d09776e
parent60f1db0525003e15485a84fa4cc8ec475df6f403 (diff)
downloadbcm5719-llvm-9ecb0e96b8414ef95d747f659a32d85b68998cec.tar.gz
bcm5719-llvm-9ecb0e96b8414ef95d747f659a32d85b68998cec.zip
clang-format: Don't corrupt macros with open braces.
Formatting: #define A { { #define B } } Before: #define A \ { \ { #define B } \ } After: #define A \ { \ { #define B \ } \ } This fixes llvm.org/PR22884. llvm-svn: 232166
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp13
-rw-r--r--clang/unittests/Format/FormatTest.cpp7
2 files changed, 15 insertions, 5 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 71e8b3fd6b0..6c92d79d139 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -35,10 +35,18 @@ public:
tryFitMultipleLinesInOne(unsigned Indent,
SmallVectorImpl<AnnotatedLine *>::const_iterator I,
SmallVectorImpl<AnnotatedLine *>::const_iterator E) {
+ // Can't join the last line with anything.
+ if (I + 1 == E)
+ return 0;
// We can never merge stuff if there are trailing line comments.
const AnnotatedLine *TheLine = *I;
if (TheLine->Last->is(TT_LineComment))
return 0;
+ if (I[1]->Type == LT_Invalid || I[1]->First->MustBreakBefore)
+ return 0;
+ if (TheLine->InPPDirective &&
+ (!I[1]->InPPDirective || I[1]->First->HasUnescapedNewline))
+ return 0;
if (Style.ColumnLimit > 0 && Indent > Style.ColumnLimit)
return 0;
@@ -51,9 +59,6 @@ public:
? 0
: Limit - TheLine->Last->TotalLength;
- if (I + 1 == E || I[1]->Type == LT_Invalid || I[1]->First->MustBreakBefore)
- return 0;
-
// FIXME: TheLine->Level != 0 might or might not be the right check to do.
// If necessary, change to something smarter.
bool MergeShortFunctions =
@@ -121,8 +126,6 @@ private:
unsigned Limit) {
if (Limit == 0)
return 0;
- if (!I[1]->InPPDirective || I[1]->First->HasUnescapedNewline)
- return 0;
if (I + 2 != E && I[2]->InPPDirective && !I[2]->First->HasUnescapedNewline)
return 0;
if (1 + I[1]->Last->TotalLength > Limit)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d6ca57f3047..c0e847fe67d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2686,6 +2686,13 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
"#define b }\\\n"
" a\n"
"a");
+ verifyFormat("#define A \\\n"
+ " { \\\n"
+ " {\n"
+ "#define B \\\n"
+ " } \\\n"
+ " }",
+ getLLVMStyleWithColumns(15));
verifyNoCrash("#if a\na(\n#else\n#endif\n{a");
verifyNoCrash("a={0,1\n#if a\n#else\n;\n#endif\n}");
OpenPOWER on IntegriCloud