diff --git a/lib/SIL/Utils/InstructionUtils.cpp b/lib/SIL/Utils/InstructionUtils.cpp index 3ef0b8213271d..adceabbe5c6af 100644 --- a/lib/SIL/Utils/InstructionUtils.cpp +++ b/lib/SIL/Utils/InstructionUtils.cpp @@ -24,6 +24,8 @@ #include "swift/SIL/SILBuilder.h" #include "swift/SIL/SILVisitor.h" +#include "clang/AST/DeclObjC.h" + using namespace swift; SILValue swift::lookThroughOwnershipInsts(SILValue v) { @@ -915,7 +917,17 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType) auto as = ApplySite(inst); switch (as.getSubstCalleeType()->getRepresentation()) { - case SILFunctionTypeRepresentation::ObjCMethod: + case SILFunctionTypeRepresentation::ObjCMethod: { + if (auto *callee = as.getCalleeFunction()) { + if (auto *clangDecl = callee->getClangDecl()) { + if (auto clangMethodDecl = dyn_cast(clangDecl)) { + if (clangMethodDecl->isDirectMethod()) { + break; + } + } + } + } + } case SILFunctionTypeRepresentation::Block: rt |= RuntimeEffect::ObjectiveC | RuntimeEffect::MetaData; break; diff --git a/test/SILOptimizer/performance-diags-ns-direct.swift b/test/SILOptimizer/performance-diags-ns-direct.swift new file mode 100644 index 0000000000000..447cca4fc602c --- /dev/null +++ b/test/SILOptimizer/performance-diags-ns-direct.swift @@ -0,0 +1,32 @@ +// RUN: %empty-directory(%t) +// RUN: split-file %s %t + +// RUN: %target-swift-frontend -emit-ir -verify -I %t/Inputs %t/test.swift + +// REQUIRES: objc_interop + +//--- Inputs/header.h + +@interface Interface + +- (void)test __attribute__((objc_direct)) __attribute__((swift_attr("@_noObjCBridging"))); + +@end + + +//--- Inputs/module.modulemap + +module ObjCModule { + header "header.h" + export * +} + +//--- test.swift + +import Foundation +import ObjCModule + +@_noObjCBridging +func test(i: Interface) { + i.test() +} \ No newline at end of file