Author: Marek Kurdej Date: 2022-05-09T11:42:41+02:00 New Revision: 85ec8a9ac141a1807d907b7514546f531007d87d
URL: https://github.com/llvm/llvm-project/commit/85ec8a9ac141a1807d907b7514546f531007d87d DIFF: https://github.com/llvm/llvm-project/commit/85ec8a9ac141a1807d907b7514546f531007d87d.diff LOG: [clang-format] Correctly handle SpaceBeforeParens for builtins. That's a partial fix for https://github.com/llvm/llvm-project/issues/55292. Before, known builtins behaved differently from other identifiers: ``` void f () { return F (__builtin_LINE() + __builtin_FOO ()); } ``` After: ``` void f () { return F (__builtin_LINE () + __builtin_FOO ()); } ``` Reviewed By: owenpan Differential Revision: https://reviews.llvm.org/D125085 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8cbe157b1fb21..68f35643bbf2f 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3436,9 +3436,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return (Style.SpaceBeforeParens != FormatStyle::SBPO_Never) || spaceRequiredBeforeParens(Right); } + // Handle builtins like identifiers. if (Line.Type != LT_PreprocessorDirective && - (Left.is(tok::identifier) || Left.isFunctionLikeKeyword() || - Left.is(tok::r_paren) || Left.isSimpleTypeSpecifier())) + (Left.Tok.getIdentifierInfo() || Left.is(tok::r_paren))) return spaceRequiredBeforeParens(Right); return false; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 98da4f773de95..78f7eee809c4d 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -15082,6 +15082,9 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { // verifyFormat("X A::operator++ (T);", Space); verifyFormat("auto lambda = [] () { return 0; };", Space); verifyFormat("int x = int (y);", Space); + verifyFormat("#define F(...) __VA_OPT__ (__VA_ARGS__)", Space); + verifyFormat("__builtin_LINE ()", Space); + verifyFormat("__builtin_UNKNOWN ()", Space); FormatStyle SomeSpace = getLLVMStyle(); SomeSpace.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits