Skip to content

Commit

Permalink
[Coroutines] Avoid some pointer element type accesses
Browse files Browse the repository at this point in the history
These are just verifying that pointer types are correct, which is
no longer relevant under opaque pointers.
  • Loading branch information
nikic committed Jan 21, 2022
1 parent 0ca426d commit bfbdb5e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions llvm/lib/Transforms/Coroutines/Coroutines.cpp
Expand Up @@ -676,6 +676,9 @@ static void checkAsyncFuncPointer(const Instruction *I, Value *V) {
if (!AsyncFuncPtrAddr)
fail(I, "llvm.coro.id.async async function pointer not a global", V);

if (AsyncFuncPtrAddr->getType()->isOpaquePointerTy())
return;

auto *StructTy =
cast<StructType>(AsyncFuncPtrAddr->getType()->getPointerElementType());
if (StructTy->isOpaque() || !StructTy->isPacked() ||
Expand All @@ -701,14 +704,16 @@ void CoroIdAsyncInst::checkWellFormed() const {
static void checkAsyncContextProjectFunction(const Instruction *I,
Function *F) {
auto *FunTy = cast<FunctionType>(F->getValueType());
if (!FunTy->getReturnType()->isPointerTy() ||
!FunTy->getReturnType()->getPointerElementType()->isIntegerTy(8))
Type *Int8Ty = Type::getInt8Ty(F->getContext());
auto *RetPtrTy = dyn_cast<PointerType>(FunTy->getReturnType());
if (!RetPtrTy || !RetPtrTy->isOpaqueOrPointeeTypeMatches(Int8Ty))
fail(I,
"llvm.coro.suspend.async resume function projection function must "
"return an i8* type",
F);
if (FunTy->getNumParams() != 1 || !FunTy->getParamType(0)->isPointerTy() ||
!FunTy->getParamType(0)->getPointerElementType()->isIntegerTy(8))
!cast<PointerType>(FunTy->getParamType(0))
->isOpaqueOrPointeeTypeMatches(Int8Ty))
fail(I,
"llvm.coro.suspend.async resume function projection function must "
"take one i8* type as parameter",
Expand All @@ -723,8 +728,7 @@ void CoroAsyncEndInst::checkWellFormed() const {
auto *MustTailCallFunc = getMustTailCallFunction();
if (!MustTailCallFunc)
return;
auto *FnTy =
cast<FunctionType>(MustTailCallFunc->getType()->getPointerElementType());
auto *FnTy = MustTailCallFunc->getFunctionType();
if (FnTy->getNumParams() != (arg_size() - 3))
fail(this,
"llvm.coro.end.async must tail call function argument type must "
Expand Down

0 comments on commit bfbdb5e

Please sign in to comment.