================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to