• yonghong-song's avatar
    fix compilation error with latest llvm/clang (#2068) · 1f6ef8ce
    yonghong-song authored
    With latest llvm/clang, we have the following compilation errors:
    
        /home/yhs/work/bcc2/src/cc/frontends/clang/b_frontend_action.cc:
          In member function ‘bool ebpf::BTypeVisitor::VisitVarDecl(clang::VarDecl*)’:
        /home/yhs/work/bcc2/src/cc/frontends/clang/b_frontend_action.cc:1130:52:
          error: no matching function for call to ‘clang::Expr::EvaluateAsInt(llvm::APSInt&, clang::ASTContext&)’
                   if (I->getInit(idx)->EvaluateAsInt(res, C)) {
                                                        ^
        /home/yhs/work/bcc2/src/cc/frontends/clang/b_frontend_action.cc:1130:52: note: candidate is:
        In file included from /home/yhs/work/llvm/build/install/include/clang/AST/Attr.h:19:0,
                     from /home/yhs/work/llvm/build/install/include/clang/AST/TypeLoc.h:18,
                     from /home/yhs/work/llvm/build/install/include/clang/AST/ASTTypeTraits.h:24,
                     from /home/yhs/work/llvm/build/install/include/clang/AST/ASTContext.h:18,
                     from /home/yhs/work/bcc2/src/cc/frontends/clang/b_frontend_action.cc:23:
        /home/yhs/work/llvm/build/install/include/clang/AST/Expr.h:604:8:
          note: bool clang::Expr::EvaluateAsInt(clang::Expr::EvalResult&, const clang::ASTContext&,
                  clang::Expr::SideEffectsKind) const
           bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
            ^
    
    The error is introduced by the following commit:
    https://reviews.llvm.org/rL348053
    
    Basically, the clang FieldDecl method EvaluateAsInt signature got
    changed and there is no compatible way in the llvm/clang
    to also work in the old versions. So this patch just provided
    a new implementation to get field value for llvm version 8 and later.
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    1f6ef8ce
b_frontend_action.cc 53.5 KB