[PATCH] D59776: [Sema] Don't check for array bounds when the types in the base expression are dependent.
Phabricator via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 25 14:35:57 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356957: [Sema] Don't check for array bounds when the types in the base expression areā¦ (authored by brunoricci, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D59776?vs=192115&id=192209#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59776/new/
https://reviews.llvm.org/D59776
Files:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/array-bounds.cpp
Index: cfe/trunk/test/SemaCXX/array-bounds.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/array-bounds.cpp
+++ cfe/trunk/test/SemaCXX/array-bounds.cpp
@@ -296,3 +296,16 @@
// We can still diagnose this.
C &h() { return reinterpret_cast<C *>(xxx)[-1]; } // expected-warning {{array index -1 is before the beginning of the array}}
}
+
+namespace PR41087 {
+ template <typename Ty> void foo() {
+ Ty buffer[2]; // expected-note 3{{array 'buffer' declared here}}
+ ((char *)buffer)[2] = 'A'; // expected-warning 1{{array index 2 is past the end of the array (which contains 2 elements)}}
+ ((char *)buffer)[-1] = 'A'; // expected-warning 2{{array index -1 is before the beginning of the array}}
+ }
+
+ void f() {
+ foo<char>(); // expected-note 1{{in instantiation of function template specialization}}
+ foo<int>(); // expected-note 1{{in instantiation of function template specialization}}
+ };
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -12522,6 +12522,8 @@
return;
const Type *BaseType = ArrayTy->getElementType().getTypePtr();
+ if (EffectiveType->isDependentType() || BaseType->isDependentType())
+ return;
Expr::EvalResult Result;
if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59776.192209.patch
Type: text/x-patch
Size: 1464 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190325/e5043d9b/attachment.bin>
More information about the cfe-commits
mailing list