Author: mygitljf Date: 2026-06-03T20:51:12Z New Revision: 0a4f19e4769eae755cdad1a4af1d73988762dd2c
URL: https://github.com/llvm/llvm-project/commit/0a4f19e4769eae755cdad1a4af1d73988762dd2c DIFF: https://github.com/llvm/llvm-project/commit/0a4f19e4769eae755cdad1a4af1d73988762dd2c.diff LOG: [clang-format][Objective-C] Fix assertion crash on stray '-'/'+' in @interfa… (#199104) Before calling `parseObjCMethod()`, it now checks whether the next token is a `(` or an identifier; if not, it simply skips ahead, thereby preventing the assertion failure and subsequent crash. Fixes #199075 Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTestObjC.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 39b7f566e2e6b..f73fe0fce4a9e 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -4263,7 +4263,8 @@ void UnwrappedLineParser::parseObjCUntilAtEnd() { addUnwrappedLine(); } else if (FormatTok->isOneOf(tok::minus, tok::plus)) { nextToken(); - parseObjCMethod(); + if (FormatTok->isOneOf(tok::l_paren, tok::identifier)) + parseObjCMethod(); } else { parseStructuralElement(); } diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp index 09a9687d6f87a..a377c065aecc9 100644 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -1803,6 +1803,22 @@ TEST_F(FormatTestObjC, AttributesOnObjCProperty) { "@property(weak) id delegate ATTRIBUTE_MACRO(X) __attribute__((X));"); } +TEST_F(FormatTestObjC, NoCrashOnStrayMethodSign) { + verifyNoCrash("@interface;\n" + "-"); + verifyNoCrash("@interface Foo\n" + "-"); + verifyNoCrash("@interface Foo\n" + "+"); + verifyNoCrash("@implementation Foo\n" + "-"); + verifyNoCrash("@interface Foo\n" + "-\n" + "@end"); + verifyNoCrash("@interface Foo\n" + "- ;"); +} + } // end namespace } // namespace test } // end namespace format _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
