Skip to content

Conversation

@j-hui
Copy link
Contributor

@j-hui j-hui commented May 9, 2025

Explanation: This patch adds a check to ensure we only attach the Swiftify macro to __counted_by and __sized_by expressions that are also syntactically valid in Swift.

Issue: rdar://150956352
Risk: low
Testing: added tests
Original PRs: #81395
Reviewer: @hnrklssn

@j-hui j-hui requested a review from a team as a code owner May 9, 2025 02:44
@j-hui
Copy link
Contributor Author

j-hui commented May 9, 2025

@swift-ci please test

__counted_by (and __sized_by) expressions can have arbitrary C syntax
in them, such as:

    void foo(int * __counted_by(*len) p, int *len);

When @_SwififyImport tries to generate Swift code for this, the
expression `*len` leads to a syntax error, since it isn't valid Swift.

This patch adds a check to ensure we only attach the Swiftify macro to
__counted_by expressions that are also syntactically valid in Swift.

rdar://150956352
(cherry picked from commit e5b1f4a)
@j-hui j-hui force-pushed the cherry-pick-6.2/dont-swiftify-invalid-expr branch from b290743 to 8be78da Compare May 9, 2025 04:14
@j-hui
Copy link
Contributor Author

j-hui commented May 9, 2025

@swift-ci please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

The naming issue isn't a critical one, we can deal with it on main.

};
} // namespace

static bool SwiftifiableCAT(const clang::CountAttributedType *CAT) {
Copy link
Member

Choose a reason for hiding this comment

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

Could we get some more descriptive names here? I see what "CAT" is an acronym for here, but it isn't quite discoverable. CountedByExpressionValidator, perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a fair point! I'll address that in my PR on main.

} // namespace

namespace {
/// Look for any side effects within a Stmt.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I just realized that I forgot to remove this stray comment that got copied over when I was setting up the StmtVisitor boilerplate 😮‍💨

@j-hui j-hui merged commit 97c5fbf into swiftlang:release/6.2 May 9, 2025
5 checks passed
@j-hui j-hui deleted the cherry-pick-6.2/dont-swiftify-invalid-expr branch May 9, 2025 18:55
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