forked from OSchip/llvm-project
Merge branch 'yo-dawg-i-herd-u-like-arrays'
llvm-svn: 145421
This commit is contained in:
parent
539d0a8a09
commit
b2339826e6
|
@ -4297,6 +4297,17 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
|
|||
<< IndexExpr->getSourceRange());
|
||||
}
|
||||
|
||||
if (!ND) {
|
||||
// Try harder to find a NamedDecl to point at in the note.
|
||||
while (const ArraySubscriptExpr *ASE =
|
||||
dyn_cast<ArraySubscriptExpr>(BaseExpr))
|
||||
BaseExpr = ASE->getBase()->IgnoreParenCasts();
|
||||
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(BaseExpr))
|
||||
ND = dyn_cast<NamedDecl>(DRE->getDecl());
|
||||
if (const MemberExpr *ME = dyn_cast<MemberExpr>(BaseExpr))
|
||||
ND = dyn_cast<NamedDecl>(ME->getMemberDecl());
|
||||
}
|
||||
|
||||
if (ND)
|
||||
DiagRuntimeBehavior(ND->getLocStart(), BaseExpr,
|
||||
PDiag(diag::note_array_index_out_of_bounds)
|
||||
|
|
|
@ -4,10 +4,14 @@ int foo() {
|
|||
int x[2]; // expected-note 4 {{array 'x' declared here}}
|
||||
int y[2]; // expected-note 2 {{array 'y' declared here}}
|
||||
int z[1]; // expected-note {{array 'z' declared here}}
|
||||
int w[1][1]; // expected-note {{array 'w' declared here}}
|
||||
int v[1][1][1]; // expected-note {{array 'v' declared here}}
|
||||
int *p = &y[2]; // no-warning
|
||||
(void) sizeof(x[2]); // no-warning
|
||||
y[2] = 2; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
|
||||
z[1] = 'x'; // expected-warning {{array index 1 is past the end of the array (which contains 1 element)}}
|
||||
w[0][2] = 0; // expected-warning {{array index 2 is past the end of the array (which contains 1 element)}}
|
||||
v[0][0][2] = 0; // expected-warning {{array index 2 is past the end of the array (which contains 1 element)}}
|
||||
return x[2] + // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
|
||||
y[-1] + // expected-warning {{array index -1 is before the beginning of the array}}
|
||||
x[sizeof(x)] + // expected-warning {{array index 8 is past the end of the array (which contains 2 elements)}}
|
||||
|
|
Loading…
Reference in New Issue