Author: rsmith Date: Tue Nov 14 17:33:46 2017 New Revision: 318245 URL: http://llvm.org/viewvc/llvm-project?rev=318245&view=rev Log: [modules] Fix crash in complex class merging scenario.
When we merge together class definitions, we can end up with the canonical declaration of a field not being the one that was lexically within the canonical definition of the class. Additionally, when we merge class definitions via update records (eg, for a template specialization whose declaration is instantiated in one module and whose definition is instantiated in multiple others), we can end up with the list of lexical contents for the class not including a particular declaration of a field whose lexical parent is that class definition. In the worst case, we have a field whose canonical declaration's lexical parent has no fields, and in that case this attempt to number the fields by walking the fields in the declaration of the class that contained one of the canonical fields will fail. Instead, when numbering fields in a class, do the obvious thing: walk the fields in the definition. I'm still trying to reduce a testcase; the setup that leads to the above scenario seems to be quite fragile. Modified: cfe/trunk/lib/AST/Decl.cpp Modified: cfe/trunk/lib/AST/Decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=318245&r1=318244&r2=318245&view=diff ============================================================================== --- cfe/trunk/lib/AST/Decl.cpp (original) +++ cfe/trunk/lib/AST/Decl.cpp Tue Nov 14 17:33:46 2017 @@ -3630,7 +3630,8 @@ unsigned FieldDecl::getFieldIndex() cons if (CachedFieldIndex) return CachedFieldIndex - 1; unsigned Index = 0; - const RecordDecl *RD = getParent(); + const RecordDecl *RD = getParent()->getDefinition(); + assert(RD && "requested index for field of struct with no definition"); for (auto *Field : RD->fields()) { Field->getCanonicalDecl()->CachedFieldIndex = Index + 1; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits