[llvm-branch-commits] [clang] [LifetimeSafety] Support allocating/freeing builtins (PR #213443)
Balázs Benics via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Nov 6 07:56:02 PST 2026
================
@@ -1138,22 +1138,35 @@ void FactsGenerator::handleLifetimeCaptureBy(const FunctionDecl *FD,
void FactsGenerator::handleFreeingCall(const Expr *Call, const FunctionDecl *FD,
ArrayRef<const Expr *> Args) {
+ if (!isFreeingFunction(*FD))
+ return;
+ auto InvalidateArg = [&](unsigned ArgIndex) {
+ assert(ArgIndex < Args.size() && "Arg index should be in bounds");
+
+ OriginList *ArgList = getOriginsList(*Args[ArgIndex]);
+ if (!ArgList)
+ return;
+ CurrentBlockFacts.push_back(FactMgr.createFact<InvalidateOriginFact>(
+ ArgList->getOuterOriginID(), Call));
+ };
+
+ bool HasOwnershipTakesAttr = false;
for (const OwnershipAttr *Attr : FD->specific_attrs<OwnershipAttr>()) {
if (Attr->getOwnKind() != OwnershipAttr::Takes)
continue;
+ HasOwnershipTakesAttr = true;
for (const ParamIdx &Idx : Attr->args()) {
// Attribute indices count implicit 'this', but constructor Args omits it:
// the first explicit parameter (2) maps to Args[0], not Args[1].
- unsigned ArgIndex = Idx.getLLVMIndex() - isa<CXXConstructorDecl>(FD);
- if (ArgIndex >= Args.size())
- continue;
- OriginList *ArgList = getOriginsList(*Args[ArgIndex]);
- if (!ArgList)
- continue;
- CurrentBlockFacts.push_back(FactMgr.createFact<InvalidateOriginFact>(
- ArgList->getOuterOriginID(), Call));
+ InvalidateArg(Idx.getLLVMIndex() - isa<CXXConstructorDecl>(FD));
----------------
steakhal wrote:
In the prev patch we discussed that `Idx.getLLVMIndex()` might be zero. Thus this expression might wrap on valid code.
Inside the lambda you assert that the index is valid, thus abort on wrap.
Is this safe?
https://github.com/llvm/llvm-project/pull/213443
More information about the llvm-branch-commits
mailing list