[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:52:09 PDT 2024
================
@@ -2438,6 +2438,22 @@ bool Type::isIncompleteType(NamedDecl **Def) const {
}
}
+bool Type::isIncompletableIncompleteType() const {
+ if (!isIncompleteType())
+ return false;
+
+ // Forward declarations of structs, classes, enums, and unions could be later
+ // completed in a compilation unit by providing a type definition.
+ if (isStructureOrClassType() || isEnumeralType() || isUnionType())
+ return false;
+
+ // Other types are incompletable.
+ //
+ // E.g. `char[]` and `void`. The type is incomplete and no future
+ // type declarations can make the type complete.
+ return true;
+}
+
----------------
delcypher wrote:
This implementation is more concise (and is probably slightly faster) but it is much less readable. I could potentially fix that by using the conditions if your patch but not writing them like this.
```
if (!isCompleteType())
return false;
// Forward declarations of structs, classes, enums, and unions could be later
// completed in a compilation unit by providing a type definition.
TagDecl *TD = getAsTagDecl();
if (TD)
return false;
// Other types are incompletable.
//
// E.g. `char[]` and `void`. The type is incomplete and no future
// type declarations can make the type complete.
return true;
```
Why is the `!TD->isCompleteDefinition()` necessary? If `isIncompleteType()` returned true then that would imply that `!TD->isCompleteDefinition()` is true, right? Or am I missing something?
https://github.com/llvm/llvm-project/pull/106321
More information about the cfe-commits
mailing list