https://github.com/pjalwadi created https://github.com/llvm/llvm-project/pull/179647
Fixes #179128. This patch fixes a false negative where Clang failed to detect out-of-bounds access when calling a member function on an invalid array index. It adds handling for CXXMemberCallExpr in CheckArrayAccess. >From 88a473609cf91bec52bc4783296fda5762397e23 Mon Sep 17 00:00:00 2001 From: prajwal jalwadi <[email protected]> Date: Wed, 4 Feb 2026 15:27:57 +0530 Subject: [PATCH] [Clang] Fix missing -Warray-bounds warning on member function calls Fixes #179128. This patch fixes a false negative where Clang failed to detect out-of-bounds access when calling a member function on an invalid array index. It adds handling for CXXMemberCallExpr in CheckArrayAccess. Signed-off-by: prajwal jalwadi<[email protected]> --- clang/lib/Sema/SemaChecking.cpp | 4 ++++ clang/test/SemaCXX/constant-expression-cxx2a.cpp | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 3f19b6ad16c13..cec6060cc9dab 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -15449,6 +15449,10 @@ void Sema::CheckArrayAccess(const Expr *expr) { expr = cast<MemberExpr>(expr)->getBase(); break; } + case Stmt::CXXMemberCallExprClass: { + expr = cast<CXXMemberCallExpr>(expr)->getImplicitObjectArgument(); + break; + } case Stmt::ArraySectionExprClass: { const ArraySectionExpr *ASE = cast<ArraySectionExpr>(expr); // FIXME: We should probably be checking all of the elements to the diff --git a/clang/test/SemaCXX/constant-expression-cxx2a.cpp b/clang/test/SemaCXX/constant-expression-cxx2a.cpp index 4fcd243b4442c..75be84557a0ec 100644 --- a/clang/test/SemaCXX/constant-expression-cxx2a.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx2a.cpp @@ -1241,8 +1241,9 @@ namespace dtor_call { } constexpr void destroy_past_end_array() { // expected-error {{never produces a constant expression}} - A a[2]; - a[2].~A(); // expected-note {{destruction of dereferenced one-past-the-end pointer}} + A a[2]; // expected-note {{array 'a' declared here}} + a[2].~A(); // expected-note {{destruction of dereferenced one-past-the-end pointer}} \ + // expected-warning {{array index 2 is past the end of the array}} } union As { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
