[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Fri May 3 13:57:52 PDT 2024


================
@@ -631,6 +631,18 @@ bool Type::isStructureType() const {
   return false;
 }
 
+bool Type::isStructureTypeWithFlexibleArrayMember() const {
+  const auto *RT = getAs<RecordType>();
+  if (!RT)
+    return false;
+  const auto *Decl = RT->getDecl();
+  if (!Decl->isStruct())
+    return false;
+  if (!Decl->hasFlexibleArrayMember())
+    return false;
+  return true;
----------------
bwendling wrote:

Maybe? The `isFlexibleArrayMemberLike` methods are more in depth analysis of the struct and checks against the `-fstrict-flex-arrays=` flag, so it's a more expensive call. But if the `hasFlexibleArrayMember` is always set "correctly," then it's probably sufficient.

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


More information about the cfe-commits mailing list