Skip to content

[clang][BoundsSafety] Re-add __sized_by/__sized_by_or_null FixIt for counted_by-on-unknown-size-pointee diagnostic #13417

Description

@delcypher

Summary

When __counted_by / __counted_by_or_null is applied to a pointer whose pointee has
unknown size (incomplete / sizeless / function / flexible-array-member), the previous
downstream diagnostic (err_bounds_safety_counted_by_without_size) offered a FixIt
suggesting __sized_by / __sized_by_or_null. Migrating to the upstream
err_counted_by_attr_pointee_unknown_size diagnostic (#13398)
dropped that FixIt, since the upstream diagnostic doesn't emit it.

Where

clang/lib/Sema/SemaBoundsSafety.cpp (ValidateBoundsAttrTypeShape) carries a FIXME:

// FIXME: We should suggest `__sized_by(_or_null)` and in the error
// diagnostic case emit a FixIt.

The corresponding FixIt checks were also removed from tests, e.g.
clang/test/BoundsSafety/Sema/counted_by_type_unknown_size.c.

Suggested fix

Re-introduce the __sized_by / __sized_by_or_null FixIt for the error case, and
restore the fixit checks in the affected tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:bounds-safetyIssue relating to the experimental -fbounds-safety feature in Clang

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions