This is an archive of the discontinued LLVM Phabricator instance.

[Serialization] Fix that ASTDeclContextNameLookupTrait::data_type_builder never checks the first 4 DeclIDs for uniqueness
AcceptedPublic

Authored by teemperor on Jul 29 2020, 3:52 AM.

Details

Reviewers
rsmith
vsapsai
Summary

The insert function is supposed to check for uniqueness of any newly added DeclID, but the uniqueness
check for small result sets is always searching the empty Found set (which is always empty in this branch)
instead of the actual list of DeclIDs. This lead to Clang often adding identical NamespaceDecls to a DeclContext
lookup result.

See also D84827 for the assert that found this issue.

Diff Detail

Event Timeline

teemperor requested review of this revision.Jul 29 2020, 3:52 AM
teemperor created this revision.

Was the assertion triggered on existing test suite or on some other code?

The change looks correct to me, just want to make sure we have it tested.

All the patches here are just fixes for the test suite. This patch fixes those tests:

Clang :: Modules/stress1.cpp                                                  
Clang :: Modules/cxx-templates.cpp                                            
Clang :: Modules/pr27513.cpp                                                  
Clang :: Modules/merge-template-members.cpp                                   
Clang :: Modules/templates.mm                                                 
Clang :: Modules/cxx-lookup.cpp                                               
Clang :: Modules/exponential-paths.cpp                                        
Clang :: Modules/odr_hash-Friend.cpp
vsapsai accepted this revision.Oct 30 2020, 11:48 AM

I believe the fix isn't controversial and doesn't require Richard's attention.

As aside, it would be nice for static analyzer to be able to detect

if (container.empty()) {
  // iterate through container
}
This revision is now accepted and ready to land.Oct 30 2020, 11:48 AM

Agreed the fix is correct, and that a unit test would be nice (although annoying since the type isn't currently in include/clang).

I wonder if this should just use a SmallDenseSet and be done with it though?

Agreed the fix is correct, and that a unit test would be nice (although annoying since the type isn't currently in include/clang).

I wonder if this should just use a SmallDenseSet and be done with it though?

Note, I don't feel strongly about the unit test if that'll hold up landing the fix (given that the assertion is going in fairly promptly anyway) -- feel free to commit -- but it might be worth considering in a follow-up.