[cfe-commits] r125693 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/array-bounds.c test/SemaCXX/array-bounds.cpp

Ted Kremenek kremenek at apple.com
Wed Feb 16 15:39:09 PST 2011


Author: kremenek
Date: Wed Feb 16 17:39:09 2011
New Revision: 125693

URL: http://llvm.org/viewvc/llvm-project?rev=125693&view=rev
Log:
Fix assertion failure in -Warray-bounds on template parameters used as arrays.

Added:
    cfe/trunk/test/SemaCXX/array-bounds.cpp
      - copied, changed from r125690, cfe/trunk/test/Sema/array-bounds.c
Removed:
    cfe/trunk/test/Sema/array-bounds.c
Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=125693&r1=125692&r2=125693&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Feb 16 17:39:09 2011
@@ -3085,7 +3085,9 @@
     dyn_cast<DeclRefExpr>(ae->getBase()->IgnoreParenImpCasts());
   if (!dr)
     return;
-  const VarDecl *vd = cast<VarDecl>(dr->getDecl());
+  const VarDecl *vd = dyn_cast<VarDecl>(dr->getDecl());
+  if (!vd)
+    return;
   const ConstantArrayType *cat = Context.getAsConstantArrayType(vd->getType());
   if (!cat)
     return;

Removed: cfe/trunk/test/Sema/array-bounds.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-bounds.c?rev=125692&view=auto
==============================================================================
--- cfe/trunk/test/Sema/array-bounds.c (original)
+++ cfe/trunk/test/Sema/array-bounds.c (removed)
@@ -1,16 +0,0 @@
-// RUN: %clang_cc1 -verify %s
-
-int foo() {
-  int x[2]; // expected-note 4 {{array 'x' declared here}}
-  int y[2]; // expected-note 2 {{array 'y' declared here}}
-  int *p = &y[2]; // no-warning
-  (void) sizeof(x[2]); // no-warning
-  y[2] = 2; // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}}
-  return x[2] +  // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}}
-         y[-1] + // expected-warning{{array index of '-1' indexes before the beginning of the array}}
-         x[sizeof(x)] +  // expected-warning{{array index of '8' indexes past the end of an array (that contains 2 elements)}}
-         x[sizeof(x) / sizeof(x[0])] +  // expected-warning{{array index of '2' indexes past the end of an array (that contains 2 elements)}}
-         x[sizeof(x) / sizeof(x[0]) - 1] + // no-warning
-         x[sizeof(x[2])]; // expected-warning{{array index of '4' indexes past the end of an array (that contains 2 elements)}}
-}
-

Copied: cfe/trunk/test/SemaCXX/array-bounds.cpp (from r125690, cfe/trunk/test/Sema/array-bounds.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?p2=cfe/trunk/test/SemaCXX/array-bounds.cpp&p1=cfe/trunk/test/Sema/array-bounds.c&r1=125690&r2=125693&rev=125693&view=diff
==============================================================================
--- cfe/trunk/test/Sema/array-bounds.c (original)
+++ cfe/trunk/test/SemaCXX/array-bounds.cpp Wed Feb 16 17:39:09 2011
@@ -14,3 +14,8 @@
          x[sizeof(x[2])]; // expected-warning{{array index of '4' indexes past the end of an array (that contains 2 elements)}}
 }
 
+// This code example tests that -Warray-bounds works with arrays that
+// are template parameters.
+template <char *sz> class Qux {
+  bool test() { return sz[0] == 'a'; }
+};
\ No newline at end of file





More information about the cfe-commits mailing list