This is an archive of the discontinued LLVM Phabricator instance.

Modify ImportDefiniton for ObjCInterfaceDecl so that we always the ImportDeclContext one we start the definition
ClosedPublic

Authored by shafik on Jul 16 2020, 11:15 AM.

Details

Summary

Once we start the definition of an ObjCInterfaceDecl we won't attempt to ImportDeclContext later on. Unlike RecordDecl case which uses DefinitionCompleter to force completeDefinition we don't seem to have a similar mechanism for ObjCInterfaceDecl.

This fix was needed due to a bug we see in LLDB expression parsing where an initial expression cause an ObjCInterfaceDecl to be defined and subsequent expressions during import do not call ImportDeclContext and we can end up in a situation where ivars are imported out of order and not all ivars are imported e.g.

(lldb) expr chb1->hb->field2
ObjCInterfaceDecl 0x7f9457495fe0 <<invalid sloc>> <invalid sloc> <undeserialized declarations> HasBitfield1
|-super ObjCInterface 0x7f9457495e78 'NSObject'
`-ObjCIvarDecl 0x7f945749d478 <<invalid sloc>> <invalid sloc> field2 'unsigned int' public
  `-IntegerLiteral 0x7f945749d458 <<invalid sloc>> 'int' 1

We have field2 which is the second ivar but we are missing field1.

In this particular case ASTContext::lookupFieldBitOffset(...) assumes we have all ivars and they are in order to obtain the index of the ivar and we break this assumption. This leads eventually to bad IRGen since it has the wrong field offset.

Diff Detail

Event Timeline

shafik created this revision.Jul 16 2020, 11:15 AM
shafik updated this revision to Diff 280291.Jul 23 2020, 4:42 PM

Updating diff since the parent landed.

martong accepted this revision.Jul 24 2020, 12:45 AM

Unlike RecordDecl case which uses DefinitionCompleter to force completeDefinition we don't seem to have a similar mechanism for ObjCInterfaceDecl.

It is unfortunate that the AST does not have something similar for ObjC interfaces.
So, this seems to be the right way unless we want to modify DeclObjC.h.
LGTM!

This revision is now accepted and ready to land.Jul 24 2020, 12:45 AM
This revision was automatically updated to reflect the committed changes.
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 24 2020, 1:15 PM