[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

Dan Liew via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 28 11:39:34 PDT 2024


================
@@ -2440,6 +2440,26 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     return !isFunctionType();
   }
 
+  /// \returns True if the type is incomplete and it is also a type that
+  /// cannot be completed by a later type definition.
+  ///
+  /// E.g. For `void` this is true but for `struct ForwardDecl;` this is false
+  /// because a definition for `ForwardDecl` could be provided later on in the
+  /// translation unit.
+  ///
+  /// Note even for types that this function returns true for it is still
+  /// possible for the declarations that contain this type to later have a
+  /// complete type in a translation unit. E.g.:
+  ///
+  /// \code{.c}
+  /// // This decl has type 'char[]' which is incomplete and cannot be later
+  /// // completed by another by another type declaration.
+  /// extern char foo[];
+  /// // This decl how has complete type 'char[5]'.
+  /// char foo[5]; // foo has a complete type
+  /// \endcode
+  bool isIncompletableIncompleteType() const;
----------------
delcypher wrote:

This is a method and not inlined at the use site for multiple reasons:

1. This method is **also** called from a different location in our internal fork of Clang. The reason for this is because the Sema code for handling the `counted_by` in upstream Clang and our internal fork are completely different. We plan to eventually merge the two different Sema codes and open source it but won't be doing that until upstream Clang allows `counted_by` in all the contexts that it is allowed in our internal fork.

2. "isIncompletableIncompleteType" is a property of the type so the natural place for this code to live is in the `Type` class.

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


More information about the cfe-commits mailing list