r213816 - Add a missing Invalid check to SubobjectDesignator::isOnePastEnd()

Reid Kleckner reid at kleckner.net
Wed Jul 23 16:24:25 PDT 2014


Author: rnk
Date: Wed Jul 23 18:24:25 2014
New Revision: 213816

URL: http://llvm.org/viewvc/llvm-project?rev=213816&view=rev
Log:
Add a missing Invalid check to SubobjectDesignator::isOnePastEnd()

The class seems to have an invariant that Entries is non-empty if
Invalid is false.  It appears this method was previously private, and
all internal uses checked Invalid.  Now there is an external caller, so
check Invalid to avoid array OOB underflow.

Fixes PR20420.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/SemaCXX/warn-global-constructors.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=213816&r1=213815&r2=213816&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Jul 23 18:24:25 2014
@@ -201,6 +201,8 @@ namespace {
 
     /// Determine whether this is a one-past-the-end pointer.
     bool isOnePastTheEnd() const {
+      if (Invalid)
+        return false;
       if (IsOnePastTheEnd)
         return true;
       if (MostDerivedArraySize &&

Modified: cfe/trunk/test/SemaCXX/warn-global-constructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-global-constructors.cpp?rev=213816&r1=213815&r2=213816&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-global-constructors.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-global-constructors.cpp Wed Jul 23 18:24:25 2014
@@ -120,3 +120,9 @@ namespace pr19253 {
   };
   E e;
 }
+
+namespace pr20420 {
+// No warning is expected. This used to crash.
+void *array_storage[1];
+const int &global_reference = *(int *)array_storage;
+}





More information about the cfe-commits mailing list