[modules] Fix miscompilation when using two RecordDecl definitions with the same name.When deserializing a RecordDecl we don't enforce that redeclarationchain contains only a single definition. So
[modules] Fix miscompilation when using two RecordDecl definitions with the same name.When deserializing a RecordDecl we don't enforce that redeclarationchain contains only a single definition. So if the canonical decl is nota definition itself, `RecordType::getDecl` can return different objectsbefore and after an include. It means we can build CGRecordLayout forone RecordDecl with its set of FieldDecl but try to use it withFieldDecl belonging to a different RecordDecl. With assertions enabledit results in> Assertion failed: (FieldInfo.count(FD) && "Invalid field for record!"),> function getLLVMFieldNo, file llvm-project/clang/lib/CodeGen/CGRecordLayout.h, line 199.and with assertions disabled a bunch of fields are treated as theirmemory is located at offset 0.Fix by keeping the first encountered RecordDecl definition and markingthe subsequent ones as non-definitions. Also need to merge FieldDeclproperly, so that `getPrimaryMergedDecl` works correctly and during namelookup we don't treat fields from same-name RecordDecl as ambiguous.rdar://80184238Differential Revision: https://reviews.llvm.org/D106994
show more ...