[cfe-commits] r126291 - /cfe/trunk/test/SemaCXX/array-bounds.cpp

Ted Kremenek kremenek at apple.com
Tue Feb 22 17:52:07 PST 2011


Author: kremenek
Date: Tue Feb 22 19:52:07 2011
New Revision: 126291

URL: http://llvm.org/viewvc/llvm-project?rev=126291&view=rev
Log:
Add test case for PR 9284, a false positive for -Warray-bounds that is now addressed using basic reachability analysis.

Modified:
    cfe/trunk/test/SemaCXX/array-bounds.cpp

Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=126291&r1=126290&r2=126291&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/array-bounds.cpp (original)
+++ cfe/trunk/test/SemaCXX/array-bounds.cpp Tue Feb 22 19:52:07 2011
@@ -90,15 +90,28 @@
   return array[(unsigned long long) 100]; // expected-warning {{array index of '100' indexes past the end of an array (that contains 100 elements)}}
 }
 
+// PR 9284 - a template parameter can cause an array bounds access to be
+// infeasible.
 template <bool extendArray>
-void myFunc() {
+void pr9284() {
     int arr[3 + (extendArray ? 1 : 0)];
 
     if (extendArray)
-        arr[3] = 42;
+        arr[3] = 42; // no-warning
 }
 
-void f() {
-    myFunc<false>();
+template <bool extendArray>
+void pr9284b() {
+    int arr[3 + (extendArray ? 1 : 0)]; // expected-note {{array 'arr' declared here}}
+
+    if (!extendArray)
+        arr[3] = 42; // expected-warning{{array index of '3' indexes past the end of an array (that contains 3 elements)}}
+}
+
+void test_pr9284() {
+    pr9284<true>();
+    pr9284<false>();
+    pr9284b<true>();
+    pr9284b<false>(); // expected-note{{in instantiation of function template specialization 'pr9284b<false>' requested here}}
 }
 





More information about the cfe-commits mailing list