[clang] [clang] Handle trivial_abi attribute for Microsoft ABI. (PR #88857)

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 29 15:53:34 PDT 2024


================
@@ -1105,6 +1105,11 @@ bool MicrosoftCXXABI::hasMostDerivedReturn(GlobalDecl GD) const {
 
 static bool isTrivialForMSVC(const CXXRecordDecl *RD, QualType Ty,
                              CodeGenModule &CGM) {
+  // If the record is marked with the trivial_abi attribute, we don't
+  // have to conform to the standard MSVC ABI.
+  if (RD->hasAttr<TrivialABIAttr>())
----------------
rnk wrote:

The pseudo code version is something like:
  bool containsTrivialAbiSubobject(CXXRecordDecl *RD) {
    if (RD->hasAttr<TrivialABIAttr>()) return true;
    for (auto B : RD->bases()) {
      if (containsTrivialAbiSubobject(B->getAsCXXRecordDecl()))
        return true;
    }
    for (auto F : RD->fields()) {
      const CXXRecordDecl* FRD = F->getType()->getAsCXXRecordDecl();
      if (FRD && containsTrivialAbiSubobject(FRD))
        return true;
    }    
    return false;
  }

A bit of a gross inefficient DFS, with some CXXBaseSpecifier details omitted. It might also be worth tracking Visited records to handle fields of the same record type without recursing over all subobjects again.

https://github.com/llvm/llvm-project/pull/88857


More information about the cfe-commits mailing list