Avatar
omochimetaru 9/4/2018 6:33 AM
6:33 AM
struct Stone { var _x: Int = 3 var x: Int { get { return _x } _modify { yield &_x } } } func mod(_ x: inout Int) { x = 8 } func main() { var a = Stone() mod(&a.x) }
6:33 AM
define hidden swiftcc void @"$S1a4mainyyF"() #0 { entry: %a = alloca %T1a5StoneV, align 8 %0 = bitcast %T1a5StoneV* %a to %swift.opaque** store %swift.opaque* null, %swift.opaque** %0, align 8 %1 = alloca [32 x i8], align 8 %2 = bitcast %T1a5StoneV* %a to i8* call void @llvm.lifetime.start.p0i8(i64 8, i8* %2) %3 = call swiftcc i64 @"$S1a5StoneVACycfC"() %a._x = getelementptr inbounds %T1a5StoneV, %T1a5StoneV* %a, i32 0, i32 0 %a._x._value = getelementptr inbounds %TSi, %TSi* %a._x, i32 0, i32 0 store i64 %3, i64* %a._x._value, align 8 %4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i32 0, i32 0 call void @llvm.lifetime.start.p0i8(i64 32, i8* %4) %5 = call swiftcc { i8*, %TSi* } @"$S1a5StoneV1xSivM"(i8* noalias dereferenceable(32) %4, %T1a5StoneV* nocapture swiftself dereferenceable(8) %a) %6 = extractvalue { i8*, %TSi* } %5, 0 %7 = extractvalue { i8*, %TSi* } %5, 1 call swiftcc void @"$S1a3modyySizF"(%TSi* nocapture dereferenceable(8) %7) %8 = bitcast i8* %6 to void (i8*, i1)* call swiftcc void %8(i8* noalias dereferenceable(32) %4, i1 false) call void @llvm.lifetime.end.p0i8(i64 32, i8* %4) %9 = bitcast %T1a5StoneV* %a to i8* call void @llvm.lifetime.end.p0i8(i64 8, i8* %9) ret void }
6:33 AM
define hidden swiftcc { i8*, %TSi* } @"$S1a5StoneV1xSivM"(i8* noalias dereferenceable(32), %T1a5StoneV* nocapture swiftself dereferenceable(8)) #1 { entry: %._x = getelementptr inbounds %T1a5StoneV, %T1a5StoneV* %1, i32 0, i32 0 %2 = insertvalue { i8*, %TSi* } { i8* bitcast (void (i8*, i1)* @"$S1a5StoneV1xSivM.resume.0" to i8*), %TSi* undef }, %TSi* %._x, 1 ret { i8*, %TSi* } %2 } define internal swiftcc void @"$S1a5StoneV1xSivM.resume.0"(i8* noalias nonnull dereferenceable(32), i1) #0 { entryresume.0: %FramePtr = bitcast i8* %0 to %"$S1a5StoneV1xSivM.Frame"* %vFrame = bitcast %"$S1a5StoneV1xSivM.Frame"* %FramePtr to i8* ret void }
6:34 AM
テストコードみてたら、 _modify でもうお試しできるとわかった