[clang] [CIR] Add pass_object_size hidden parameter support (PR #191482)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 15 12:10:24 PDT 2026
================
@@ -2581,11 +2581,37 @@ mlir::Value CIRGenFunction::emitVAArg(VAArgExpr *ve) {
return cir::VAArgOp::create(builder, loc, type, vaList);
}
+/// Checks if using the result of __builtin_object_size(p, @p from) in place of
+/// __builtin_object_size(p, @p to) is correct.
+///
+/// type=0 is the maximum object size; compatible with type=1 (maximum of the
+/// remaining bytes, which is always <= total size). type=3 is the minimum
+/// remaining bytes; compatible with type=2 (minimum object size).
+static bool areBOSTypesCompatible(int from, int to) {
+ return from == to || (from == 0 && to == 1) || (from == 3 && to == 2);
+}
+
mlir::Value CIRGenFunction::emitBuiltinObjectSize(const Expr *e, unsigned type,
cir::IntType resType,
mlir::Value emittedE,
bool isDynamic) {
- assert(!cir::MissingFeatures::opCallImplicitObjectSizeArgs());
+ // If this is a pass_object_size parameter, load the implicit size arg.
+ if (auto *d = dyn_cast<DeclRefExpr>(e->IgnoreParenImpCasts())) {
+ auto *param = dyn_cast<ParmVarDecl>(d->getDecl());
+ auto *ps = d->getDecl()->getAttr<PassObjectSizeAttr>();
+ if (param && ps && areBOSTypesCompatible(ps->getType(), type)) {
+ auto iter = sizeArguments.find(param);
+ assert(iter != sizeArguments.end());
+
+ const ImplicitParamDecl *sizeDecl = iter->second;
+ auto dIter = localDeclMap.find(sizeDecl);
----------------
adams381 wrote:
Done.
https://github.com/llvm/llvm-project/pull/191482
More information about the cfe-commits
mailing list