Skip to content

Commit 90fa95c

Browse files
authored
Merge pull request #59697 from zoecarver/use-call-for-attrs
[cxx-interop] Record extra layer of indirection when calculating clang type from SILType.
2 parents c5b91d1 + f86f9b7 commit 90fa95c

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,6 +2916,7 @@ llvm::CallInst *IRBuilder::CreateCall(const FunctionPointer &fn,
29162916
fn.getRawPointer()->getType()->getPointerElementType());
29172917
llvm::CallInst *call =
29182918
IRBuilderBase::CreateCall(fnTy, fn.getRawPointer(), args, bundles);
2919+
29192920
call->setAttributes(
29202921
fixUpTypesInByValAndStructRetAttributes(fnTy, fn.getAttributes()));
29212922
call->setCallingConv(fn.getCallingConv());

lib/IRGen/GenClangType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ clang::CanQualType IRGenModule::getClangType(CanType type) {
3232
}
3333

3434
clang::CanQualType IRGenModule::getClangType(SILType type) {
35+
if (type.isForeignReferenceType())
36+
return getClangType(type.getASTType()
37+
->wrapInPointer(PTK_UnsafePointer)
38+
->getCanonicalType());
3539
return getClangType(type.getASTType());
3640
}
3741

test/Interop/Cxx/foreign-reference/Inputs/move-only.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ struct __attribute__((swift_attr("import_as_ref"))) MoveOnly {
2929

3030
MoveOnly moveIntoResult(MoveOnly &x) { return move(x); }
3131

32+
struct __attribute__((swift_attr("import_as_ref"))) NoCopyMove {
33+
NoCopyMove() = default;
34+
NoCopyMove(const NoCopyMove &) = delete;
35+
NoCopyMove(NoCopyMove &&) = delete;
36+
37+
int test() const { return 42; }
38+
int testMutable() { return 42; }
39+
40+
static NoCopyMove *create() {
41+
return new (malloc(sizeof(NoCopyMove))) NoCopyMove();
42+
}
43+
};
44+
3245
struct __attribute__((swift_attr("import_as_ref"))) HasMoveOnlyChild {
3346
MoveOnly child;
3447

test/Interop/Cxx/foreign-reference/move-only.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ MoveOnlyTestSuite.test("MoveOnly") {
1919
expectEqual(x.test(), 42)
2020
}
2121

22+
MoveOnlyTestSuite.test("NoCopyMove") {
23+
var x = NoCopyMove.create()
24+
expectEqual(x.test(), 42)
25+
expectEqual(x.testMutable(), 42)
26+
27+
x = NoCopyMove.create()
28+
expectEqual(x.test(), 42)
29+
}
30+
2231
MoveOnlyTestSuite.test("PrivateCopyCtor") {
2332
var x = PrivateCopyCtor.create()
2433
expectEqual(x.test(), 42)

0 commit comments

Comments
 (0)