https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/97220
This patch adds a null check for the current method declaration before attempting to determine if it is a designated initializer. This prevents a potential null pointer dereference when `getCurMethodDecl()` returns nullptr, reported by static analyzer tool in clang::SemaObjC::BuildInstanceMessage(). >From 63f45c952ff8ab7df261a150355a34267e4a645c Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" <soumi.ma...@intel.com> Date: Sun, 30 Jun 2024 08:40:27 -0700 Subject: [PATCH] [Clang] Prevent null pointer dereference in designated initializer check This patch adds a null check for the current method declaration before attempting to determine if it is a designated initializer. This prevents a potential null pointer dereference when `getCurMethodDecl()` returns nullptr, reported by static analyzer tool in clang::SemaObjC::BuildInstanceMessage(). --- clang/lib/Sema/SemaExprObjC.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 7ccecf055feed..05aa30e16ed8e 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -3206,9 +3206,11 @@ ExprResult SemaObjC::BuildInstanceMessage( } if (!isDesignatedInitChain) { const ObjCMethodDecl *InitMethod = nullptr; + auto *CurMD = SemaRef.getCurMethodDecl(); + if (!CurMD) + return nullptr; bool isDesignated = - SemaRef.getCurMethodDecl()->isDesignatedInitializerForTheInterface( - &InitMethod); + CurMD->isDesignatedInitializerForTheInterface(&InitMethod); assert(isDesignated && InitMethod); (void)isDesignated; Diag(SelLoc, SuperLoc.isValid() ? _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits