This is an archive of the discontinued LLVM Phabricator instance.

[clang][ASTImporter] Improve StructuralEquivalence algorithm on repeated friends
AbandonedPublic

Authored by danix800 on Aug 4 2023, 8:56 AM.

Details

Summary

Repeated friends are deduplicated when imported, but StructuralEquivalence checks friends by exact matching.
If ToContext is empty (not containing the class to be imported), the imported friends are deduplicated, any
further importing of the class would be rejected at the structure equivalence checking, i.e:

struct foo { friend class X; friend class X; }; // FromContext

only one friend is imported, similar to the following:

struct foo { friend class X; }; // ToContext

but when imported again, struct foo in FromContext is reported as not equivalent to struct foo in ToContext,
thus rejected.

The structural equivalence checking algorithm is improved by applying similar deduplication as Importer does.
Thus from StructuralEquivalence's point of view, the above two RecordDecls are equivalent.

Fixes https://github.com/llvm/llvm-project/issues/64425.

Diff Detail

Event Timeline

danix800 created this revision.Aug 4 2023, 8:56 AM
Herald added a project: Restricted Project. · View Herald Transcript
danix800 requested review of this revision.Aug 4 2023, 8:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 8:56 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
steakhal resigned from this revision.Aug 4 2023, 8:58 AM

In general, I'm not really involved with the ASTImporter.
Please, put me as a reviewer if the ASTImporter directly affects the Static Analyzer.

danix800 edited the summary of this revision. (Show Details)Aug 4 2023, 9:08 AM
danix800 updated this revision to Diff 549059.Aug 10 2023, 8:47 AM

CXXRecordDecl::friend_iterator is actually a reversed iterator. Deduplication with
different iterator direction produces different result. ASTImporter uses forward iterator
so structural equivalence checking should be in consistent with that.

danix800 abandoned this revision.Aug 10 2023, 10:51 AM