================ @@ -1381,21 +1405,58 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB, AttributeList AL = NewInnerCB->getAttributes(); for (unsigned I = 0, E = InnerCB->arg_size(); I < E; ++I) { // Check if the underlying value for the parameter is an argument. - const Value *UnderlyingV = - getUnderlyingObject(InnerCB->getArgOperand(I)); - const Argument *Arg = dyn_cast<Argument>(UnderlyingV); - if (!Arg) - continue; + const Argument *Arg = dyn_cast<Argument>(InnerCB->getArgOperand(I)); + unsigned ArgNo; + if (Arg) { + ArgNo = Arg->getArgNo(); + // For dereferenceable, dereferenceable_or_null, align, etc... + // we don't want to propagate if the existing param has the same + // attribute with "better" constraints. So, only remove from the + // existing AL if the region of the existing param is smaller than + // what we can propagate. AttributeList's merge API honours the + // already existing attribute value so we choose the "better" + // attribute by removing if the existing one is worse. + if (AL.getParamDereferenceableBytes(I) < + ValidExactParamAttrs[ArgNo].getDereferenceableBytes()) + AL = + AL.removeParamAttribute(Context, I, Attribute::Dereferenceable); + if (AL.getParamDereferenceableOrNullBytes(I) < + ValidExactParamAttrs[ArgNo].getDereferenceableOrNullBytes()) + AL = + AL.removeParamAttribute(Context, I, Attribute::Dereferenceable); + if (AL.getParamAlignment(I).valueOrOne() < + ValidExactParamAttrs[ArgNo].getAlignment().valueOrOne()) + AL = AL.removeParamAttribute(Context, I, Attribute::Alignment); + + auto ExistingRange = AL.getParamRange(I); + AL = AL.addParamAttributes(Context, I, ValidExactParamAttrs[ArgNo]); + + // For range we use the intersection. + if (ExistingRange.has_value()) { + if (auto NewRange = ValidExactParamAttrs[ArgNo].getRange()) { + auto CombinedRange = ExistingRange->intersectWith(*NewRange); ---------------- nikic wrote:
auto -> ConstantRange https://github.com/llvm/llvm-project/pull/91101 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits