This is an archive of the discontinued LLVM Phabricator instance.

[UniqueLinkageName] Use exsiting GlobalDecl object instead of reconstructing one.
ClosedPublic

Authored by hoy on May 12 2021, 12:43 PM.

Details

Summary

C++ constructors/destructors need to go through a different constructor to construct a GlobalDecl object in order to retrieve their linkage type. This causes an assert failure in the default constructor of GlobalDecl. I'm chaning it to using the exsiting GlobalDecl object.

Diff Detail

Event Timeline

hoy created this revision.May 12 2021, 12:43 PM
hoy requested review of this revision.May 12 2021, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2021, 12:43 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

This was previously crashing, I guess? Testing should validate the behavior beyond the crash, though - (presumably there's some more specific behavior than "does not crash" that wasn't being tested for before - that certain names are mangled appropriately or what-have-you)

hoy added a comment.May 13 2021, 4:02 PM

This was previously crashing, I guess? Testing should validate the behavior beyond the crash, though - (presumably there's some more specific behavior than "does not crash" that wasn't being tested for before - that certain names are mangled appropriately or what-have-you)

Yes, an assert was triggered related to c++ constructors/destructors while it's not now. Regarding the behavior, c++ constructors/destructors are not static, so I don't expect a behavior change.

This was previously crashing, I guess? Testing should validate the behavior beyond the crash, though - (presumably there's some more specific behavior than "does not crash" that wasn't being tested for before - that certain names are mangled appropriately or what-have-you)

Yes, an assert was triggered related to c++ constructors/destructors while it's not now. Regarding the behavior, c++ constructors/destructors are not static, so I don't expect a behavior change.

ctors/dtors can have internal linkage, if the type has internal linkage (if it's in an anonymous namespace) - but in any case, my point was that there's some specific behavior you're expecting, even if that behavior is "does not get this attribute" - previously no code tested that with this feature enabled the ctor wouldn't get the attribute (because it couldn't've tested that, because what it did was crash) - so testing that would be good.

But testing the attribute does work on the ctor of a type in an anonymous namespace would be suitable too.

hoy added a comment.May 14 2021, 4:42 PM

This was previously crashing, I guess? Testing should validate the behavior beyond the crash, though - (presumably there's some more specific behavior than "does not crash" that wasn't being tested for before - that certain names are mangled appropriately or what-have-you)

Yes, an assert was triggered related to c++ constructors/destructors while it's not now. Regarding the behavior, c++ constructors/destructors are not static, so I don't expect a behavior change.

ctors/dtors can have internal linkage, if the type has internal linkage (if it's in an anonymous namespace) - but in any case, my point was that there's some specific behavior you're expecting, even if that behavior is "does not get this attribute" - previously no code tested that with this feature enabled the ctor wouldn't get the attribute (because it couldn't've tested that, because what it did was crash) - so testing that would be good.

But testing the attribute does work on the ctor of a type in an anonymous namespace would be suitable too.

Good to know that ctors/dtors can have internal linkage. How do you get that? The C++ standard doesn't allow ctors to be static.

This was previously crashing, I guess? Testing should validate the behavior beyond the crash, though - (presumably there's some more specific behavior than "does not crash" that wasn't being tested for before - that certain names are mangled appropriately or what-have-you)

Yes, an assert was triggered related to c++ constructors/destructors while it's not now. Regarding the behavior, c++ constructors/destructors are not static, so I don't expect a behavior change.

ctors/dtors can have internal linkage, if the type has internal linkage (if it's in an anonymous namespace) - but in any case, my point was that there's some specific behavior you're expecting, even if that behavior is "does not get this attribute" - previously no code tested that with this feature enabled the ctor wouldn't get the attribute (because it couldn't've tested that, because what it did was crash) - so testing that would be good.

But testing the attribute does work on the ctor of a type in an anonymous namespace would be suitable too.

Good to know that ctors/dtors can have internal linkage. How do you get that? The C++ standard doesn't allow ctors to be static.

Placing the type within an anonymous namespace should do the trick, something like this: https://godbolt.org/z/8YMWhbWM8

hoy updated this revision to Diff 355012.Jun 28 2021, 1:13 PM

Added tests for static ctor/dtor.

dblaikie accepted this revision.Jun 28 2021, 1:28 PM

Looks alright, thanks!

This revision is now accepted and ready to land.Jun 28 2021, 1:28 PM