================
@@ -49,6 +77,123 @@ enum class CountedByInvalidPointeeTypeKind {
VALID,
};
+/// Check type conflicts under the -fbounds-safety attribute model.
+/// Return std::nullopt if validation should continue with the shared checks.
+static std::optional<bool> checkBoundsAttrTypeConflictsAndMisc(
+ Sema &S, QualType Ty, SourceLocation AttrLoc,
+ const Sema::BoundsAttrFlags &Flags, StringRef AttrSpelling,
+ bool AllowRedecl, Expr *AttrArg) {
+ // The -fbounds-safety model's checks for conflicting attributes, atomic
+ // pointers and array shapes are not upstream yet.
+ return std::nullopt;
+}
+
+bool Sema::ValidateBoundsAttrTypeShape(QualType Ty, SourceLocation AttrLoc,
+ SourceRange AttrRange,
+ BoundsAttrFlags &Flags,
+ StringRef AttrSpelling, bool
AllowRedecl,
+ Expr *AttrArg, bool UpdateFlags) {
+ if (getLangOpts().hasBoundsSafetyAttributes())
+ if (std::optional<bool> Result = checkBoundsAttrTypeConflictsAndMisc(
+ *this, Ty, AttrLoc, Flags, AttrSpelling, AllowRedecl, AttrArg))
+ return *Result;
+
+ BoundsAttributedType::BoundsAttrKind Kind = getBoundsAttrKind(Flags);
+
+ // counted_by and sized_by require a pointer or array.
+ if (!Ty->isPointerType() && !Ty->isArrayType()) {
+ Diag(AttrLoc, diag::err_count_attr_not_on_ptr_or_flexible_array_member)
+ << Kind << 0;
+ return false;
+ }
+
+ // Arrays only support counted_by outside the -fbounds-safety attribute
model.
+ if (!getLangOpts().hasBoundsSafetyAttributes() && Ty->isArrayType() &&
----------------
rapidsna wrote:
Okay, let's do that.
https://github.com/llvm/llvm-project/pull/227774
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits