This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Export CanPassInRegisters as a type trait
ClosedPublic

Authored by royjacobson on Jan 14 2023, 1:13 PM.

Details

Summary

While working on D140664, I thought it would be nice to be able to write tests
for parameter passing ABI. Currently we test this by dumping the AST and
matching the results which makes it hard to write new tests.
Adding this builtin will allow writing better ABI tests which
can help improve our coverage in this area.

While less useful, maybe some users would also find it useful for asserting
against pessimisations for their classes.

Diff Detail

Event Timeline

royjacobson created this revision.Jan 14 2023, 1:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2023, 1:13 PM
royjacobson requested review of this revision.Jan 14 2023, 1:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2023, 1:14 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
erichkeane added inline comments.Jan 17 2023, 6:19 AM
clang/lib/Sema/SemaExprCXX.cpp
5380

Is there good reason to return true for all non-record types? Should we instead be limiting the types that can make it this far?

shafik added a subscriber: shafik.Jan 17 2023, 8:16 AM
shafik added inline comments.
clang/lib/Sema/SemaExprCXX.cpp
5380

Looking how it is used internally, I think it makes sense to restrict this to records.

Reject non class types, update doc.

royjacobson added inline comments.Jan 17 2023, 1:57 PM
clang/lib/Sema/SemaExprCXX.cpp
5380

My initial thinking was 'well references/builtins ARE passed by registers'. But I thought about this a bit and I agree with you, it's probably better to restrict this.

erichkeane accepted this revision.Jan 17 2023, 4:08 PM
This revision is now accepted and ready to land.Jan 17 2023, 4:08 PM

fix the test after diag change

This revision was landed with ongoing or failed builds.Feb 13 2023, 9:16 AM
This revision was automatically updated to reflect the committed changes.

Is this essentially "is_trivial_for_the_purposes_of_abi"?

Is this essentially "is_trivial_for_the_purposes_of_abi"?

I'd say so. Are you asking for a potential libc++ use case?

Is this essentially "is_trivial_for_the_purposes_of_abi"?

I'd say so. Are you asking for a potential libc++ use case?

Kinda. I first thought it would say whether the type is actually passed in registers. That would have been very useful for things like __is_cheap_to_copy and move_only_function. Unfortunately, trivial for the purposes of ABI isn't enough to know in these cases.