Page MenuHomePhabricator

Make Decl:: setOwningModuleID() public. (NFC)
ClosedPublic

Authored by aprantl on Mar 3 2020, 12:57 PM.

Details

Summary

This API is going to be used by LLDB to recreate owning module information for Decls deserializwed from DWARF. Because of the assertion I also need to make setFromASTFile public. Alternatively, we could remove the assertion.

Diff Detail

Event Timeline

aprantl created this revision.Mar 3 2020, 12:57 PM
aprantl retitled this revision from Make Decl::setFromASTFile() public. (NFC) to Make Decl:: setOwningModuleID() public. (NFC).Mar 4 2020, 8:48 AM
aprantl edited the summary of this revision. (Show Details)
rsmith added inline comments.Mar 4 2020, 4:15 PM
clang/include/clang/AST/DeclBase.h
629–630

Setting this after creating a Decl is not safe in general; declarations with this flag set have 8 bytes of additional storage allocated before their start.

An assert(FromASTFile || hasLocalOwningModuleStorage()); would at least catch the unsafe cases. This also needs a comment saying that it's not safe to use in general, and perhaps a scarier name to discourage people from calling it. (Unless you're creating declarations with ::CreateDeserialized -- in which case you'd need all the Decl subclasses to befriend the creator, making this function unnecessary -- this is currently only going to be safe if ModulesLocalVisibility is enabled.)

aprantl updated this revision to Diff 248618.Mar 5 2020, 3:51 PM

I took your suggestion to heart and changed the downstream LLDB patch to use CreateDeserialized() everywhere, which is frankly a better fit there anyway. To make this possible I had to make a few more setters public, see the updated patch.

I also discovered that DeclBase::operator new() now always allocates 2*4 bytes extra storage. I think it needs to do this for local submodule visibility. This makes my change to CreateDeserialized() not strictly necessary, but I think it is better anyway.

aprantl marked an inline comment as done.Mar 5 2020, 3:54 PM
aprantl added inline comments.
clang/include/clang/AST/DeclBase.h
629–630

I think the warning is unnecessary, since the storage is always allocated. Please let me know if I misunderstood something.

rsmith accepted this revision.Mar 5 2020, 6:00 PM

I'm surprised so few setters needed to be made public for this to work. If this required making lots more setters public, I'd be concerned, because we generally don't want large chunks of the AST to be mutable after creation. But this seems fine.

clang/include/clang/AST/DeclBase.h
629–630

The storage isn't necessarily allocated if the decl is created with ::Create rather than ::CreateDeserialized. Just changing the comment to say the declaration must have been created with CreateDeserialized would be fine.

This revision is now accepted and ready to land.Mar 5 2020, 6:00 PM
shafik accepted this revision.Mar 11 2020, 10:34 AM

LGTM

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2020, 3:57 PM