[clang] [CIR] Implement local 'cleanup' attribute (PR #238501)
Konstantinos Parasyris via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 3 13:54:14 PST 2026
================
@@ -32,6 +32,42 @@
using namespace clang;
using namespace clang::CIRGen;
+namespace {
+/// Call the function named by a variable's `cleanup` attribute with the
+/// variable's address when it goes out of scope.
+struct CallCleanupFunction final : EHScopeStack::Cleanup {
+ const CIRGenFunctionInfo &fnInfo;
+ Address addr;
+ QualType varType;
+ CIRGenCallee callee;
+ SourceRange attrRange;
+
+ CallCleanupFunction(cir::FuncOp cleanupFn, const CIRGenFunctionInfo *info,
+ Address addr, QualType varType, const CleanupAttr *attr)
+ : fnInfo(*info), addr(addr), varType(varType),
+ callee(CIRGenCallee::forDirect(
+ cleanupFn, CIRGenCalleeInfo(attr->getFunctionDecl()))),
+ attrRange(attr->getRange()) {}
+
+ void emit(CIRGenFunction &cgf, Flags flags) override {
+ QualType argTy = fnInfo.arguments()[0];
----------------
koparasy wrote:
Is arguments not null always?
https://github.com/llvm/llvm-project/pull/238501
More information about the cfe-commits
mailing list