[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
Mon Jun 8 17:49:19 PDT 2026


================
@@ -2457,6 +2457,16 @@ UnsignedOrNone evaluateBuiltinObjectSize(const ASTContext &ASTCtx,
       if (Kind == 1)
         return std::nullopt;
     }
+    // For Type=1, defer to the runtime path on a true incomplete-array
+    // flexible array member (e.g. 'char fam[]') even when the base is a
+    // concrete local/global. Without this, the bytecode interpreter would
+    // happily fold &af.fam to 'NumElems * elemSize = 0' below; the default
+    // const-evaluator avoids the same trap, and CGBuiltin emits
+    // @llvm.objectsize for the correct layout-derived answer (matching
+    // GCC's __bos/__bdos on '&af.fam').
+    if (Kind == 1 && pointsToLastObject(Ptr) && Ptr.getFieldDesc()->isArray() &&
----------------
kees wrote:

Yeah, I got it fixed up. I need to block PR pushes if git-clang-format trips. :P

https://github.com/llvm/llvm-project/pull/201161


More information about the cfe-commits mailing list