From 92d19977d2a06362f3169f8da8676f6ffadafc4e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 13 Jan 2019 12:29:03 +0100 Subject: [PATCH] handle rename of getLocStart to getBeginLoc and getLocEnd to getEndLoc The old names were deprecated in clang revision 339403 and removed in clang revision 341573. Signed-off-by: Sven Verdoolaege --- Makefile.am | 1 + clang_compatibility.h | 30 ++++++++++++++++++++++++++++++ killed_locals.cc | 7 ++++--- m4/ax_detect_clang.m4 | 9 +++++++++ pet.cc | 5 +++-- scan.cc | 17 +++++++++-------- 6 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 clang_compatibility.h diff --git a/Makefile.am b/Makefile.am index 821d225..1913558 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,6 +53,7 @@ libpet_la_SOURCES = \ aff.c \ array.h \ array.c \ + clang_compatibility.h \ clang.h \ clang.cc \ context.h \ diff --git a/clang_compatibility.h b/clang_compatibility.h new file mode 100644 index 0000000..cebdef9 --- /dev/null +++ b/clang_compatibility.h @@ -0,0 +1,30 @@ +#ifndef PET_CLANG_COMPATIBILITY_H +#define PET_CLANG_COMPATIBILITY_H + +#include "config.h" + +#ifdef HAVE_BEGIN_END_LOC +template +inline clang::SourceLocation begin_loc(T *decl) +{ + return decl->getBeginLoc(); +} +template +inline clang::SourceLocation end_loc(T *decl) +{ + return decl->getEndLoc(); +} +#else +template +inline clang::SourceLocation begin_loc(T *decl) +{ + return decl->getLocStart(); +} +template +inline clang::SourceLocation end_loc(T *decl) +{ + return decl->getLocEnd(); +} +#endif + +#endif diff --git a/killed_locals.cc b/killed_locals.cc index 7e552a6..e93a7ff 100644 --- a/killed_locals.cc +++ b/killed_locals.cc @@ -34,6 +34,7 @@ #include "config.h" #include "clang.h" +#include "clang_compatibility.h" #include "killed_locals.h" using namespace std; @@ -89,7 +90,7 @@ void pet_killed_locals::add_locals(DeclStmt *stmt) */ void pet_killed_locals::set_addr_end(UnaryOperator *expr) { - addr_end = getExpansionOffset(SM, expr->getLocEnd()); + addr_end = getExpansionOffset(SM, end_loc(expr)); } /* Given an expression of type ArraySubscriptExpr or DeclRefExpr, @@ -139,11 +140,11 @@ bool pet_killed_locals::check_decl_in_expr(Expr *expr) decl = ref->getDecl(); if (locals.find(decl) == locals.end()) return true; - loc = getExpansionOffset(SM, expr->getLocStart()); + loc = getExpansionOffset(SM, begin_loc(expr)); if (loc <= expr_end) return true; - expr_end = getExpansionOffset(SM, ref->getLocEnd()); + expr_end = getExpansionOffset(SM, end_loc(ref)); depth = pet_clang_array_depth(expr->getType()); if (loc >= scop_end || loc <= old_addr_end || depth != 0) locals.erase(decl); diff --git a/m4/ax_detect_clang.m4 b/m4/ax_detect_clang.m4 index 2c7a66d..43e84ce 100644 --- a/m4/ax_detect_clang.m4 +++ b/m4/ax_detect_clang.m4 @@ -210,6 +210,15 @@ AC_TRY_COMPILE([ Clang->setInvocation(std::make_shared(*invocation)); ], [AC_DEFINE([SETINVOCATION_TAKES_SHARED_PTR], [], [Defined if CompilerInstance::setInvocation takes a shared_ptr])]) +AC_TRY_COMPILE([ + #include +], [ + clang::FunctionDecl *fd; + fd->getBeginLoc(); + fd->getEndLoc(); +], + [AC_DEFINE([HAVE_BEGIN_END_LOC], [], + [Define if getBeginLoc and getEndLoc should be used])]) AC_LANG_POP CPPFLAGS="$SAVE_CPPFLAGS" diff --git a/pet.cc b/pet.cc index b2cc5a4..5e2a0a7 100644 --- a/pet.cc +++ b/pet.cc @@ -90,6 +90,7 @@ #include +#include "clang_compatibility.h" #include "id.h" #include "options.h" #include "scan.h" @@ -661,8 +662,8 @@ struct PetASTConsumer : public ASTConsumer { if (scops.list.size() == 0) return; - start = SM.getFileOffset(fd->getLocStart()); - end = SM.getFileOffset(fd->getLocEnd()); + start = SM.getFileOffset(begin_loc(fd)); + end = SM.getFileOffset(end_loc(fd)); for (it = scops.list.begin(); it != scops.list.end(); ++it) { ScopLoc loc = *it; diff --git a/scan.cc b/scan.cc index 460ee82..ece2b07 100644 --- a/scan.cc +++ b/scan.cc @@ -55,6 +55,7 @@ #include "aff.h" #include "array.h" +#include "clang_compatibility.h" #include "clang.h" #include "context.h" #include "expr.h" @@ -2236,10 +2237,10 @@ __isl_give pet_tree *PetScan::extract(StmtRange stmt_range, bool block, if (options->autodetect) { if (tree_i) { range_end = getExpansionOffset(SM, - child->getLocEnd()); + end_loc(child)); if (pet_tree_block_n_child(tree) == 0) range_start = getExpansionOffset(SM, - child->getLocStart()); + begin_loc(child)); tree = pet_tree_block_add_child(tree, tree_i); } else { partial_range = true; @@ -2547,8 +2548,8 @@ struct pet_scop *PetScan::scan(Stmt *stmt) unsigned start_off, end_off; pet_tree *tree; - start_off = getExpansionOffset(SM, stmt->getLocStart()); - end_off = getExpansionOffset(SM, stmt->getLocEnd()); + start_off = getExpansionOffset(SM, begin_loc(stmt)); + end_off = getExpansionOffset(SM, end_loc(stmt)); if (start_off > loc.end) return NULL; @@ -2564,8 +2565,8 @@ struct pet_scop *PetScan::scan(Stmt *stmt) Stmt *child = *start; if (!child) continue; - start_off = getExpansionOffset(SM, child->getLocStart()); - end_off = getExpansionOffset(SM, child->getLocEnd()); + start_off = getExpansionOffset(SM, begin_loc(child)); + end_off = getExpansionOffset(SM, end_loc(child)); if (start_off < loc.start && end_off >= loc.end) return scan(child); if (start_off >= loc.start) @@ -2581,7 +2582,7 @@ struct pet_scop *PetScan::scan(Stmt *stmt) StmtIterator end; for (end = start; end != stmt->child_end(); ++end) { Stmt *child = *end; - start_off = SM.getFileOffset(child->getLocStart()); + start_off = SM.getFileOffset(begin_loc(child)); if (start_off >= loc.end) break; } @@ -3330,7 +3331,7 @@ struct pet_scop *PetScan::scan(FunctionDecl *fd) */ void PetScan::set_current_stmt(Stmt *stmt) { - SourceLocation loc = stmt->getLocStart(); + SourceLocation loc = begin_loc(stmt); SourceManager &SM = PP.getSourceManager(); last_line = current_line; -- 2.11.4.GIT