https://github.com/dmaclach updated https://github.com/llvm/llvm-project/pull/216125
>From f1f108131eb094a95baa42893797e11b94da4277 Mon Sep 17 00:00:00 2001 From: Dave MacLachlan <[email protected]> Date: Thu, 13 Aug 2026 10:38:55 -0700 Subject: [PATCH 1/2] [clang] Fix RecursiveASTVisitor to traverse the exception parameter in ObjCAtCatchStmt. Ensures that the catch parameter declaration (the exception variable) in an Objective-C @catch block is visited during AST traversal. Previously, this declaration was skipped. A unit test has been added to verify the fix. --- clang/include/clang/AST/RecursiveASTVisitor.h | 6 +++++- .../Tooling/RecursiveASTVisitorTestDeclVisitor.cpp | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 617990b82edca..12204dcfb5938 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2575,6 +2575,11 @@ DEF_TRAVERSE_STMT(CXXCatchStmt, { // children() iterates over the handler block. }) +DEF_TRAVERSE_STMT(ObjCAtCatchStmt, { + TRY_TO(TraverseDecl(S->getCatchParamDecl())); + // children() iterates over the handler block. +}) + DEF_TRAVERSE_STMT(DeclStmt, { for (auto *I : S->decls()) { TRY_TO(TraverseDecl(I)); @@ -2604,7 +2609,6 @@ DEF_TRAVERSE_STMT(IndirectGotoStmt, {}) DEF_TRAVERSE_STMT(LabelStmt, {}) DEF_TRAVERSE_STMT(AttributedStmt, {}) DEF_TRAVERSE_STMT(NullStmt, {}) -DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {}) DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {}) DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {}) DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {}) diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTestDeclVisitor.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTestDeclVisitor.cpp index eed016e9ee7c2..2af0ecb40b225 100644 --- a/clang/unittests/Tooling/RecursiveASTVisitorTestDeclVisitor.cpp +++ b/clang/unittests/Tooling/RecursiveASTVisitorTestDeclVisitor.cpp @@ -134,4 +134,13 @@ TEST(RecursiveASTVisitor, NoRecursionInSelfFriend) { "vector_iterator<int> it_int;\n")); } +TEST(RecursiveASTVisitor, VisitsObjCAtCatchStmtExceptionVariable) { + VarDeclVisitor Visitor; + Visitor.ExpectMatch("e", 2, 28); + EXPECT_TRUE(Visitor.runOver( + "@interface NSException; @end\n" + "void f() { @try {} @catch (NSException *e) {} }", + VarDeclVisitor::Lang_OBJC)); +} + } // end anonymous namespace >From a554739f5e4ea5ff450b7955105bba09c15917a0 Mon Sep 17 00:00:00 2001 From: Dave MacLachlan <[email protected]> Date: Thu, 13 Aug 2026 10:47:30 -0700 Subject: [PATCH 2/2] Fixed up formatting. --- .../Tooling/RecursiveASTVisitorTestDeclVisitor.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTestDeclVisitor.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTestDeclVisitor.cpp index 2af0ecb40b225..fe842431d89bc 100644 --- a/clang/unittests/Tooling/RecursiveASTVisitorTestDeclVisitor.cpp +++ b/clang/unittests/Tooling/RecursiveASTVisitorTestDeclVisitor.cpp @@ -137,10 +137,9 @@ TEST(RecursiveASTVisitor, NoRecursionInSelfFriend) { TEST(RecursiveASTVisitor, VisitsObjCAtCatchStmtExceptionVariable) { VarDeclVisitor Visitor; Visitor.ExpectMatch("e", 2, 28); - EXPECT_TRUE(Visitor.runOver( - "@interface NSException; @end\n" - "void f() { @try {} @catch (NSException *e) {} }", - VarDeclVisitor::Lang_OBJC)); + EXPECT_TRUE(Visitor.runOver("@interface NSException; @end\n" + "void f() { @try {} @catch (NSException *e) {} }", + VarDeclVisitor::Lang_OBJC)); } } // end anonymous namespace _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
