Files
swift-mirror/test/SILOptimizer/keypath-folding-crash.sil
Becca Royal-Gordon c44284d874 Diagnose invalid @_hasStorage attributes
A bug in `@objc @implementation` is causing incorrect `@_hasStorage` attributes to be printed into module interfaces. As an initial step towards fixing this, diagnose bad `@_hasStorage` attributes and treat them as computed properties so that these malformed interfaces don’t cause compiler crashes.

Partially fixes rdar://144811653.
2025-03-27 16:24:44 -07:00

55 lines
1.5 KiB
Plaintext

// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-sil-opt -I %t %t/test.sil -sil-combine | %FileCheck %s
// REQUIRES: objc_interop
//--- module.modulemap
module CModule {
header "c-header.h"
export *
}
//--- c-header.h
@import Foundation;
@interface ObjClass : NSObject
@property (nonatomic, strong, readwrite, nonnull) NSObject *o;
@end
//--- test.sil
sil_stage canonical
import Swift
import SwiftShims
import Builtin
import CModule
@objc @implementation extension ObjClass {
@objc @_hasStorage dynamic var o: NSObject { get set }
}
sil @swift_getAtKeyPath : $@convention(thin) <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0, @guaranteed KeyPath<τ_0_0, τ_0_1>) -> @out τ_0_1
// Check that we don't crash
// CHECK-LABEL: sil @testObjcKeypath :
// CHECK: keypath
// CHECK: apply
// CHECK: } // end sil function 'testObjcKeypath'
sil @testObjcKeypath : $@convention(thin) (@in_guaranteed ObjClass) -> @out NSObject {
bb0(%0 : $*NSObject, %1 : $*ObjClass):
%2 = keypath $KeyPath<ObjClass, NSObject>, (root $ObjClass; stored_property #ObjClass.o : $NSObject)
%3 = function_ref @swift_getAtKeyPath : $@convention(thin) <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0, @guaranteed KeyPath<τ_0_0, τ_0_1>) -> @out τ_0_1
%4 = apply %3<ObjClass, NSObject>(%0, %1, %2) : $@convention(thin) <τ_0_0, τ_0_1> (@in_guaranteed τ_0_0, @guaranteed KeyPath<τ_0_0, τ_0_1>) -> @out τ_0_1
strong_release %2 : $KeyPath<ObjClass, NSObject>
%6 = tuple ()
return %6 : $()
}