[modules] Fix IRGen assertion on accessing ObjC ivar inside a method.
When have ObjCInterfaceDecl with the same name in 2 different modules, hitting the assertion > Assertion failed: (Index < RL->getFieldCount() && "Ivar is not inside record layout!"), > function lookupFieldBitOffset, file llvm-project/clang/lib/AST/RecordLayoutBuilder.cpp, line 3434. on accessing an ivar inside a method. The assertion happens because ivar belongs to one module while its containing interface belongs to another module and then we fail to find the ivar inside the containing interface. We already keep a single ObjCInterfaceDecl definition in redecleration chain and in this case containing interface was correct. The issue is with ObjCIvarDecl. IVar decl for IRGen is taken from ObjCIvarRefExpr that is created in `Sema::BuildIvarRefExpr` using ivar decl returned from `Sema::LookupIvarInObjCMethod`. And ivar lookup returns a wrong decl because basically we take the first ObjCIvarDecl found in `ASTReader::FindExternalVisibleDeclsByName` (called by `DeclContext::lookup`). And in `ASTReader.Lookups` lookup table for a wrong module comes first because `ASTReader::finishPendingActions` processes `PendingUpdateRecords` in reverse order and the first encountered ObjCIvarDecl will end up the last in `ASTReader.Lookups`. Fix by merging ObjCIvarDecl from different modules correctly and by using a canonical one in IRGen. rdar://82854574 Differential Revision: https://reviews.llvm.org/D110280
Loading
Please register or sign in to comment