================ @@ -3922,6 +3922,42 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S, return true; } + const auto OldFX = Old->getFunctionEffects(); + const auto NewFX = New->getFunctionEffects(); + if (OldFX != NewFX) { + const auto Diffs = FunctionEffectSet::differences(OldFX, NewFX); + for (const auto &Item : Diffs) { + const FunctionEffect *Effect = Item.first; + const bool Adding = Item.second; + if (Effect->diagnoseRedeclaration(Adding, *Old, OldFX, *New, NewFX)) { + Diag(New->getLocation(), + diag::warn_mismatched_func_effect_redeclaration) + << Effect->name(); + Diag(Old->getLocation(), diag::note_previous_declaration); + } + } + + const auto MergedFX = OldFX | NewFX; + + // Having diagnosed any problems, prevent further errors by applying the + // merged set of effects to both declarations. + auto applyMergedFX = [&](FunctionDecl *FD) { + const auto *FPT = FD->getType()->getAs<FunctionProtoType>(); + FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); + EPI.FunctionEffects = MergedFX; + QualType ModQT = Context.getFunctionType(FD->getReturnType(), + FPT->getParamTypes(), EPI); + + FD->setType(ModQT); + }; + + applyMergedFX(Old); + applyMergedFX(New); + + OldQType = Old->getType(); ---------------- Sirraide wrote:
Sounds good to me. https://github.com/llvm/llvm-project/pull/84983 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits