[llvm] [IR][DSE] Support non-malloc functions in malloc+memset->calloc fold (PR #138299)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat May 10 13:05:58 PDT 2025
================
@@ -2377,6 +2377,33 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
CheckFailed("'allockind()' can't be both zeroed and uninitialized");
}
+ if (Attribute A = Attrs.getFnAttr("alloc-variant-zeroed"); A.isValid()) {
+ StringRef S = A.getValueAsString();
+ Check(!S.empty(), "'alloc-variant-zeroed' must not be empty");
+ if (const Function *F = dyn_cast<Function>(V)) {
+ if (Function *Variant = F->getParent()->getFunction(S)) {
+ Attribute Family = Attrs.getFnAttr("alloc-family");
+ Attribute VariantFamily = Variant->getFnAttribute("alloc-family");
+ if (Family.isValid())
+ Check(VariantFamily.isValid() && VariantFamily.getValueAsString() ==
+ Family.getValueAsString(),
+ "'alloc-variant-zeroed' must name a function belonging to the "
+ "same 'alloc-family'");
+
+ Check(
+ Variant->hasFnAttribute(Attribute::AllocKind) &&
+ (Variant->getFnAttribute(Attribute::AllocKind).getAllocKind() &
+ AllocFnKind::Zeroed) != AllocFnKind::Unknown,
+ "'alloc-variant-zeroed' must name a function with "
+ "'allockind(\"zeroed\")'");
+
+ Check(F->getFunctionType() == Variant->getFunctionType(),
----------------
nikic wrote:
```suggestion
Check(FT == Variant->getFunctionType(),
```
And then you can drop the `if (const Function *F = dyn_cast<Function>(V))` bit?
https://github.com/llvm/llvm-project/pull/138299
More information about the llvm-commits
mailing list