Skip to content

Commit

Permalink
Fix llvm20 compilation error (#5194)
Browse files Browse the repository at this point in the history
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 <yonghong.song@linux.dev>
  • Loading branch information
yonghong-song authored Jan 19, 2025
1 parent 68710c4 commit 1832c03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,11 @@ bool BTypeVisitor::VisitBinaryOperator(BinaryOperator *E) {
}

uint64_t ofs = C.getFieldOffset(F);
#if LLVM_VERSION_MAJOR >= 20
uint64_t sz = F->isBitField() ? F->getBitWidthValue() : C.getTypeSize(F->getType());
#else
uint64_t sz = F->isBitField() ? F->getBitWidthValue(C) : C.getTypeSize(F->getType());
#endif
string base = rewriter_.getRewrittenText(expansionRange(Base->getSourceRange()));
string text = "bpf_dins_pkt(" + fn_args_[0]->getName().str() + ", (u64)" + base + "+" + to_string(ofs >> 3)
+ ", " + to_string(ofs & 0x7) + ", " + to_string(sz) + ",";
Expand Down Expand Up @@ -1410,7 +1414,11 @@ bool BTypeVisitor::VisitImplicitCastExpr(ImplicitCastExpr *E) {
return false;
}
uint64_t ofs = C.getFieldOffset(F);
#if LLVM_VERSION_MAJOR >= 20
uint64_t sz = F->isBitField() ? F->getBitWidthValue() : C.getTypeSize(F->getType());
#else
uint64_t sz = F->isBitField() ? F->getBitWidthValue(C) : C.getTypeSize(F->getType());
#endif
string text = "bpf_dext_pkt(" + fn_args_[0]->getName().str() + ", (u64)" + Ref->getDecl()->getName().str() + "+"
+ to_string(ofs >> 3) + ", " + to_string(ofs & 0x7) + ", " + to_string(sz) + ")";
rewriter_.ReplaceText(expansionRange(E->getSourceRange()), text);
Expand Down
7 changes: 6 additions & 1 deletion src/cc/json_map_decl_visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ void BMapDeclVisitor::genJSONForField(FieldDecl *F) {
#else
result_ += ", [" + T->getSize().toString(10, false) + "]";
#endif
if (F->isBitField())
if (F->isBitField()) {
#if LLVM_VERSION_MAJOR >= 20
result_ += ", " + to_string(F->getBitWidthValue());
#else
result_ += ", " + to_string(F->getBitWidthValue(C));
#endif
}
result_ += "], ";
}

Expand Down

0 comments on commit 1832c03

Please sign in to comment.