Skip to content

Commit 1d3b051

Browse files
committed
[cxx-interop] Remove logic around applying attributes.
Removes the logic around applying attributes to C++ constructor's indirect results. Also fixes some commenting.
1 parent b2bb47d commit 1d3b051

File tree

4 files changed

+7
-38
lines changed

4 files changed

+7
-38
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,9 +3522,6 @@ namespace {
35223522
if (decl->getDefinition() && !decl->isBeingDefined() &&
35233523
!decl->isDependentContext() &&
35243524
decl->needsImplicitDefaultConstructor()) {
3525-
// Casting away const here should be OK because
3526-
// SwiftDeclConverter::Visit() is in practice called with a non-const
3527-
// argument.
35283525
clang::CXXConstructorDecl *ctor =
35293526
clangSema.DeclareImplicitDefaultConstructor(
35303527
const_cast<clang::CXXRecordDecl *>(decl));
@@ -3927,7 +3924,7 @@ namespace {
39273924
FuncDecl *func =
39283925
createFuncOrAccessor(Impl.SwiftContext, loc, accessorInfo, name,
39293926
nameLoc, bodyParams, resultTy,
3930-
/*async*/ false, /*throws*/ false, dc, decl);
3927+
/*async=*/false, /*throws=*/false, dc, decl);
39313928
result = func;
39323929

39333930
if (!dc->isModuleScopeContext()) {

lib/IRGen/GenCall.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,10 @@ llvm::CallingConv::ID irgen::expandCallingConv(IRGenModule &IGM,
338338

339339
static void addIndirectResultAttributes(IRGenModule &IGM,
340340
llvm::AttributeList &attrs,
341-
unsigned paramIndex, bool allowSRet,
342-
bool noCapture = true) {
341+
unsigned paramIndex, bool allowSRet) {
343342
llvm::AttrBuilder b;
344343
b.addAttribute(llvm::Attribute::NoAlias);
345-
if (noCapture)
346-
b.addAttribute(llvm::Attribute::NoCapture);
344+
b.addAttribute(llvm::Attribute::NoCapture);
347345
if (allowSRet)
348346
b.addAttribute(llvm::Attribute::StructRet);
349347
attrs = attrs.addAttributes(IGM.getLLVMContext(),
@@ -1429,18 +1427,6 @@ void SignatureExpansion::expandExternalSignatureTypes() {
14291427
}
14301428
}
14311429

1432-
if (formalIndirectResult) {
1433-
// If the result is a formal indirect result in SIL, that means that the
1434-
// Clang function has an explicit output parameter (e.g. it's a C++
1435-
// constructor). This means:
1436-
// - Don't mark it `sret`, as this should only be used for C++ return
1437-
// values.
1438-
// - The Clang function might capture the pointer, so don't specify
1439-
// `nocapture`.
1440-
addIndirectResultAttributes(IGM, Attrs, 0, /* allowSRet = */ false,
1441-
/* noCapture = */ false);
1442-
}
1443-
14441430
if (returnInfo.isIndirect() || returnInfo.isIgnore()) {
14451431
ResultIRType = IGM.VoidTy;
14461432
} else {

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,9 @@ struct UnsafePointer<T> { }
1212
struct UnsafeMutablePointer<T> { }
1313

1414
public func createHasVirtualBase() -> HasVirtualBase {
15-
// - The `this` parameter should carry a `noalias` attribute, as it is
16-
// guaranteed that nothing will alias the object before it has been fully
17-
// constructed. Note that this doesn't apply on ABIs (Itanium ARM,
18-
// Microsoft x64) where we insert an (inlined) thunk; in this case, we're
19-
// getting the attributes of the constructor that was generated by Clang,
20-
// which doesn't insert these attributes.
21-
//
22-
// - The `this` parameter should _not_ carry an `sret` attribute because the
23-
// constructor doesn't return the constructed object as a return value.
24-
//
25-
// - The `this` parameter should _not_ carry a `nocapture` attribute (unlike
26-
// Swift constructors that return their result indirectly) because the C++
27-
// constructor has explicit access to `this` and may capture it.
28-
//
2915
// ITANIUM_X64: define swiftcc void @"$ss20createHasVirtualBaseSo0bcD0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret %0)
3016
// ITANIUM_X64-NOT: define
31-
// ITANIUM_X64: call void @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* noalias %{{[0-9]+}}, i32 %{{[0-9]+}})
17+
// ITANIUM_X64: call void @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* %{{[0-9]+}}, i32 %{{[0-9]+}})
3218
//
3319
// ITANIUM_ARM: define protected swiftcc void @"$ss20createHasVirtualBaseSo0bcD0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret %0)
3420
// To verify that the thunk is inlined, make sure there's no intervening
@@ -48,7 +34,7 @@ public func createHasVirtualBase() -> HasVirtualBase {
4834
public func createImplicitDefaultConstructor() -> ImplicitDefaultConstructor {
4935
// ITANIUM_X64: define swiftcc i32 @"$ss32createImplicitDefaultConstructorSo0bcD0VyF"()
5036
// ITANIUM_X64-NOT: define
51-
// ITANIUM_X64: call void @_ZN26ImplicitDefaultConstructorC1Ev(%struct.ImplicitDefaultConstructor* noalias %{{[0-9]+}})
37+
// ITANIUM_X64: call void @_ZN26ImplicitDefaultConstructorC1Ev(%struct.ImplicitDefaultConstructor* %{{[0-9]+}})
5238
//
5339
// ITANIUM_ARM: define protected swiftcc i32 @"$ss32createImplicitDefaultConstructorSo0bcD0VyF"()
5440
// ITANIUM_ARM-NOT: define
@@ -66,7 +52,7 @@ public func createStructWithSubobjectCopyConstructorAndValue() {
6652
// ITANIUM_X64-LABEL: define swiftcc void @"$ss48createStructWithSubobjectCopyConstructorAndValueyyF"()
6753
// ITANIUM_X64: [[MEMBER:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV
6854
// ITANIUM_X64: [[MEMBER_AS_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* %member to %struct.StructWithCopyConstructorAndValue*
69-
// ITANIUM_X64: void @_ZN33StructWithCopyConstructorAndValueC1Ev(%struct.StructWithCopyConstructorAndValue* noalias [[MEMBER_AS_STRUCT]])
55+
// ITANIUM_X64: void @_ZN33StructWithCopyConstructorAndValueC1Ev(%struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT]])
7056
// ITANIUM_X64: call %TSo33StructWithCopyConstructorAndValueV* @"$sSo33StructWithCopyConstructorAndValueVWOc"(%TSo33StructWithCopyConstructorAndValueV* [[MEMBER]], %TSo33StructWithCopyConstructorAndValueV* [[TMP:%.*]])
7157
// ITANIUM_X64: [[OBJ_MEMBER:%.*]] = getelementptr inbounds %TSo42StructWithSubobjectCopyConstructorAndValueV, %TSo42StructWithSubobjectCopyConstructorAndValueV* %obj, i32 0, i32 0
7258
// ITANIUM_X64: call %TSo33StructWithCopyConstructorAndValueV* @"$sSo33StructWithCopyConstructorAndValueVWOb"(%TSo33StructWithCopyConstructorAndValueV* [[TMP]], %TSo33StructWithCopyConstructorAndValueV* [[OBJ_MEMBER]])

test/Interop/Cxx/class/constructors-objc-irgen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public func createConstructorWithNSArrayParam() -> ConstructorWithNSArrayParam {
1111
// CHECK: [[VAR:%[0-9]+]] = alloca %TSo27ConstructorWithNSArrayParamV, align 1
1212
// CHECK: %{{[0-9]+}} = call swiftcc %TSo7NSArrayC* @"$sSa10FoundationE19_bridgeToObjectiveCSo7NSArrayCyF"(%swift.bridge* %{{[0-9]+}}, %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sypN", i32 0, i32 1))
1313
// CHECK: [[CAST_VAR:%[0-9]+]] = bitcast %TSo27ConstructorWithNSArrayParamV* [[VAR]] to %struct.ConstructorWithNSArrayParam*
14-
// CHECK: call void @_ZN27ConstructorWithNSArrayParamC1EP7NSArray(%struct.ConstructorWithNSArrayParam* noalias [[CAST_VAR]], [[VAR]]* %{{[0-9]+}})
14+
// CHECK: call void @_ZN27ConstructorWithNSArrayParamC1EP7NSArray(%struct.ConstructorWithNSArrayParam* [[CAST_VAR]], [[VAR]]* %{{[0-9]+}})
1515
return ConstructorWithNSArrayParam([])
1616
}

0 commit comments

Comments
 (0)