Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2556,9 +2556,10 @@ llvm::Value *emitIndirectAsyncFunctionPointer(IRGenFunction &IGF,
llvm::Constant *One =
llvm::Constant::getIntegerValue(IntPtrTy, APInt(IntPtrTy->getBitWidth(),
1));
llvm::Constant *NegativeOne =
llvm::Constant::getIntegerValue(IntPtrTy, APInt(IntPtrTy->getBitWidth(),
-2));
// TODO: Avoid implicit truncation.
llvm::Constant *NegativeOne = llvm::Constant::getIntegerValue(
IntPtrTy, APInt(IntPtrTy->getBitWidth(), -2, /*isSigned*/ false,
/*implicitTrunc*/ true));
swift::irgen::Alignment PointerAlignment = IGF.IGM.getPointerAlignment();

llvm::Value *PtrToInt = IGF.Builder.CreatePtrToInt(pointer, IntPtrTy);
Expand Down Expand Up @@ -2587,8 +2588,10 @@ llvm::Value *emitIndirectCoroFunctionPointer(IRGenFunction &IGF,
IntPtrTy, APInt(IntPtrTy->getBitWidth(), 0));
llvm::Constant *One = llvm::Constant::getIntegerValue(
IntPtrTy, APInt(IntPtrTy->getBitWidth(), 1));
// TODO: Avoid implicit truncation.
llvm::Constant *NegativeOne = llvm::Constant::getIntegerValue(
IntPtrTy, APInt(IntPtrTy->getBitWidth(), -2));
IntPtrTy, APInt(IntPtrTy->getBitWidth(), -2, /*isSigned*/ false,
/*implicitTrunc*/ true));
Copy link
Contributor

@rjmccall rjmccall Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pass /*isSigned*/ true. If IntPtrTy->getBitWidth() were actually huge, we would in fact want this to be sign-extended, and it also fixes the assertion without needing to pass implicitTrunc because it's okay to truncate consistent sign bits. (This also means you can just make the change on main.)

Also, I don't think this is on you to fix, but how did we end up with a variable called NegativeOne that represents a value of -2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

how did we end up with a variable called NegativeOne that represents a value of -2

68bc33fed32#diff-e3cb1b9416734345839b90f1c5ec26d9173d335e687abb007c9ec0b332b3d3e4

cc @compnerd

swift::irgen::Alignment PointerAlignment = IGF.IGM.getPointerAlignment();

llvm::Value *PtrToInt = IGF.Builder.CreatePtrToInt(pointer, IntPtrTy);
Expand Down