Author: Prajwal P J Date: 2026-02-09T12:59:38+01:00 New Revision: fed9abcb4796507622bdd9e2e36bc80260a5197b
URL: https://github.com/llvm/llvm-project/commit/fed9abcb4796507622bdd9e2e36bc80260a5197b DIFF: https://github.com/llvm/llvm-project/commit/fed9abcb4796507622bdd9e2e36bc80260a5197b.diff LOG: [Clang] Fix missing -Warray-bounds warning on member function calls. (#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. Signed-off-by: prajwal jalwadi<[email protected]> Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaChecking.cpp clang/test/SemaCXX/constant-expression-cxx2a.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 0dbea8efc2642..a1bb1bd2467b7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -223,6 +223,10 @@ Improvements to Clang's diagnostics - Improved ``-Wassign-enum`` performance by caching enum enumerator values. (#GH176454) +- Fixed a false negative in ``-Warray-bounds`` where the warning was suppressed + when accessing a member function on a past-the-end array element. + (#GH179128) + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index d1c46a875208a..dd00f883ff9f6 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -15452,6 +15452,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..fb60b5300c362 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
