From ee9ec8f052875b5f1f889c8469f4124bcd65f96d Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 20 Aug 2015 15:06:24 +0200 Subject: [PATCH] extract out pet_clang_find_function_decl_with_body This will be reused to check for function bodies to inline. Signed-off-by: Sven Verdoolaege --- clang.cc | 21 +++++++++++++++++++++ clang.h | 3 +++ scan.cc | 13 ++----------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/clang.cc b/clang.cc index 4b679ec..106394d 100644 --- a/clang.cc +++ b/clang.cc @@ -95,3 +95,24 @@ int pet_clang_get_type_size(QualType qt, ASTContext &ast_context) return size; } + +/* Return the FunctionDecl that refers to the same function + * that "fd" refers to, but that has a body. + * Return NULL if no such FunctionDecl is available. + * + * It is not clear why hasBody takes a reference to a const FunctionDecl *. + * It seems that it is possible to directly use the iterators to obtain + * a non-const pointer. + * Since we are not going to use the pointer to modify anything anyway, + * it seems safe to drop the constness. The alternative would be to + * modify a lot of other functions to include const qualifiers. + */ +FunctionDecl *pet_clang_find_function_decl_with_body(FunctionDecl *fd) +{ + const FunctionDecl *def; + + if (!fd->hasBody(def)) + return NULL; + + return const_cast(def); +} diff --git a/clang.h b/clang.h index 79b73dd..d07b6b8 100644 --- a/clang.h +++ b/clang.h @@ -2,6 +2,7 @@ #define PET_CLANG_H #include +#include #include #include @@ -9,5 +10,7 @@ clang::QualType pet_clang_base_type(clang::QualType qt); clang::RecordDecl *pet_clang_record_decl(clang::QualType T); clang::Expr *pet_clang_strip_casts(clang::Expr *expr); int pet_clang_get_type_size(clang::QualType qt, clang::ASTContext &ast_context); +clang::FunctionDecl *pet_clang_find_function_decl_with_body( + clang::FunctionDecl *fd); #endif diff --git a/scan.cc b/scan.cc index 34ec25c..8efca4f 100644 --- a/scan.cc +++ b/scan.cc @@ -2129,27 +2129,18 @@ __isl_give pet_function_summary *PetScan::get_summary(FunctionDecl *fd) * Even if a function body is available, "fd" itself may point * to a declaration without function body. We therefore first * replace it by the declaration that comes with a body (if any). - * - * It is not clear why hasBody takes a reference to a const FunctionDecl *. - * It seems that it is possible to directly use the iterators to obtain - * a non-const pointer. - * Since we are not going to use the pointer to modify anything anyway, - * it seems safe to drop the constness. The alternative would be to - * modify a lot of other functions to include const qualifiers. */ __isl_give pet_expr *PetScan::set_summary(__isl_take pet_expr *expr, FunctionDecl *fd) { pet_function_summary *summary; - const FunctionDecl *def; if (!expr) return NULL; - if (!fd->hasBody(def)) + fd = pet_clang_find_function_decl_with_body(fd); + if (!fd) return expr; - fd = const_cast(def); - summary = get_summary(fd); expr = pet_expr_call_set_summary(expr, summary); -- 2.11.4.GIT