From 7bbf44c76695b969e238ee6786c5c565a6fda754 Mon Sep 17 00:00:00 2001 From: Ruowen Qin Date: Sun, 23 Jun 2024 00:05:56 +0800 Subject: [PATCH] fix the deprecated features of old llvm-14 - cast assertion failure - getNonOpaquePointerElementType() LLVM removed the type of pointer Signed-off-by: Ruowen Qin --- .../InnerUnikernels/IUInsertEntry.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Transforms/InnerUnikernels/IUInsertEntry.cpp b/llvm/lib/Transforms/InnerUnikernels/IUInsertEntry.cpp index bc71793fa2347a..6df790ce1ce292 100644 --- a/llvm/lib/Transforms/InnerUnikernels/IUInsertEntry.cpp +++ b/llvm/lib/Transforms/InnerUnikernels/IUInsertEntry.cpp @@ -41,6 +41,7 @@ #include "llvm/IRReader/IRReader.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ErrorOr.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/ModuleUtils.h" @@ -170,6 +171,8 @@ bool IUEntryInsertion::runOnModule(Module &M) const { auto *CS = cast(Init); // rtti + // Run-Time Type Information (RTTI) is a feature in C++ that allows the + // type of an object to be determined during program execution Constant *OP0 = CS->getOperand(0); auto *OP0Cda = cast(OP0); const char *RawRTTI = OP0Cda->getRawDataValues().data(); @@ -194,13 +197,10 @@ bool IUEntryInsertion::runOnModule(Module &M) const { // prog_fn Constant *OP1 = CS->getOperand(1); - auto *OP1CE = cast(OP1); + Function *Func = cast(OP1); + FunctionType *FuncType = Func->getFunctionType(); - Type *OP1SrcTy = OP1CE->getOperand(0)->getType(); - Type *OP1PointeeT = OP1SrcTy->getNonOpaquePointerElementType(); - - FunctionType *ProgFuncTy = cast(OP1PointeeT); - Type *ProgSelfTy = ProgFuncTy->getParamType(0); + Type *ProgSelfTy = FuncType->getParamType(0); SmallVector CtxTys; PointerType *CtxPT = StructType::get(C, CtxTys)->getPointerTo(); @@ -215,10 +215,8 @@ bool IUEntryInsertion::runOnModule(Module &M) const { // name: &'a str Constant *OP2 = CS->getOperand(2); - auto *OP2CE = cast(OP2); - Constant *ProgNameInit = - cast(OP2CE->getOperand(0))->getInitializer(); + Constant *ProgNameInit = cast(OP2)->getInitializer(); auto *ProgNameStruct = cast(ProgNameInit); auto *ProgNameCda = cast(ProgNameStruct->getOperand(0)); @@ -226,7 +224,7 @@ bool IUEntryInsertion::runOnModule(Module &M) const { ProgNameCda->getType()->getNumElements()); // Add inserted program name metadata to backend pass - if (auto *FunOP1 = dyn_cast(OP1CE->getOperand(0))) { + if (auto *FunOP1 = dyn_cast(Func)) { StringRef UserProg = FunOP1->getName(); Metadata *Str = MDString::get(Context, UserProg); MDNode *Node = MDNode::get(Context, Str);