diff --git a/lib/IRGen/GenPointerAuth.cpp b/lib/IRGen/GenPointerAuth.cpp index 94b6b81be8b66..a786a9b159420 100644 --- a/lib/IRGen/GenPointerAuth.cpp +++ b/lib/IRGen/GenPointerAuth.cpp @@ -771,6 +771,18 @@ void ConstantAggregateBuilderBase::addSignedPointer(llvm::Constant *pointer, llvm::ConstantInt::get(IGM().Int64Ty, otherDiscriminator)); } +llvm::ConstantInt *IRGenModule::getMallocTypeId(llvm::Function *fn) { + if (!getOptions().EmitTypeMallocForCoroFrame) { + // Even when typed malloc isn't enabled, a type id may be required for ABI + // reasons (e.g. as an argument to swift_coro_alloc). Use a cheaply + // materialized value. + return llvm::ConstantInt::get(Int64Ty, 0); + } + uint64_t hash = llvm::getStableSipHash(fn->getName()); + uint32_t hash32 = (hash % std::numeric_limits::max()) + 1; + return llvm::ConstantInt::get(Int64Ty, hash32); +} + llvm::ConstantInt* IRGenFunction::getMallocTypeId() { - return getDiscriminatorForString(IGM, CurFn->getName()); + return IGM.getMallocTypeId(CurFn); } diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h index c399e59d81bbf..8c67a59583a6c 100644 --- a/lib/IRGen/IRGenModule.h +++ b/lib/IRGen/IRGenModule.h @@ -1674,6 +1674,8 @@ private: \ llvm::AttributeList constructInitialAttributes(); StackProtectorMode shouldEmitStackProtector(SILFunction *f); + llvm::ConstantInt *getMallocTypeId(llvm::Function *fn); + void emitProtocolDecl(ProtocolDecl *D); void emitEnumDecl(EnumDecl *D); void emitStructDecl(StructDecl *D); diff --git a/test/IRGen/yield_once_enable_emit_type_malloc_coro_frame.sil b/test/IRGen/yield_once_enable_emit_type_malloc_coro_frame.sil index 9eddb211dd261..9ae46e04a70cd 100644 --- a/test/IRGen/yield_once_enable_emit_type_malloc_coro_frame.sil +++ b/test/IRGen/yield_once_enable_emit_type_malloc_coro_frame.sil @@ -11,8 +11,8 @@ sil @marker : $(Builtin.Int32) -> () // CHECK-SAME: [[CORO_ATTRIBUTES:#[0-9]+]] sil @test_simple : $@yield_once () -> () { entry: - // CHECK-32: [[ID:%.*]] = call token (i32, i32, ptr, ptr, ptr, ptr, ...) @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @"$sIetA_TC", ptr @__swift_coroFrameAllocStub, ptr @free, i64 38223) - // CHECK-64: [[ID:%.*]] = call token (i32, i32, ptr, ptr, ptr, ptr, ...) @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @"$sIetA_TC", ptr @__swift_coroFrameAllocStub, ptr @free, i64 38223) + // CHECK-32: [[ID:%.*]] = call token (i32, i32, ptr, ptr, ptr, ptr, ...) @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:4]], ptr %0, ptr @"$sIetA_TC", ptr @__swift_coroFrameAllocStub, ptr @free, i64 121146903) + // CHECK-64: [[ID:%.*]] = call token (i32, i32, ptr, ptr, ptr, ptr, ...) @llvm.coro.id.retcon.once(i32 [[BUFFER_SIZE]], i32 [[BUFFER_ALIGN:8]], ptr %0, ptr @"$sIetA_TC", ptr @__swift_coroFrameAllocStub, ptr @free, i64 121146903) // CHECK-NEXT: [[BEGIN:%.*]] = call ptr @llvm.coro.begin(token [[ID]], ptr null) // CHECK-NEXT: call swiftcc void @marker(i32 1000)