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

[SR-2529] Keep __attribute__((noescape)) when importing Clang types #45134

Open
jtbandes opened this issue Aug 31, 2016 · 0 comments
Open

[SR-2529] Keep __attribute__((noescape)) when importing Clang types #45134

jtbandes opened this issue Aug 31, 2016 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@jtbandes
Copy link
Collaborator

Previous ID SR-2529
Radar None
Original Reporter @jtbandes
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, ClangImporter
Assignee None
Priority Medium

md5: 6d1ad1f08685b164784460a549014381

relates to:

  • SR-2520 Type alias is lost when applying @escaping-ness
  • SR-2406 Print attribute((noescape)) in the generated header

Issue Description:

When I went to implement SR-2406, I discovered that function types imported from Clang (including function pointers, block pointers, and typedefs thereof) are imported with no regard for __attribute__((noescape)). The attribute should be preserved in the imported type's extInfo.

Here's a summary of how the flow seems to happen right now, from what I saw:

  • To import a typedef decls, the importer just calls getUnderlyingType() and imports that type:
    clang::QualType ClangType = Decl->getUnderlyingType();
    SwiftType = Impl.importType(ClangType,
    ImportTypeKind::Typedef,
    isInSystemModule(DC),
    ClangType->isBlockPointerType(),
    OTK_Optional);
  • To import a block pointer type, it just imports the underlying function pointer:
    Type pointeeType = Impl.importType(type->getPointeeType(),
    ImportTypeKind::Abstract,
    AllowNSUIntegerAsInt,
    CanFullyBridgeTypes);
  • Then, here's where parameters of function pointer types are imported:
    for (auto param = type->param_type_begin(),
    paramEnd = type->param_type_end();
    param != paramEnd; ++param) {
    auto swiftParamTy = Impl.importType(*param, ImportTypeKind::Parameter,
    AllowNSUIntegerAsInt,
    CanFullyBridgeTypes,
    OTK_Optional);
    if (!swiftParamTy)
    return Type();
    // FIXME: If we were walking TypeLocs, we could actually get parameter
    // names. The probably doesn't matter outside of a FuncDecl, which
    // we'll have to special-case, but it's an interesting bit of data loss.
    params.push_back(swiftParamTy);
    }
  • At that point, it seems like the noescape information is not available. Other places which use it are checking hasAttr<clang::NoEscapeAttr>() on a param decl, but this only has access to the param types.
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant