[clang] [Clang][counted_by] Honor counted_by in __bdos on direct struct access (PR #201161)
Kees Cook via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 2 18:06:20 PDT 2026
================
@@ -16276,13 +16276,44 @@ static bool determineEndOffset(EvalInfo &Info, SourceLocation ExprLoc,
return true;
}
+/// Determine whether @p E designates a flexible array member annotated with
+/// 'counted_by'. This mirrors the Expr-walking that CGBuiltin's
+/// StructFieldAccess / emitCountedByMemberSize do to decide whether to emit
----------------
kees wrote:
Hm, on further investigation, I needed to match GCC's behavior here. I need to deliberately treat '&af.fam' (address-of-array) as *not* a `counted_by` access since '&af.fam' designates the array object as a whole and gets the layout-derived size, while 'af.fam' (decayed) and '&af.fam[idx]' designate element-pointers and get the count-based size.
I will move the visitor code out to get shared; I wasn't sure how to do that, but I think putting it in Expr.cpp/h works?
https://github.com/llvm/llvm-project/pull/201161
More information about the cfe-commits
mailing list