================
@@ -539,6 +539,9 @@ class TrivialFunctionAnalysisVisitor
if (R->hasDefinition() && R->hasTrivialDestructor())
----------------
steakhal wrote:
Hey claude: The hasTrivialDestructor could return true even if the class has
non-trivially destructible fields or such fields in some transitive base class?
> Based on the exploration, the answer is no - hasTrivialDestructor() does
> correctly account for fields and transitive base classes.
>
> Here's how it works:
>
> hasTrivialDestructor() just reads a pre-computed bit flag
> (clang/include/clang/AST/DeclCXX.h:1370):
>
> bool hasTrivialDestructor() const {
> return data().HasTrivialSpecialMembers & SMF_Destructor;
> }
>
> The flag starts as "all trivial" (SMF_All) when the DefinitionData is
> initialized (clang/lib/AST/DeclCXX.cpp:76), and is cleared during semantic
> analysis when
> non-trivial components are discovered:
>
> - Direct base classes (DeclCXX.cpp:410):
> if (!BaseClassDecl->hasTrivialDestructor())
> data().HasTrivialSpecialMembers &= ~SMF_Destructor;
> - Member fields (DeclCXX.cpp:1308):
> if (!FieldRec->hasTrivialDestructor())
> data().HasTrivialSpecialMembers &= ~SMF_Destructor;
>
> The propagation is recursive by construction - each class's flag is
> computed from its own components, which themselves had their flags computed
> from their own
> components. So if A has a non-trivial destructor, B : A will have the bit
> cleared, and C with a B member will also have the bit cleared.
https://github.com/llvm/llvm-project/pull/183711
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits