Skip to content

Commit 1832c03

Browse files
Fix llvm20 compilation error (#5194)
The following is the error message: /home/yhs/work/bcc/src/cc/frontends/clang/b_frontend_action.cc: In member function ‘bool ebpf::BTypeVisitor::VisitBinaryOperator(clang::BinaryOperator*)’: /home/yhs/work/bcc/src/cc/frontends/clang/b_frontend_action.cc:1383:64: error: no matching function for call to ‘clang::FieldDecl::getBitWidthValue(clang::ASTContext&)’ 1383 | uint64_t sz = F->isBitField() ? F->getBitWidthValue(C) : C.getTypeSize(F->getType()); | ~~~~~~~~~~~~~~~~~~~^~~ which is due to upstream patch: llvm/llvm-project#122289 This patch fixed the above compilation error. Signed-off-by: Yonghong Song <[email protected]>
1 parent 68710c4 commit 1832c03

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/cc/frontends/clang/b_frontend_action.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,11 @@ bool BTypeVisitor::VisitBinaryOperator(BinaryOperator *E) {
13801380
}
13811381

13821382
uint64_t ofs = C.getFieldOffset(F);
1383+
#if LLVM_VERSION_MAJOR >= 20
1384+
uint64_t sz = F->isBitField() ? F->getBitWidthValue() : C.getTypeSize(F->getType());
1385+
#else
13831386
uint64_t sz = F->isBitField() ? F->getBitWidthValue(C) : C.getTypeSize(F->getType());
1387+
#endif
13841388
string base = rewriter_.getRewrittenText(expansionRange(Base->getSourceRange()));
13851389
string text = "bpf_dins_pkt(" + fn_args_[0]->getName().str() + ", (u64)" + base + "+" + to_string(ofs >> 3)
13861390
+ ", " + to_string(ofs & 0x7) + ", " + to_string(sz) + ",";
@@ -1410,7 +1414,11 @@ bool BTypeVisitor::VisitImplicitCastExpr(ImplicitCastExpr *E) {
14101414
return false;
14111415
}
14121416
uint64_t ofs = C.getFieldOffset(F);
1417+
#if LLVM_VERSION_MAJOR >= 20
1418+
uint64_t sz = F->isBitField() ? F->getBitWidthValue() : C.getTypeSize(F->getType());
1419+
#else
14131420
uint64_t sz = F->isBitField() ? F->getBitWidthValue(C) : C.getTypeSize(F->getType());
1421+
#endif
14141422
string text = "bpf_dext_pkt(" + fn_args_[0]->getName().str() + ", (u64)" + Ref->getDecl()->getName().str() + "+"
14151423
+ to_string(ofs >> 3) + ", " + to_string(ofs & 0x7) + ", " + to_string(sz) + ")";
14161424
rewriter_.ReplaceText(expansionRange(E->getSourceRange()), text);

src/cc/json_map_decl_visitor.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ void BMapDeclVisitor::genJSONForField(FieldDecl *F) {
8686
#else
8787
result_ += ", [" + T->getSize().toString(10, false) + "]";
8888
#endif
89-
if (F->isBitField())
89+
if (F->isBitField()) {
90+
#if LLVM_VERSION_MAJOR >= 20
91+
result_ += ", " + to_string(F->getBitWidthValue());
92+
#else
9093
result_ += ", " + to_string(F->getBitWidthValue(C));
94+
#endif
95+
}
9196
result_ += "], ";
9297
}
9398

0 commit comments

Comments
 (0)