From 98eb348eb38aaba63aa149000c97d27a7e5190c3 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Fri, 13 Aug 2021 16:25:32 +0100 Subject: [PATCH] Revert "[clang-format] Distinguish K&R C function definition and attribute" This reverts commit de763c4037157e60551ba227ccd0ed02e109c317. Causing test failures on the Arm/AArch64 quick bots: https://lab.llvm.org/buildbot/#/builders/188/builds/2202 --- clang/lib/Format/UnwrappedLineParser.cpp | 25 ++++++++----------------- clang/unittests/Format/FormatTest.cpp | 10 ---------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e234c74..0c4caca 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -14,6 +14,7 @@ #include "UnwrappedLineParser.h" #include "FormatToken.h" +#include "clang/Basic/TokenKinds.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -994,13 +995,6 @@ static bool isJSDeclOrStmt(const AdditionalKeywords &Keywords, Keywords.kw_import, tok::kw_export); } -// Checks whether a token is a type in K&R C (aka C78). -static bool isC78Type(const FormatToken &Tok) { - return Tok.isOneOf(tok::kw_char, tok::kw_short, tok::kw_int, tok::kw_long, - tok::kw_unsigned, tok::kw_float, tok::kw_double, - tok::identifier); -} - // This function checks whether a token starts the first parameter declaration // in a K&R C (aka C78) function definition, e.g.: // int f(a, b) @@ -1012,8 +1006,9 @@ static bool isC78ParameterDecl(const FormatToken *Tok) { if (!Tok) return false; - if (!isC78Type(*Tok) && - !Tok->isOneOf(tok::kw_register, tok::kw_struct, tok::kw_union)) + if (!Tok->isOneOf(tok::kw_int, tok::kw_char, tok::kw_float, tok::kw_double, + tok::kw_struct, tok::kw_union, tok::kw_long, tok::kw_short, + tok::kw_unsigned, tok::kw_register)) return false; Tok = Tok->Previous; @@ -1374,7 +1369,7 @@ void UnwrappedLineParser::parseStructuralElement(bool IsTopLevel) { case tok::r_brace: addUnwrappedLine(); return; - case tok::l_paren: { + case tok::l_paren: parseParens(); // Break the unwrapped line if a K&R C function definition has a parameter // declaration. @@ -1382,18 +1377,14 @@ void UnwrappedLineParser::parseStructuralElement(bool IsTopLevel) { break; if (!Previous || Previous->isNot(tok::identifier)) break; - const FormatToken *PrevPrev = Previous->Previous; - if (!PrevPrev || (!isC78Type(*PrevPrev) && PrevPrev->isNot(tok::star))) + if (Previous->Previous && Previous->Previous->is(tok::at)) break; - const FormatToken *Next = AllTokens[Tokens->getPosition() + 1]; - if (Next && Next->isOneOf(tok::l_paren, tok::semi)) - break; - if (isC78ParameterDecl(FormatTok)) { + if (!Line->Tokens.begin()->Tok->is(tok::kw_typedef) && + isC78ParameterDecl(FormatTok)) { addUnwrappedLine(); return; } break; - } case tok::kw_operator: nextToken(); if (FormatTok->isBinaryOperator()) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 63e93b7..1283aa6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8247,16 +8247,6 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { " return a + b < c;\n" "};", Style); - verifyFormat("byte *\n" // Break here. - "f(a)\n" // Break here. - "byte a[];\n" - "{\n" - " return a;\n" - "}", - Style); - verifyFormat("bool f(int a, int) override;\n" - "Bar g(int a, Bar) final; // comment", - Style); // The return breaking style doesn't affect: // * function and object definitions with attribute-like macros -- 2.7.4