[Coroutines] Avoid some pointer element type accesses

These are just verifying that pointer types are correct, which is
no longer relevant under opaque pointers.
This commit is contained in:
Nikita Popov 2022-01-21 12:34:35 +01:00
parent 0ca426d6ac
commit bfbdb5e43e
1 changed files with 9 additions and 5 deletions

View File

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