Skip to content

Commit beaaa74

Browse files
martinboehmezoecarver
authored andcommitted
Don't put an sret attribute on the this argument.
1 parent bed2603 commit beaaa74

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,13 @@ void SignatureExpansion::expandExternalSignatureTypes() {
14351435
if (formalIndirectResult) {
14361436
// If the result is a formal indirect result in SIL, that means that the
14371437
// Clang function has an explicit output parameter (e.g. it's a C++
1438-
// constructor), which it might capture -- so don't specify "nocapture".
1439-
addIndirectResultAttributes(IGM, Attrs, 0, claimSRet(), /* nocapture = */ false);
1438+
// constructor). This means:
1439+
// - Don't mark it `sret`, as this should only be used for C++ return
1440+
// values.
1441+
// - The Clang function might capture the pointer, so don't specify
1442+
// `nocapture`.
1443+
addIndirectResultAttributes(IGM, Attrs, 0, /* allowSRet = */ false,
1444+
/* noCapture = */ false);
14401445
}
14411446

14421447
if (returnInfo.isIndirect() || returnInfo.isIgnore()) {

test/Interop/Cxx/class/constructors-ir.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ typealias Void = ()
1111
public func createHasVirtualBase() -> HasVirtualBase {
1212
// - The `this` parameter should carry a `noalias` attribute, as it is
1313
// guaranteed that nothing will alias the object before it has been fully
14-
// constructed. It should also carry an `sret` attribute to indicate that
15-
// this is an out parameter for a structure being returned by the function.
16-
// Note that this doesn't apply on ABIs (Itanium ARM, Microsoft x64)
17-
// where we insert an (inlined) thunk; in this case, we're getting the
18-
// attributes of the constructor that was generated by Clang, which doesn't
19-
// insert these attributes.
14+
// constructed. Note that this doesn't apply on ABIs (Itanium ARM,
15+
// Microsoft x64) where we insert an (inlined) thunk; in this case, we're
16+
// getting the attributes of the constructor that was generated by Clang,
17+
// which doesn't insert these attributes.
18+
//
19+
// - The `this` parameter should _not_ carry an `sret` attribute because the
20+
// constructor doesn't return the constructed object as a return value.
2021
//
2122
// - The `this` parameter should _not_ carry a `nocapture` attribute (unlike
2223
// Swift constructors that return their result indirectly) because the C++
2324
// constructor has explicit access to `this` and may capture it.
2425
//
2526
// ITANIUM_X64: define swiftcc void @"$ss20createHasVirtualBaseSo0bcD0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret %0)
2627
// ITANIUM_X64-NOT: define
27-
// ITANIUM_X64: call void @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* noalias sret %{{[0-9]+}}, i32 %{{[0-9]+}})
28+
// ITANIUM_X64: call void @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* noalias %{{[0-9]+}}, i32 %{{[0-9]+}})
2829
//
2930
// ITANIUM_ARM: define protected swiftcc void @"$ss20createHasVirtualBaseSo0bcD0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret %0)
3031
// To verify that the thunk is inlined, make sure there's no intervening

0 commit comments

Comments
 (0)