This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG5221875a957d: [clang-format] Fix an invalid code generation in RemoveBracesLLVM (authored by owenpan).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D126438/new/ https://reviews.llvm.org/D126438 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -25385,6 +25385,30 @@ "}", Style); + verifyFormat("if (a)\n" + " if (b)\n" + " c;\n" + " else {\n" + " if (d)\n" + " e;\n" + " }\n" + "else\n" + " f;", + Style); + + verifyFormat("if (a)\n" + " if (b)\n" + " c;\n" + " else {\n" + " if (d)\n" + " e;\n" + " else if (f)\n" + " g;\n" + " }\n" + "else\n" + " h;", + Style); + verifyFormat("if (a)\n" " b;\n" "else if (c)\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2587,10 +2587,13 @@ FormatTok->setFinalizedType(TT_ElseLBrace); ElseLeftBrace = FormatTok; CompoundStatementIndenter Indenter(this, Style, Line->Level); - if (parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u, - /*MunchSemi=*/true, - KeepElseBraces) == IfStmtKind::IfOnly) { - Kind = IfStmtKind::IfElseIf; + const IfStmtKind ElseBlockKind = + parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u, + /*MunchSemi=*/true, KeepElseBraces); + if ((ElseBlockKind == IfStmtKind::IfOnly || + ElseBlockKind == IfStmtKind::IfElseIf) && + FormatTok->is(tok::kw_else)) { + KeepElseBraces = true; } addUnwrappedLine(); } else if (FormatTok->is(tok::kw_if)) {
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -25385,6 +25385,30 @@ "}", Style); + verifyFormat("if (a)\n" + " if (b)\n" + " c;\n" + " else {\n" + " if (d)\n" + " e;\n" + " }\n" + "else\n" + " f;", + Style); + + verifyFormat("if (a)\n" + " if (b)\n" + " c;\n" + " else {\n" + " if (d)\n" + " e;\n" + " else if (f)\n" + " g;\n" + " }\n" + "else\n" + " h;", + Style); + verifyFormat("if (a)\n" " b;\n" "else if (c)\n" Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2587,10 +2587,13 @@ FormatTok->setFinalizedType(TT_ElseLBrace); ElseLeftBrace = FormatTok; CompoundStatementIndenter Indenter(this, Style, Line->Level); - if (parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u, - /*MunchSemi=*/true, - KeepElseBraces) == IfStmtKind::IfOnly) { - Kind = IfStmtKind::IfElseIf; + const IfStmtKind ElseBlockKind = + parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u, + /*MunchSemi=*/true, KeepElseBraces); + if ((ElseBlockKind == IfStmtKind::IfOnly || + ElseBlockKind == IfStmtKind::IfElseIf) && + FormatTok->is(tok::kw_else)) { + KeepElseBraces = true; } addUnwrappedLine(); } else if (FormatTok->is(tok::kw_if)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits