curdeius created this revision. curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan. Herald added a project: All. curdeius requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
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 ()); } Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D125085 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -15082,6 +15082,9 @@ // 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; Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3434,9 +3434,11 @@ 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.is(tok::identifier) || Left.Tok.getIdentifierInfo() || + Left.isFunctionLikeKeyword() || Left.is(tok::r_paren) || + Left.isSimpleTypeSpecifier())) return spaceRequiredBeforeParens(Right); return false; }
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -15082,6 +15082,9 @@ // 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; Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3434,9 +3434,11 @@ 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.is(tok::identifier) || Left.Tok.getIdentifierInfo() || + Left.isFunctionLikeKeyword() || Left.is(tok::r_paren) || + Left.isSimpleTypeSpecifier())) return spaceRequiredBeforeParens(Right); return false; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits