[clang] [CIR] Add pass_object_size hidden parameter support (PR #191482)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 28 09:20:45 PDT 2026
================
@@ -2625,7 +2585,44 @@ 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.
+ //
+ // BOS type compatibility: a pass_object_size annotation with one type can
+ // satisfy a __builtin_object_size query with a different type when the
+ // annotated type is a safe approximation. Type 0 (max, whole object) is
+ // an overestimate for type 1 (max, closest surrounding subobject), and
+ // type 3 (min, closest surrounding subobject) is an underestimate for
+ // type 2 (min, whole object).
+ enum BOSType {
+ MaxWholeObject = 0,
+ MaxSubobject = 1,
+ MinWholeObject = 2,
+ MinSubobject = 3,
+ };
+ if (auto *d = dyn_cast<DeclRefExpr>(e->IgnoreParenImpCasts())) {
+ auto *param = dyn_cast<ParmVarDecl>(d->getDecl());
+ auto *ps = d->getDecl()->getAttr<PassObjectSizeAttr>();
+ if (param && ps) {
+ int from = ps->getType();
+ bool compatible =
+ from == static_cast<int>(type) ||
+ (from == MaxWholeObject && type == MaxSubobject) ||
+ (from == MinSubobject && type == MinWholeObject);
+ if (compatible) {
+ auto sizeIter = sizeArguments.find(param);
----------------
adams381 wrote:
Done -- changed `mlir::Value ptr` to `auto ptr` (both branches of the ternary are `mlir::Value`, type is obvious) and dropped unnecessary `const` on `bool min`.
https://github.com/llvm/llvm-project/pull/191482
More information about the cfe-commits
mailing list