[clang] [Clang] add user-level sizeless attribute (PR #71894)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 9 21:59:38 PST 2023
================
@@ -2400,7 +2402,66 @@ bool Type::isWebAssemblyTableType() const {
return false;
}
-bool Type::isSizelessType() const { return isSizelessBuiltinType(); }
+bool Type::isSizelessType() const {
+ // Check if this type or any of its constituents are sizeless, due to
+ // being a builtin type or individually having the user attribute.
+ // As structs can be recursive, we iterate through without repeats.
+ SmallVector<const Type *, 1> todo = {this};
+ llvm::SmallPtrSet<const Type *, 1> done;
+
+ while (todo.size()) {
+ auto current = todo.pop_back_val();
+ if (done.count(current))
+ continue;
+ done.insert(current);
+
+ // If either this is a known sizeless type from being a builtin
+ // or as marked by the user, this is a sizeless type.
+ if (current->isSizelessBuiltinType())
+ return true;
+ if (current->hasAttr(attr::SizelessType))
+ return true;
+
+ // Otherwise return true if any inner types are sizeless.
+ switch (current->CanonicalType->getTypeClass()) {
+ default:
+ break;
+ case Record: {
+ // A struct with sizeless types is itself sizeless.
+ RecordDecl *Rec = cast<RecordType>(current->CanonicalType)->getDecl();
----------------
tbaederr wrote:
```suggestion
const auto *Rec = cast<RecordType>(current->CanonicalType)->getDecl();
```
https://github.com/llvm/llvm-project/pull/71894
More information about the cfe-commits
mailing list