[cfe-commits] r145421 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/array-bounds.cpp
Matt Beaumont-Gay
matthewbg at google.com
Tue Nov 29 11:27:11 PST 2011
Author: matthewbg
Date: Tue Nov 29 13:27:11 2011
New Revision: 145421
URL: http://llvm.org/viewvc/llvm-project?rev=145421&view=rev
Log:
Merge branch 'yo-dawg-i-herd-u-like-arrays'
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=145421&r1=145420&r2=145421&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Nov 29 13:27:11 2011
@@ -4297,6 +4297,17 @@
<< 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)
Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=145421&r1=145420&r2=145421&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/array-bounds.cpp (original)
+++ cfe/trunk/test/SemaCXX/array-bounds.cpp Tue Nov 29 13:27:11 2011
@@ -4,10 +4,14 @@
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)}}
More information about the cfe-commits
mailing list