[clang] [Clang][counted_by] Honor counted_by in __bdos on direct struct access (PR #201161)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 3 13:55:00 PDT 2026
================
@@ -16309,6 +16315,23 @@ tryEvaluateBuiltinObjectSize(const Expr *E, unsigned Type, EvalInfo &Info) {
if (LVal.getLValueOffset().isNegative())
return 0;
+ // For __builtin_dynamic_object_size on a counted_by-annotated flexible
+ // array member, defer to IR generation (emitCountedBySize in CGBuiltin):
+ // its runtime computation uses the live 'count' field and is more accurate
+ // than the layout/initializer-derived size we'd produce here. Use the same
+ // findStructFieldAccess form-recognition CGBuiltin does, so we refuse to
+ // fold on exactly the shapes that path handles (and, importantly, *not*
+ // on '&af.fam' which designates the array-as-a-whole and stays on the
+ // layout-derived path to match GCC). Checked after the negative-offset
+ // early return above so that obviously out-of-bounds operands still fold
+ // to 0, preserving existing behavior.
+ if (IsDynamic) {
----------------
efriedma-quic wrote:
Please also implement this for bytecode interpreter (evaluateBuiltinObjectSize() in clang/lib/AST/ByteCode/InterpBuiltin.cpp), to maintain parity.
https://github.com/llvm/llvm-project/pull/201161
More information about the cfe-commits
mailing list