Author: danielmarjamaki Date: Tue Feb 28 08:53:50 2017 New Revision: 296477
URL: http://llvm.org/viewvc/llvm-project?rev=296477&view=rev Log: [Sema] Detect more array index out of bounds when C++ overloaded operators are used Differential Revision: https://reviews.llvm.org/D30192 Modified: cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/SemaCXX/array-bounds.cpp Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=296477&r1=296476&r2=296477&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Feb 28 08:53:50 2017 @@ -10609,6 +10609,12 @@ void Sema::CheckArrayAccess(const Expr * CheckArrayAccess(rhs); return; } + case Stmt::CXXOperatorCallExprClass: { + const auto *OCE = cast<CXXOperatorCallExpr>(expr); + for (const auto *Arg : OCE->arguments()) + CheckArrayAccess(Arg); + return; + } default: return; } Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=296477&r1=296476&r2=296477&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/array-bounds.cpp (original) +++ cfe/trunk/test/SemaCXX/array-bounds.cpp Tue Feb 28 08:53:50 2017 @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -verify -std=c++11 %s int foo() { int x[2]; // expected-note 4 {{array 'x' declared here}} @@ -253,3 +253,19 @@ void test_rdar10916006(void) int a[128]; // expected-note {{array 'a' declared here}} a[(unsigned char)'\xA1'] = 1; // expected-warning {{array index 161 is past the end of the array}} } + +struct P { + int a; + int b; +}; + +void test_struct_array_index() { + struct P p[10]; // expected-note {{array 'p' declared here}} + p[11] = {0, 1}; // expected-warning {{array index 11 is past the end of the array (which contains 10 elements)}} +} + +int operator+(const struct P &s1, const struct P &s2); +int test_operator_overload_struct_array_index() { + struct P x[10] = {0}; // expected-note {{array 'x' declared here}} + return x[1] + x[11]; // expected-warning {{array index 11 is past the end of the array (which contains 10 elements)}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits