Skip to content

Commit

Permalink
fix the deprecated features of old llvm-14
Browse files Browse the repository at this point in the history
- cast<ConstantExpr> assertion failure
- getNonOpaquePointerElementType() LLVM removed the type of pointer

Signed-off-by: Ruowen Qin <chinqrw@gmail.com>
  • Loading branch information
chinrw committed Jun 22, 2024
1 parent 90518f6 commit 7bbf44c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions llvm/lib/Transforms/InnerUnikernels/IUInsertEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -170,6 +171,8 @@ bool IUEntryInsertion::runOnModule(Module &M) const {
auto *CS = cast<ConstantStruct>(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<ConstantDataArray>(OP0);
const char *RawRTTI = OP0Cda->getRawDataValues().data();
Expand All @@ -194,13 +197,10 @@ bool IUEntryInsertion::runOnModule(Module &M) const {

// prog_fn
Constant *OP1 = CS->getOperand(1);
auto *OP1CE = cast<ConstantExpr>(OP1);
Function *Func = cast<Function>(OP1);
FunctionType *FuncType = Func->getFunctionType();

Type *OP1SrcTy = OP1CE->getOperand(0)->getType();
Type *OP1PointeeT = OP1SrcTy->getNonOpaquePointerElementType();

FunctionType *ProgFuncTy = cast<FunctionType>(OP1PointeeT);
Type *ProgSelfTy = ProgFuncTy->getParamType(0);
Type *ProgSelfTy = FuncType->getParamType(0);

SmallVector<Type *, 0> CtxTys;
PointerType *CtxPT = StructType::get(C, CtxTys)->getPointerTo();
Expand All @@ -215,18 +215,16 @@ bool IUEntryInsertion::runOnModule(Module &M) const {

// name: &'a str
Constant *OP2 = CS->getOperand(2);
auto *OP2CE = cast<ConstantExpr>(OP2);

Constant *ProgNameInit =
cast<GlobalVariable>(OP2CE->getOperand(0))->getInitializer();
Constant *ProgNameInit = cast<GlobalVariable>(OP2)->getInitializer();
auto *ProgNameStruct = cast<ConstantStruct>(ProgNameInit);
auto *ProgNameCda =
cast<ConstantDataArray>(ProgNameStruct->getOperand(0));
std::string ProgName(ProgNameCda->getRawDataValues().data(),
ProgNameCda->getType()->getNumElements());

// Add inserted program name metadata to backend pass
if (auto *FunOP1 = dyn_cast<Function>(OP1CE->getOperand(0))) {
if (auto *FunOP1 = dyn_cast<Function>(Func)) {
StringRef UserProg = FunOP1->getName();
Metadata *Str = MDString::get(Context, UserProg);
MDNode *Node = MDNode::get(Context, Str);
Expand Down

0 comments on commit 7bbf44c

Please sign in to comment.