Skip to content

[Safe Buffers][BoundsSafety] Initial bounds attributes support for FAMs #10254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2025

Conversation

ziqingluo-90
Copy link

Enable parsing and syntax-level checking of bound attributes in flexible array member declarations.

(rdar://139293326)

@ziqingluo-90
Copy link
Author

@swift-ci test llvm

Enable parsing and syntax-level checking of bound attributes in
flexible array member declarations.

(rdar://139293326)
Copy link

@hnrklssn hnrklssn left a comment

Choose a reason for hiding this comment

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

Looks good! Could you add these test cases?

class FAM_THIS_ARROW_ARROW {
  T *tp;
  int fam[__counted_by(this->tp->count)]; // expected-error{{arrow notation not allowed for struct member in count parameter}}
};

class FAM_THIS_ARROW_DOT {
  T *t;
  int fam[__counted_by(this->t.count)]; // dot-expressions in counted-by is ok for FAMs
};

class FAM_ARITHMETIC {
  int count;
  int offset;
  int fam[__counted_by(count - offset)]; //  ok
};

class FAM_THIS_PTR_ARITHMETIC {
  int count;
  int fam[__counted_by((this + 1)->count]; //  error
};

class FAM_THIS_PTR_ARITHMETIC {
  int count;
  int fam[__counted_by(*this.count]; //  error
};

@@ -10904,7 +10911,7 @@ class CountArgChecker : public TreeTransform<CountArgChecker> {
VD->getType(), VK_LValue);
return DRE;
}

BOUNDS_SAFETY_CHECK_FAM_OR_ARROW_FOR_MEMBER:

Choose a reason for hiding this comment

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

Oh an do we maybe want to extract this into a lambda or helper function instead of a goto label?

Copy link

@hnrklssn hnrklssn left a comment

Choose a reason for hiding this comment

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

LGTM

@ziqingluo-90 ziqingluo-90 merged commit 963afa8 into swiftlang:next Mar 18, 2025
@ziqingluo-90 ziqingluo-90 deleted the eng/PR-139293326 branch March 18, 2025 16:36
ziqingluo-90 added a commit that referenced this pull request Mar 18, 2025
…Ms (#10254)

Enable parsing and syntax-level checking of bound attributes in
flexible array member declarations.

(rdar://139293326)
ziqingluo-90 added a commit that referenced this pull request Mar 20, 2025
…Ms (#10254) (#10285)

Enable parsing and syntax-level checking of bound attributes in
flexible array member declarations.

(rdar://139293326)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants