[PATCH] D50119: Compiler support for P1144R0 "__is_trivially_relocatable(T)"

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 16 22:44:58 PST 2018


Quuxplusone added inline comments.


================
Comment at: include/clang/AST/DeclCXX.h:482
+    /// and a defaulted destructor.
+    unsigned IsNaturallyTriviallyRelocatable : 1;
+
----------------
erichkeane wrote:
> Quuxplusone wrote:
> > erichkeane wrote:
> > > Typically we'd have this calculated when requested rather than stored. I suspect using a bit for something like this isn't going to be terribly acceptable.
> > You know better than I do; but I'm also not sure how to calculate it on request.
> You'll end up just recursively walking the CXXRecordDecl upon application of the type trait, and need to check the things that make it NOT trivially relocatable.
> 
> I think it also extensively simplifies this patch, since none of the CXXRecordDecl functions are required (just the type-trait emission).
@erichkeane: I tried to follow this advice tonight, but I can't find any other type trait in Clang that is implemented the way you described. Every other type trait seems to be implemented in exactly the way I did it: isPolymorphic, isAbstract, isStandardLayoutType, isTrivialType, isAggregateType, hasTrivialDefaultConstructor... they all seem to occupy a bit in CXXRecordDecl. None of them seem to be computed by walking the `fields()` of a CXXRecordDecl on the fly — and that makes sense to me, because that would be an arbitrarily slow operation, whereas keeping the bit is O(1) no matter how many times the result is asked for.
If calculating traits on request is "typical," can you point me to somewhere in Clang where it happens, so that I can try to copy how they do it?


Repository:
  rC Clang

https://reviews.llvm.org/D50119





More information about the cfe-commits mailing list