r362147 - [c++2a] Fix assertion failure if we would walk over more than one level

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu May 30 13:45:12 PDT 2019


Author: rsmith
Date: Thu May 30 13:45:12 2019
New Revision: 362147

URL: http://llvm.org/viewvc/llvm-project?rev=362147&view=rev
Log:
[c++2a] Fix assertion failure if we would walk over more than one level
of derived-to-base conversion path when implicitly starting union
subobject lifetimes in constant evaluation.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=362147&r1=362146&r2=362147&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu May 30 13:45:12 2019
@@ -5031,7 +5031,8 @@ static bool HandleUnionActiveMemberChang
       if (ICE->getCastKind() != CK_DerivedToBase &&
           ICE->getCastKind() != CK_UncheckedDerivedToBase)
         break;
-      for (const CXXBaseSpecifier *Elt : ICE->path()) {
+      // Walk path backwards as we walk up from the base to the derived class.
+      for (const CXXBaseSpecifier *Elt : llvm::reverse(ICE->path())) {
         --PathLength;
         (void)Elt;
         assert(declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(),

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp?rev=362147&r1=362146&r2=362147&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp Thu May 30 13:45:12 2019
@@ -521,4 +521,14 @@ namespace Union {
     u1 = u2;
     return true;
   }();
+
+  struct S1 {
+    int n;
+  };
+  struct S2 : S1 {};
+  struct S3 : S2 {};
+  void f() {
+    S3 s;
+    s.n = 0;
+  }
 }




More information about the cfe-commits mailing list