[llvm-branch-commits] [cfe-branch] r329478 - Merging r327099:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Apr 6 20:30:07 PDT 2018


Author: tstellar
Date: Fri Apr  6 20:30:07 2018
New Revision: 329478

URL: http://llvm.org/viewvc/llvm-project?rev=329478&view=rev
Log:
Merging r327099:

------------------------------------------------------------------------
r327099 | rsmith | 2018-03-08 18:00:01 -0800 (Thu, 08 Mar 2018) | 3 lines

PR36645: Go looking for an appropriate array bound when constant-evaluating a
name of an array object.

------------------------------------------------------------------------

Modified:
    cfe/branches/release_60/lib/AST/ExprConstant.cpp
    cfe/branches/release_60/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/branches/release_60/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/lib/AST/ExprConstant.cpp?rev=329478&r1=329477&r2=329478&view=diff
==============================================================================
--- cfe/branches/release_60/lib/AST/ExprConstant.cpp (original)
+++ cfe/branches/release_60/lib/AST/ExprConstant.cpp Fri Apr  6 20:30:07 2018
@@ -61,14 +61,22 @@ namespace {
 
   static QualType getType(APValue::LValueBase B) {
     if (!B) return QualType();
-    if (const ValueDecl *D = B.dyn_cast<const ValueDecl*>())
+    if (const ValueDecl *D = B.dyn_cast<const ValueDecl*>()) {
       // FIXME: It's unclear where we're supposed to take the type from, and
-      // this actually matters for arrays of unknown bound. Using the type of
-      // the most recent declaration isn't clearly correct in general. Eg:
+      // this actually matters for arrays of unknown bound. Eg:
       //
       // extern int arr[]; void f() { extern int arr[3]; };
       // constexpr int *p = &arr[1]; // valid?
-      return cast<ValueDecl>(D->getMostRecentDecl())->getType();
+      //
+      // For now, we take the array bound from the most recent declaration.
+      for (auto *Redecl = cast<ValueDecl>(D->getMostRecentDecl()); Redecl;
+           Redecl = cast_or_null<ValueDecl>(Redecl->getPreviousDecl())) {
+        QualType T = Redecl->getType();
+        if (!T->isIncompleteArrayType())
+          return T;
+      }
+      return D->getType();
+    }
 
     const Expr *Base = B.get<const Expr*>();
 

Modified: cfe/branches/release_60/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/test/SemaCXX/constant-expression-cxx11.cpp?rev=329478&r1=329477&r2=329478&view=diff
==============================================================================
--- cfe/branches/release_60/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/branches/release_60/test/SemaCXX/constant-expression-cxx11.cpp Fri Apr  6 20:30:07 2018
@@ -629,6 +629,10 @@ namespace ArrayOfUnknownBound {
 
   extern const int carr[]; // expected-note {{here}}
   constexpr int n = carr[0]; // expected-error {{constant}} expected-note {{non-constexpr variable}}
+
+  constexpr int local_extern[] = {1, 2, 3};
+  void f() { extern const int local_extern[]; }
+  static_assert(local_extern[1] == 2, "");
 }
 
 namespace DependentValues {




More information about the llvm-branch-commits mailing list