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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 7 10:35:57 PST 2025


================
@@ -186,4 +218,206 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes,
   return false;
 }
 
+static void EmitIncompleteCountedByPointeeNotes(Sema &S,
+                                                const CountAttributedType *CATy,
+                                                NamedDecl *IncompleteTyDecl,
+                                                bool NoteAttrLocation = true) {
+  assert(IncompleteTyDecl == nullptr || isa<TypeDecl>(IncompleteTyDecl));
+
+  if (NoteAttrLocation) {
+    // Note where the attribute is declared
+    // This is an approximation that's not quite right. This points to the
+    // the expression inside the attribute rather than the attribute itself.
+    //
+    // TODO: Implement logic to find the relevant TypeLoc for the attribute and
+    // get the SourceRange from that (#113582).
+    auto AttrSrcRange = CATy->getCountExpr()->getSourceRange();
----------------
erichkeane wrote:

https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable

Basically, if you can't tell the type from the RHS (or if the type is irrelevant, such as iterator types), we choose not to use 'auto'.

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


More information about the cfe-commits mailing list