diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3393,9 +3393,17 @@ return NamedReturnInfo(); } + auto isAlignmentDependent = [](const VarDecl *VD) { + for (auto *I : VD->specific_attrs()) + if (I->isAlignmentDependent()) + return true; + return false; + }; + // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. if (!VDType->isDependentType() && VD->hasAttr() && + !isAlignmentDependent(VD) && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible;