[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 7 09:43:29 PST 2025
================
@@ -2068,13 +2068,55 @@ class Sema final : public SemaBase {
bool CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes,
bool OrNull);
+ /// Perform Bounds Safety Semantic checks for assigning to a `__counted_by` or
+ /// `__counted_by_or_null` pointer type \param LHSTy.
+ ///
+ /// \param LHSTy The type being assigned to. Checks will only be performed if
+ /// the type is a `counted_by` or `counted_by_or_null ` pointer.
+ /// \param RHSExpr The expression being assigned from.
+ /// \param Action The type assignment being performed
+ /// \param Loc The SourceLocation to use for error diagnostics
+ /// \param ComputeAssignee If provided this function will be called before
+ /// emitting a diagnostic. The function should return the name of
+ /// entity being assigned to or an empty string if this cannot be
+ /// determined.
+ ///
+ /// \returns True iff no diagnostic where emitted, false otherwise.
+ bool BoundsSafetyCheckAssignmentToCountAttrPtr(
+ QualType LHSTy, Expr *RHSExpr, AssignmentAction Action,
+ SourceLocation Loc,
+ llvm::function_ref<std::string()> ComputeAssignee = nullptr);
+
+ /// Perform Bounds Safety Semantic checks for initializing a Bounds Safety
+ /// pointer.
+ ///
+ /// \param Entity The entity being initialized
+ /// \param Kind The kind of initialization being performed
+ /// \param Action The type assignment being performed
+ /// \param LHSTy The type being assigned to. Checks will only be performed if
+ /// the type is a `counted_by` or `counted_by_or_null ` pointer.
+ /// \param RHSExpr The expression being used for initialization.
+ ///
+ /// \returns True iff no diagnostic where emitted, false otherwise.
+ bool BoundsSafetyCheckInitialization(const InitializedEntity &Entity,
+ const InitializationKind &Kind,
+ AssignmentAction Action,
+ QualType LHSType, Expr *RHSExpr);
+
+ /// Perform Bounds Safety semantic checks for uses of invalid uses counted_by
+ /// or counted_by_or_null pointers in \param E.
+ ///
+ /// \param E the expression to check
+ ///
+ /// \returns True iff no diagnostic where emitted, false otherwise.
+ bool BoundsSafetyCheckUseOfCountAttrPtr(Expr *E);
----------------
AaronBallman wrote:
```suggestion
bool BoundsSafetyCheckUseOfCountAttrPtr(const Expr *E);
```
Can this be made `const`? I would expect a function named "check" doesn't need to mutate the expression.
https://github.com/llvm/llvm-project/pull/106321
More information about the cfe-commits
mailing list