Skip to content

Commit 1a94f1c

Browse files
committed
PerformanceDiagnostics: allow metatype arguments to _diagnoseUnexpectedEnumCaseValue
This is a fatal error function, used for imported C enums. rdar://117520459
1 parent e967219 commit 1a94f1c

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,16 @@ static bool metatypeUsesAreNotRelevant(MetatypeInst *mt) {
442442
break;
443443
}
444444
}
445+
if (auto *apply = dyn_cast<ApplyInst>(use->getUser())) {
446+
if (auto *callee = apply->getReferencedFunctionOrNull()) {
447+
// Exclude `Swift._diagnoseUnexpectedEnumCaseValue<A, B>(type: A.Type, rawValue: B) -> Swift.Never`
448+
// It's a fatal error function, used for imported C enums.
449+
if (callee->getName() == "$ss32_diagnoseUnexpectedEnumCaseValue4type03rawE0s5NeverOxm_q_tr0_lF" &&
450+
!mt->getModule().getOptions().EmbeddedSwift) {
451+
continue;
452+
}
453+
}
454+
}
445455
return false;
446456
}
447457
return true;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
typedef enum : int {
3+
A = 1,
4+
B = 2,
5+
C = 5,
6+
} __attribute__((enum_extensibility(closed))) c_closed_enum_t;
7+
8+
9+

test/SILOptimizer/performance-annotations.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -parse-as-library -disable-availability-checking -emit-sil %s -o /dev/null -verify
1+
// RUN: %target-swift-frontend -parse-as-library -disable-availability-checking -import-objc-header %S/Inputs/perf-annotations.h -emit-sil %s -o /dev/null -verify
22
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
33
// REQUIRES: swift_in_compiler
44

@@ -480,3 +480,15 @@ public func testNonCopyable(_ foo: consuming NonCopyable) {
480480
let _ = foo.value
481481
}
482482

483+
@_noAllocation
484+
func matchCEnum(_ variant: c_closed_enum_t) -> Int {
485+
switch variant {
486+
case .A:
487+
return 1
488+
case .B:
489+
return 2
490+
case .C:
491+
return 5
492+
}
493+
}
494+

test/SILOptimizer/readonly_arrays_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift -target %target-future-triple -O %s -o %t/a.out
2+
// RUN: %target-build-swift -O %s -o %t/a.out
33
// RUN: %target-run %t/a.out | %FileCheck %s
44

55
// REQUIRES: executable_test,swift_stdlib_no_asserts,optimized_stdlib

0 commit comments

Comments
 (0)