[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)
Dan Liew via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 18 09:41:56 PDT 2024
================
@@ -8697,9 +8708,10 @@ static bool CheckCountedByAttrOnField(
InvalidTypeKind = CountedByInvalidPointeeTypeKind::FLEXIBLE_ARRAY_MEMBER;
}
- if (InvalidTypeKind != CountedByInvalidPointeeTypeKind::VALID) {
+ if (InvalidTypeKind != CountedByInvalidPointeeTypeKind::VALID &&
+ !CountInBytes) {
----------------
delcypher wrote:
> I think that is a reasonable restriction to add in -fbounds-safety, but
I think we should avoid bifurcating the semantics of `sized_by` based on the `-fbounds-safety` flag where possible. The more differences we have the more pain we are going to cause during adoption. Consider a project that first annotates their headers with `sized_by` but doesn't pass `-fbounds-safety`. They will get one set of semantics, then a project that consumes that header file builds with `-fbounds-safety`. That project is built with different semantics. If the semantics differ enough its possible that the header file will build fine without `-fbound-safety` but fail to build with it.
> but for simply saying "this is the size", is it really an issue?
The issue for me is that it doesn't really make sense to have pointers to "sizeless types" (not to be confused with "incomplete types") or to "function types" in the first place and so to me that implies adding `sized_by` to those pointers doesn't make sense either.
I don't want to delay this PR for too long so if you think my ask is unreasonable we can file an issue and get back to it.
Ultimately I think @rapidsna should make the call on this issue.
https://github.com/llvm/llvm-project/pull/93231
More information about the cfe-commits
mailing list