Refactor check for builtin function

Create a new function to test whether a decl is a builtin function.
This commit is contained in:
John Bytheway 2019-03-07 21:54:51 +00:00 committed by Kim Gräsman
parent ca65ee68c2
commit 33b7ce7500
3 changed files with 19 additions and 8 deletions

View File

@ -39,6 +39,7 @@
#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
@ -1079,6 +1080,15 @@ bool DeclsAreInSameClass(const Decl* decl1, const Decl* decl2) {
return decl1->getDeclContext()->isRecord();
}
bool IsBuiltinFunction(const clang::NamedDecl* decl,
const std::string& symbol_name) {
if (const clang::IdentifierInfo* iden = decl->getIdentifier()) {
return iden->getBuiltinID() != 0 &&
!clang::Builtin::Context::isBuiltinFunc(symbol_name.c_str());
}
return false;
}
// --- Utilities for Type.
const Type* GetTypeOf(const Expr* expr) {

View File

@ -655,6 +655,10 @@ const clang::NamedDecl* GetNonfriendClassRedecl(const clang::NamedDecl* decl);
// same, and it's a class (or struct).
bool DeclsAreInSameClass(const clang::Decl* decl1, const clang::Decl* decl2);
// Returns true if the given decl/name is a builtin function
bool IsBuiltinFunction(const clang::NamedDecl* decl,
const std::string& symbol_name);
// --- Utilities for Type.
const clang::Type* GetTypeOf(const clang::Expr* expr);

View File

@ -1188,14 +1188,11 @@ void ProcessFullUse(OneUse* use,
return;
}
// A compiler builtin without a predefined header file (e.g. __builtin_..)
if (const clang::IdentifierInfo* iden = use->decl()->getIdentifier()) {
if (iden->getBuiltinID() != 0 &&
!clang::Builtin::Context::isBuiltinFunc(use->symbol_name().c_str())) {
VERRS(6) << "Ignoring use of " << use->symbol_name()
<< " (" << use->PrintableUseLoc() << "): built-in function\n";
use->set_ignore_use();
return;
}
if (IsBuiltinFunction(use->decl(), use->symbol_name()) {
VERRS(6) << "Ignoring use of " << use->symbol_name()
<< " (" << use->PrintableUseLoc() << "): built-in function\n";
use->set_ignore_use();
return;
}
// Special case for operators new/delete: Only treated as built-in if they
// are the default, non-placement versions.