Skip to content

[ClangImporter] Look through bounds attributes for template matching #82076

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hnrklssn
Copy link
Contributor

@hnrklssn hnrklssn commented Jun 7, 2025

When instantiating templated functions with pointers to the templated type, the ClangImporter does not strip type sugar. This strips type sugar for bounds attributes, to make sure that they import the same regardless of whether they are parsed or not.

rdar://151041990

When instantiating templated functions with pointers to the templated
type, the ClangImporter does not strip type sugar. This strips type
sugar for bounds attributes, to make sure that they import the same
regardless of whether they are parsed or not.

rdar://151041990
@hnrklssn
Copy link
Contributor Author

hnrklssn commented Jun 7, 2025

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

hnrklssn commented Jun 7, 2025

These functions all contain this type of pattern:

if (isa<clang::PointerType>(paramTy) &&
             isa<clang::TemplateTypeParmType>(paramTy->getPointeeType())) {

My hunch is that they actually ought to use something like this (or equivalent with getAsAdjusted):

if (paramTy->getAs<clang::PointerType>() &&
             paramTy->getAs<clang::PointerType>()->getPointeeType()->getAs<clang::TemplateTypeParmType>() {

But I don't want to introduce unnecessary risk this late in the release cycle, so I elected to only strip the type sugar we know we need to strip, in case it affects other things. Especially since it seems like this template logic is all a bit of a hack anyways that eventually needs to be replaced; e.g. this doesn't seem to get imported:

template <class T>
void foo(T **p);

CC @egorzhdan in case you have more context

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.

1 participant