Author: Bill Wendling Date: 2024-01-10T15:36:33-08:00 New Revision: 4a3fb9ce27dda17e97341f28005a28836c909cfc
URL: https://github.com/llvm/llvm-project/commit/4a3fb9ce27dda17e97341f28005a28836c909cfc DIFF: https://github.com/llvm/llvm-project/commit/4a3fb9ce27dda17e97341f28005a28836c909cfc.diff LOG: [Clang] Update 'counted_by' documentation Describe a limitation of the 'counted_by' attribute when used in unions. Also fix a errant typo. Added: Modified: clang/include/clang/Basic/AttrDocs.td clang/lib/CodeGen/CGBuiltin.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 2e8d7752c9751e..c025acd3b106a3 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7825,5 +7825,33 @@ requirement: --p->count; p->array[index] = val; } + +Flexible array members, with the ``counted_by`` attribute, in unions are +supported with one limitation. If multiple flexible array members have the +``counted_by`` attribute, ``__builtin_dynamic_object_size`` won't be able to +calculate the object's size. For instance, in this example: + +.. code-block:: c + + struct union_of_fams { + int flags; + union { + unsigned long normal_field; + struct { + int count1; + int arr1[] __counted_by(count1); + }; + struct { + signed char count2; + int arr2[] __counted_by(count2); + }; + }; + }; + + size_t get_size(struct union_of_fams *p) { + return __builtin_dynamic_object_size(p, 1); + } + +a call to ``get_size`` will return ``-1``. }]; } diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 998fcc3af58175..b5aee3eaa53c5d 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -955,7 +955,7 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, // }; // }; // - // We don't konw which 'count' to use in this scenario: + // We don't know which 'count' to use in this scenario: // // size_t get_size(struct union_of_fams *p) { // return __builtin_dynamic_object_size(p, 1); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits