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

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 28 05:17:04 PDT 2024


================
@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
----------------
Sirraide wrote:

This entire function seems like a very bad idea to me: I don’t think Sema should ever have to fiddle with source locations in terms of character offsets or anything like that. This seems extremely brittle in case a user writes something like e.g. `__counted_by (  count  )` or uses macros (which you mention in a comment doesn’t work).

I think you should be able to get a hold of the corresponding `CountAttributedTypeLoc` somehow (e.g. via the `FieldDecl`, which has a `TypeSourceInfo*`, which you should be able to get the type loc from; you might have to do this a few levels up the call stack before we ever get here) and then use its source location and range.

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


More information about the cfe-commits mailing list