Skip to content

Commit 6c8fa42

Browse files
chinrwjinghao-jia
authored andcommitted
fix the deprecated features of old llvm-14
- cast<ConstantExpr> assertion failure - getNonOpaquePointerElementType() LLVM removed the type of pointer Signed-off-by: Ruowen Qin <[email protected]>
1 parent 35a580b commit 6c8fa42

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

llvm/lib/Transforms/InnerUnikernels/IUInsertEntry.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "llvm/IRReader/IRReader.h"
4242
#include "llvm/Support/Casting.h"
4343
#include "llvm/Support/ErrorHandling.h"
44+
#include "llvm/Support/ErrorOr.h"
4445
#include "llvm/Support/SourceMgr.h"
4546
#include "llvm/Support/raw_ostream.h"
4647
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -170,6 +171,8 @@ bool IUEntryInsertion::runOnModule(Module &M) const {
170171
auto *CS = cast<ConstantStruct>(Init);
171172

172173
// rtti
174+
// Run-Time Type Information (RTTI) is a feature in C++ that allows the
175+
// type of an object to be determined during program execution
173176
Constant *OP0 = CS->getOperand(0);
174177
auto *OP0Cda = cast<ConstantDataArray>(OP0);
175178
const char *RawRTTI = OP0Cda->getRawDataValues().data();
@@ -194,13 +197,10 @@ bool IUEntryInsertion::runOnModule(Module &M) const {
194197

195198
// prog_fn
196199
Constant *OP1 = CS->getOperand(1);
197-
auto *OP1CE = cast<ConstantExpr>(OP1);
200+
Function *Func = cast<Function>(OP1);
201+
FunctionType *FuncType = Func->getFunctionType();
198202

199-
Type *OP1SrcTy = OP1CE->getOperand(0)->getType();
200-
Type *OP1PointeeT = OP1SrcTy->getNonOpaquePointerElementType();
201-
202-
FunctionType *ProgFuncTy = cast<FunctionType>(OP1PointeeT);
203-
Type *ProgSelfTy = ProgFuncTy->getParamType(0);
203+
Type *ProgSelfTy = FuncType->getParamType(0);
204204

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

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

220-
Constant *ProgNameInit =
221-
cast<GlobalVariable>(OP2CE->getOperand(0))->getInitializer();
219+
Constant *ProgNameInit = cast<GlobalVariable>(OP2)->getInitializer();
222220
auto *ProgNameStruct = cast<ConstantStruct>(ProgNameInit);
223221
auto *ProgNameCda =
224222
cast<ConstantDataArray>(ProgNameStruct->getOperand(0));
225223
std::string ProgName(ProgNameCda->getRawDataValues().data(),
226224
ProgNameCda->getType()->getNumElements());
227225

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

0 commit comments

Comments
 (0)