Skip to content

[ConstraintSystem] Adjust isArgumentOfImportedDecl to handle synthesized declarations #83620

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 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/ClangImporter/SwiftDeclSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ SwiftDeclSynthesizer::createDefaultConstructor(NominalTypeDecl *structDecl) {
// Mark the constructor transparent so that we inline it away completely.
constructor->getAttrs().add(new (context) TransparentAttr(/*implicit*/ true));

constructor->setSynthesized();

constructor->setBodySynthesizer(synthesizeStructDefaultConstructorBody,
structDecl);

Expand Down Expand Up @@ -652,6 +654,8 @@ ConstructorDecl *SwiftDeclSynthesizer::createValueConstructor(
// Make the constructor transparent so we inline it away completely.
constructor->getAttrs().add(new (context) TransparentAttr(/*implicit*/ true));

constructor->setSynthesized();

if (wantBody) {
auto memberMemory =
context.AllocateUninitialized<uintptr_t>(members.size() + 1);
Expand Down Expand Up @@ -1294,6 +1298,7 @@ SwiftDeclSynthesizer::makeEnumRawValueConstructor(EnumDecl *enumDecl) {
/*ThrownType=*/TypeLoc(), paramPL,
/*GenericParams=*/nullptr, enumDecl);
ctorDecl->setImplicit();
ctorDecl->setSynthesized();
ctorDecl->copyFormalAccessFrom(enumDecl);
ctorDecl->setBodySynthesizer(synthesizeEnumRawValueConstructorBody, enumDecl);
return ctorDecl;
Expand Down
17 changes: 16 additions & 1 deletion lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4437,7 +4437,22 @@ bool ConstraintSystem::isArgumentOfImportedDecl(
return false;

auto *choice = overload->choice.getDecl();
return choice->hasClangNode();

// Imported declaration.
if (choice->hasClangNode())
return true;

// Implicit declaration synthesized by the compiler.
// Such declarations don't have clang nodes backing
// them but for the purposes of this check we consider
// them imported if the parent is.
if (choice->isSynthesized()) {
auto *dc = choice->getDeclContext();
if (auto *parent = dc->getAsDecl())
return parent->hasClangNode();
}

return false;
}

ConversionEphemeralness
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %empty-directory(%t/src)
// RUN: %empty-directory(%t/sdk)
// RUN: split-file %s %t/src

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %t/src/main.swift \
// RUN: -import-objc-header %t/src/Test.h \
// RUN: -module-name main -I %t -verify

// REQUIRES: objc_interop

//--- Test.h
#include <stdint.h>

typedef struct {
uint8_t* buffer;
} frame_t __attribute__((swift_name("Frame")));

//--- main.swift
func test(rawPointer: UnsafeMutableRawPointer) {
_ = Frame(buffer: rawPointer) // Ok (even though init is synthesized the type is imported)
}