Skip to content

Conversation

patrykstefanski
Copy link

Add checks for missing and duplicated assignments in bounds-attributed groups. This model requires each mutable decl in a group to be assigned exactly once.

rdar://161608243

Add checks for missing and duplicated assignments in bounds-attributed
groups. This model requires each mutable decl in a group to be assigned
exactly once.

rdar://161608243
@patrykstefanski patrykstefanski self-assigned this Oct 18, 2025
@patrykstefanski patrykstefanski added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label Oct 18, 2025
Copy link

@ziqingluo-90 ziqingluo-90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you. Just have one nitpick.

Btw, is checking dependencies between assignments within one assignment group something we planned to do? For example,

void f(int * __counted_by(n) ptr, size_t n) {
  ptr = span.first(n).data();
  n = 42;  // this assignment should happen first
}

const llvm::SmallPtrSetImpl<const ValueDecl *> &Missing,
bool IsRelatedToDecl, ASTContext &Ctx) override {

llvm::SmallString<64> RequiredAssignments = DeclSetToStr(Required);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option could be using notes to list these objects that need to be assigned exactly once. Each Decl per note.
This way, we could make the warning message shorter and less parameterized (this benefits grep-ing warning messages), and provide more information in notes, e.g., adding " ... need to be assigned exactly once." and pointing to their source locations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants