This is an archive of the discontinued LLVM Phabricator instance.

[dllexport] Avoid multiple codegen assert for explicitly defaulted methods in explicit instantiation definitions (PR47683)
ClosedPublic

Authored by hans on Nov 5 2020, 6:17 AM.

Diff Detail

Event Timeline

hans created this revision.Nov 5 2020, 6:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2020, 6:17 AM
hans requested review of this revision.Nov 5 2020, 6:17 AM
rnk added inline comments.Nov 5 2020, 9:27 AM
clang/lib/Sema/SemaDeclCXX.cpp
5887–5919

I wonder if this code block could be simplified by calculating two booleans:

  • ShouldReference: If true, call S.MarkFunctionReferenced
  • ShouldHandleNow: if true, call HandleTopLevelDecl

We want to mark the vast majority of C++ method decls referenced. The conditions I see here are:

  • user provided
  • non-trivial
  • trivial explicitly defaulted
  • trivial copy assign & move assign
  • an exception for non-inherited attributes on implicit specializations (?)
  • an exception for defaulted explicit instantiations

I tried to come up with a simpler description of those conditions, and couldn't come up with one.

Nevermind. I don't think my suggestion will make the code any simpler, but I'll leave this as a comment for your consideration.

5898–5907

Part of me wants to handle explicitly defaulted things separately from implicit special members, so we don't have to check for explicitly defaulted-ness twice.

clang/test/CodeGenCXX/dllexport.cpp
929

Let's also add a test case where the constructor is explicitly defaulted outside the body of the class. From reading the code, I know we will take the isUserProvided path instead, but I'd like to have it for completeness.

hans marked 3 inline comments as done.Nov 9 2020, 1:51 AM
hans added inline comments.
clang/lib/Sema/SemaDeclCXX.cpp
5898–5907

Thanks, that makes it a bit nicer.

hans updated this revision to Diff 303778.Nov 9 2020, 1:52 AM
hans marked an inline comment as done.

Addressing comments.

thakis accepted this revision.Nov 9 2020, 4:11 AM
thakis added a subscriber: thakis.
thakis added inline comments.
clang/lib/Sema/SemaDeclCXX.cpp
5917

should this grow a assert(TSK != TSK_ExplicitInstantiationDefinition) for symmetry?

This revision is now accepted and ready to land.Nov 9 2020, 4:11 AM
hans added inline comments.Nov 9 2020, 4:36 AM
clang/lib/Sema/SemaDeclCXX.cpp
5917

Hmm no, we can still have TSK==TSK_ExplicitInstantiationDefinition here, it's just for explicitly defaulted methods where we don't want to pass it to the consumer.