Prior to this change:
We see the following crash:
assert.h assertion failed at PATH/TO/clang/lib/AST/ExprConstant.cpp:6320 in auto HandleConstructorCall(const Expr *, const LValue &, CallRef, const CXXConstructorDecl *, EvalInfo &, APValue &)::(anonymous class)::operator()(FieldDecl *, bool) const: Indirect && "fields out of order?" *** Check failure stack trace: *** @ 0x5555721ac3a6 __assert_fail @ 0x555569c24a7f HandleConstructorCall()::$_0::operator()() @ 0x555569c239a1 HandleConstructorCall() @ 0x555569b35ac0 HandleConstructorCall() @ 0x555569c0bf8c (anonymous namespace)::RecordExprEvaluator::VisitCXXConstructExpr() @ 0x555569c16974 (anonymous namespace)::RecordExprEvaluator::VisitCXXConstructExpr() @ 0x555569c0f60a clang::StmtVisitorBase<>::Visit() @ 0x555569c26fcb (anonymous namespace)::RecordExprEvaluator::VisitCastExpr() @ 0x555569c27a0e clang::StmtVisitorBase<>::VisitExplicitCastExpr() @ 0x555569c184fe clang::StmtVisitorBase<>::VisitCXXFunctionalCastExpr() @ 0x555569c0fd87 clang::StmtVisitorBase<>::Visit() @ 0x555569c4c001 EvaluateRecord() @ 0x555569b2dabf EvaluateInPlace() @ 0x555569b33b19 EvaluateCallArg() @ 0x555569b80acf EvaluateArgs() @ 0x555569c26813 (anonymous namespace)::ExprEvaluatorBase<>::handleCallExpr() @ 0x555569c181ef (anonymous namespace)::RecordExprEvaluator::VisitCallExpr() @ 0x555569c0fb96 clang::StmtVisitorBase<>::Visit() @ 0x555569c16887 (anonymous namespace)::ExprEvaluatorBase<>::VisitCXXBindTemporaryExpr() @ 0x555569c0f57c clang::StmtVisitorBase<>::Visit() @ 0x555569c1946e (anonymous namespace)::ExprEvaluatorBase<>::VisitExprWithCleanups() @ 0x555569c10476 clang::StmtVisitorBase<>::Visit() @ 0x555569c4c001 EvaluateRecord() @ 0x555569b2dabf EvaluateInPlace() @ 0x555569b8b754 EvaluateVarDecl() @ 0x555569b8b843 EvaluateDecl() @ 0x555569b872d3 EvaluateStmt() @ 0x555569b8772c EvaluateStmt() @ 0x555569c2457e HandleConstructorCall() @ 0x555569b35ac0 HandleConstructorCall() @ 0x555569c0bf8c (anonymous namespace)::RecordExprEvaluator::VisitCXXConstructExpr() @ 0x555569c16974 (anonymous namespace)::RecordExprEvaluator::VisitCXXConstructExpr() @ 0x555569c0f60a clang::StmtVisitorBase<>::Visit() @ 0x555569c4c001 EvaluateRecord() @ 0x555569b2dabf EvaluateInPlace() @ 0x555569b2e6d6 clang::Expr::EvaluateAsInitializer() @ 0x555569a18b14 clang::VarDecl::evaluateValueImpl() @ 0x555569a187da clang::VarDecl::evaluateValue() @ 0x555563f5a973 clang::CodeGen::ConstantEmitter::tryEmitPrivateForVarInit() @ 0x555563f5cda3 clang::CodeGen::ConstantEmitter::tryEmitForInitializer() @ 0x5555644eb927 clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition() @ 0x5555644d935d clang::CodeGen::CodeGenModule::EmitGlobalDefinition() @ 0x5555644e199e clang::CodeGen::CodeGenModule::EmitGlobal() @ 0x5555644d6967 clang::CodeGen::CodeGenModule::EmitTopLevelDecl() @ 0x5555644d7dbe clang::CodeGen::CodeGenModule::EmitTopLevelDecl() @ 0x5555648e973e (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl() @ 0x555563950511 clang::BackendConsumer::HandleTopLevelDecl() @ 0x555569544269 clang::ASTConsumer::HandleImplicitImportDecl() @ 0x55556839611d clang::Sema::BuildModuleInclude() @ 0x555568395e33 clang::Sema::ActOnModuleInclude() @ 0x5555669529df clang::Parser::ParseTopLevelDecl() @ 0x55556694af35 clang::ParseAST() @ 0x5555663b0b66 clang::ASTFrontendAction::ExecuteAction() @ 0x555563947e9c clang::CodeGenAction::ExecuteAction() @ 0x5555663b0084 clang::FrontendAction::Execute() @ 0x555566273de5 clang::CompilerInstance::ExecuteAction() @ 0x5555623226aa clang::ExecuteCompilerInvocation() @ 0x5555622ece85 cc1_main() @ 0x5555622cb325 ExecuteCC1Tool() @ 0x55556679c567 clang::driver::CC1Command::Execute()::$_0::operator()()
Debug values (Frame 0x555569c239a1 at Line SkipToField(FD, false);):
Context in function static bool HandleConstructorCall(const Expr *E, const LValue &This,...):
const CXXRecordDecl *RD = Definition->getParent(); ... for (const auto *I : Definition->inits()) { if ((FD = I->getMember())) { ... } } ...
RD->dumpColor() CXXRecordDecl 0x68f339c36a8 <PATH/TO/include/c++/v1/vector:428:3, line:444:3> line:428:9 imported in //third_party/stl:stl_cc_library.third_party/stl/cxx17/vector class __destroy_vector
FD->dumpColor() FieldDecl 0x68f33694608 parent 0x68f339c3f30 <PATH/TO/include/c++/v1/vector:443:7, col:15> col:15 imported in //third_party/stl:stl_cc_library.third_party/stl/cxx17/vector referenced __vec_ 'vector<string> &'
Note that RD does not contain any FieldDecl but __destroy_vector actually contains member vector<string> &.
The crash is primarily because of this missing information of the FieldDecl from RecordDecl.
Note that FD refers to 0x68f339c3f30 as the parent which is different from RD 0x68f339c36a8.
FD->getParent()->dumpColor() CXXRecordDecl 0x68f339c3f30 prev 0x68f339c36a8 <PATH/TO/include/c++/v1/vector:428:3, line:444:3> line:428:9 imported in //third_party/stl:stl_cc_library.third_party/stl/cxx17/vector class __destroy_vector definition ... |-FieldDecl 0x68f33694798 first 0x68f33694608 <line:443:7, col:15> col:15 imported in //third_party/stl:stl_cc_library.third_party/stl/cxx17/vector referenced __vec_ 'vector<string> &' ...
In fact RD (0x68f339c36a8) is the previous declaration of FD->getParent().
The FieldDecl should be read from the definition data (FD->getParent() or RD->getMostRecentDecl() or RD->getDefinition())
I think it would make sense to use the definition of the class as RD here, since we're going to be iterating through RD's fields.