Skip to content

Commit

Permalink
fix compilation error with latest llvm
Browse files Browse the repository at this point in the history
The clang commit https://reviews.llvm.org/rL331155
changed the clang::SourceManager function prototype
   SourceRange getExpansionRange(SourceRange Range)
to
   CharSourceRange getExpansionRange(SourceRange Range)
and caused the following compilation failure:

  /home/yhs/work/bcc/src/cc/frontends/clang/b_frontend_action.cc:
  In member function ‘clang::SourceRange ebpf::ProbeVisitor::expansionRange(clang::SourceRange)’:
  /home/yhs/work/bcc/src/cc/frontends/clang/b_frontend_action.cc:267:58:
  error: could not convert ‘(&(&((ebpf::ProbeVisitor *)this)->ebpf::ProbeVisitor::rewriter_)
         ->clang::Rewriter::getSourceMgr())->clang::SourceManager::getExpansionRange(range)’
  from ‘clang::CharSourceRange’ to ‘clang::SourceRange’
     return rewriter_.getSourceMgr().getExpansionRange(range);
                                                            ^
  ...

It is hard to find a compatible change which works
for both old llvm and the latest change. So this patch
just fixed the problem for clang 7.0.0 and the old code
is used for clang 6.x and lower.

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song committed May 2, 2018
1 parent 01c843e commit 806627e
Showing 1 changed file with 8 additions and 0 deletions.
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 @@ -302,7 +302,11 @@ bool ProbeVisitor::IsContextMemberExpr(Expr *E) {

SourceRange
ProbeVisitor::expansionRange(SourceRange range) {
#if LLVM_MAJOR_VERSION >= 7
return rewriter_.getSourceMgr().getExpansionRange(range).getAsRange();
#else
return rewriter_.getSourceMgr().getExpansionRange(range);
#endif
}

template <unsigned N>
Expand Down Expand Up @@ -695,7 +699,11 @@ bool BTypeVisitor::VisitImplicitCastExpr(ImplicitCastExpr *E) {

SourceRange
BTypeVisitor::expansionRange(SourceRange range) {
#if LLVM_MAJOR_VERSION >= 7
return rewriter_.getSourceMgr().getExpansionRange(range).getAsRange();
#else
return rewriter_.getSourceMgr().getExpansionRange(range);
#endif
}

template <unsigned N>
Expand Down

0 comments on commit 806627e

Please sign in to comment.