Skip to content
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

Cherrypick for 143986251 & 145705060 #10156

Conversation

ziqingluo-90
Copy link

Original PRs:
#10129
#9971

ziqingluo-90 and others added 2 commits March 3, 2025 22:40
…ts to counted_by parameters (swiftlang#9971)

Add support of
- overloaded subscript operator of hardened view/containers, and
- calls to const member functions of 0 arguments

Now it can match patterns like:

```
std::span<char> D, S;
std::array<std::span<char>, 10> A;

memcpy(D.first(S.size()).data(), S.data(), S.size());
memcpy(D.first(A[x].size()).data(), A[x].data(), A[x].size());
```

(rdar://143986251)
…an cause infinite loops

The interop analysis substitutes formal parameters to arguments in AST
visiting.  Conceptually, the substitution should be done exactly once.
But the previous implementation never checked if the substitution has
happened.  In cases where the argument contains DREs referring to the
Decl of the corresponding formal parameter, the analysis enters an
infinite loop.  A typical example is the following.

```
void f(int * __counted_by(n) p, size_t n) {
  f(p, n);
}
```

This commit fixes the issue.

(rdar://145705060)

(cherry picked from commit 31f72f7)
@ziqingluo-90 ziqingluo-90 requested a review from a team as a code owner March 4, 2025 06:48
@ziqingluo-90
Copy link
Author

@swift-ci test

1 similar comment
@ziqingluo-90
Copy link
Author

@swift-ci test

@ziqingluo-90 ziqingluo-90 merged commit b5b6dce into swiftlang:stable/20240723 Mar 5, 2025
3 checks passed
@ziqingluo-90 ziqingluo-90 deleted the dev/ziqing/cherrypick-143986251-145705060 branch March 5, 2025 01:16
@adrian-prantl
Copy link

FYI, it would be nice to use more descriptive titles for the pull requests. Many people active in this repository cannot decode radar numbers.

@drodriguez
Copy link

Also, I think this was not run test for LLVM check-clang and might have introduced a broken test: see the last failing builds of https://ci.swift.org/view/Pull%20Requests/job/pr-apple-llvm-project-llvm-macos/ like https://ci.swift.org/view/Pull%20Requests/job/pr-apple-llvm-project-llvm-macos/599/ which fails on Clang :: SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-argument.cpp introduced here.

@ziqingluo-90
Copy link
Author

Also, I think this was not run test for LLVM check-clang and might have introduced a broken test: see the last failing builds of https://ci.swift.org/view/Pull%20Requests/job/pr-apple-llvm-project-llvm-macos/ like https://ci.swift.org/view/Pull%20Requests/job/pr-apple-llvm-project-llvm-macos/599/ which fails on Clang :: SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-argument.cpp introduced here.

Thanks for the heads-up. I have a fix here: #10175

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.

3 participants