File bcc-fix-compilation-error-with-latest-llvm.patch of Package bcc.15364

From 806627e33a718d70e5465b35c2956a5a9e4d9af9 Mon Sep 17 00:00:00 2001
From: Yonghong Song <yhs@fb.com>
Date: Wed, 2 May 2018 10:32:31 -0700
Subject: [PATCH] fix compilation error with latest llvm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 <yhs@fb.com>
---
 src/cc/frontends/clang/b_frontend_action.cc | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc
index 9382f639..05b37bcb 100644
--- a/src/cc/frontends/clang/b_frontend_action.cc
+++ b/src/cc/frontends/clang/b_frontend_action.cc
@@ -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>
@@ -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>
-- 
2.16.4

openSUSE Build Service is sponsored by