Skip to content

Commit 18ab2f8

Browse files
jckarterDave Abrahams
authored andcommitted
Runtime: Only complain about a deprecated ObjC entry point once.
We only need to alert the user once. rdar://problem/32229417
1 parent a87c35e commit 18ab2f8

File tree

7 files changed

+36
-5
lines changed

7 files changed

+36
-5
lines changed

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ FUNCTION(GetInitializedObjCClass, swift_getInitializedObjCClass, RegisterPreserv
12421242
FUNCTION(Swift3ImplicitObjCEntrypoint, swift_objc_swift3ImplicitObjCEntrypoint,
12431243
DefaultCC,
12441244
RETURNS(VoidTy),
1245-
ARGS(ObjCPtrTy, ObjCSELTy, Int8PtrTy, SizeTy, SizeTy, SizeTy),
1245+
ARGS(ObjCPtrTy, ObjCSELTy, Int8PtrTy, SizeTy, SizeTy, SizeTy, Int8PtrTy),
12461246
ATTRS(NoUnwind))
12471247

12481248
#endif

lib/IRGen/GenBuiltin.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ if (Builtin.ID == BuiltinValueKind::id) { \
860860
}
861861

862862
if (Builtin.ID == BuiltinValueKind::Swift3ImplicitObjCEntrypoint) {
863-
llvm::Value *entrypointArgs[6];
863+
llvm::Value *entrypointArgs[7];
864864
auto argIter = IGF.CurFn->arg_begin();
865865

866866
// self
@@ -881,6 +881,16 @@ if (Builtin.ID == BuiltinValueKind::id) { \
881881
entrypointArgs[4] = args.claimNext();
882882
// Column
883883
entrypointArgs[5] = args.claimNext();
884+
885+
// Create a flag variable so that this invocation logs only once.
886+
auto flagStorageTy = llvm::ArrayType::get(IGF.IGM.Int8Ty,
887+
IGF.IGM.getAtomicBoolSize().getValue());
888+
auto flag = new llvm::GlobalVariable(IGF.IGM.Module, flagStorageTy,
889+
/*constant*/ false,
890+
llvm::GlobalValue::PrivateLinkage,
891+
llvm::ConstantAggregateZero::get(flagStorageTy));
892+
flag->setAlignment(IGF.IGM.getAtomicBoolAlignment().getValue());
893+
entrypointArgs[6] = llvm::ConstantExpr::getBitCast(flag, IGF.IGM.Int8PtrTy);
884894

885895
IGF.Builder.CreateCall(IGF.IGM.getSwift3ImplicitObjCEntrypointFn(),
886896
entrypointArgs);

lib/IRGen/IRGenModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
385385

386386
initClangTypeConverter();
387387

388+
if (ClangASTContext) {
389+
auto atomicBoolTy = ClangASTContext->getAtomicType(ClangASTContext->BoolTy);
390+
AtomicBoolSize = Size(ClangASTContext->getTypeSize(atomicBoolTy));
391+
AtomicBoolAlign = Alignment(ClangASTContext->getTypeSize(atomicBoolTy));
392+
}
393+
388394
IsSwiftErrorInRegister =
389395
clang::CodeGen::swiftcall::isSwiftErrorLoweredInRegister(
390396
ClangCodeGen->CGM());

lib/IRGen/IRGenModule.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class IRGenModule {
492492
llvm::PointerType *ErrorPtrTy; /// %swift.error*
493493
llvm::StructType *OpenedErrorTripleTy; /// { %swift.opaque*, %swift.type*, i8** }
494494
llvm::PointerType *OpenedErrorTriplePtrTy; /// { %swift.opaque*, %swift.type*, i8** }*
495-
495+
496496
unsigned InvariantMetadataID; /// !invariant.load
497497
unsigned DereferenceableID; /// !dereferenceable
498498
llvm::MDNode *InvariantNode;
@@ -574,9 +574,14 @@ class IRGenModule {
574574
void error(SourceLoc loc, const Twine &message);
575575

576576
bool useDllStorage();
577+
578+
Size getAtomicBoolSize() const { return AtomicBoolSize; }
579+
Alignment getAtomicBoolAlignment() const { return AtomicBoolAlign; }
577580

578581
private:
579582
Size PtrSize;
583+
Size AtomicBoolSize;
584+
Alignment AtomicBoolAlign;
580585
llvm::Type *FixedBufferTy; /// [N x i8], where N == 3 * sizeof(void*)
581586

582587
llvm::Type *ValueWitnessTys[MaxNumValueWitnesses];

stdlib/public/runtime/SwiftObject.mm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,13 @@ static bool usesNativeSwiftReferenceCounting_nonNull(
13651365
void swift_objc_swift3ImplicitObjCEntrypoint(id self, SEL selector,
13661366
const char *filename,
13671367
size_t filenameLength,
1368-
size_t line, size_t column) {
1368+
size_t line, size_t column,
1369+
std::atomic<bool> *didLog) {
1370+
// Only log once. We should have been given a unique zero-initialized
1371+
// atomic flag for each entry point.
1372+
if (didLog->exchange(true))
1373+
return;
1374+
13691375
// Figure out how much reporting we want by querying the environment
13701376
// variable SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT. We have four meaningful
13711377
// levels:

test/IRGen/objc_deprecated_objc_thunks.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ObjCSubclass : NSObject {
1616
// CHECK-SWIFT4-LABEL: define hidden void @_T0016objc_deprecated_A7_thunks12ObjCSubclassC3fooyyFTo(%0*, i8*)
1717
// CHECK-SWIFT4: entry:
1818
// CHECK-SWIFT4: [[SELF:%[0-9]+]] = bitcast %0* %0 to %objc_object*
19-
// CHECK-SWIFT4-NEXT: call void @swift_objc_swift3ImplicitObjCEntrypoint(%objc_object* [[SELF]], i8* %1, i8* getelementptr inbounds ({{.*}}[[FILENAME_STR]]{{.*}}), i64 [[FILENAME_LENGTH:[0-9]+]], i64 13, i64 3)
19+
// CHECK-SWIFT4-NEXT: call void @swift_objc_swift3ImplicitObjCEntrypoint(%objc_object* [[SELF]], i8* %1, i8* getelementptr inbounds ({{.*}}[[FILENAME_STR]]{{.*}}), i64 [[FILENAME_LENGTH:[0-9]+]], i64 13, i64 3, i8* {{.*}})
2020

2121
// CHECK-SWIFT3-LABEL: define hidden void @_T0016objc_deprecated_A7_thunks12ObjCSubclassC3fooyyFTo(%0*, i8*)
2222
// CHECK-SWIFT3: entry:

test/Interpreter/SDK/objc_swift3_deprecated_objc_inference.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ DeprecatedObjCInferenceTestSuite.test("messagingObjCInference") {
4545
// CHECK_WARNINGS: .swift:26:3: implicit Objective-C entrypoint -[a.MyClass foo]
4646
// CHECK_CRASH: .swift:26:3: implicit Objective-C entrypoint -[a.MyClass foo]
4747
x.perform(Selector(fooSel))
48+
// CHECK_WARNINGS-NOT: .swift:26:3: implicit Objective-C entrypoint -[a.MyClass foo]
49+
x.perform(Selector(fooSel))
4850

4951
// CHECK_WARNINGS: .swift:27:3: implicit Objective-C entrypoint +[a.MyClass bar]
5052
type(of: x).perform(Selector(barSel))
53+
// CHECK_WARNINGS-NOT: .swift:27:3: implicit Objective-C entrypoint +[a.MyClass bar]
54+
type(of: x).perform(Selector(barSel))
5155

5256
// CHECK_NOTHING-NEXT: ---End
5357
// CHECK_WARNINGS: ---End

0 commit comments

Comments
 (0)