llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Prajwal P J (pjalwadi) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/179647.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaChecking.cpp (+4) - (modified) clang/test/SemaCXX/constant-expression-cxx2a.cpp (+3-2) ``````````diff 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 { `````````` </details> https://github.com/llvm/llvm-project/pull/179647 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
