2626#include " clang/AST/StmtObjC.h"
2727#include " clang/AST/StmtOpenMP.h"
2828#include " clang/AST/TypeLoc.h"
29+ #include " llvm/Support/raw_ostream.h"
2930
3031extern clang::tooling::UnifiedPath DpctInstallPath;
3132namespace clang {
@@ -442,7 +443,7 @@ void ExprAnalysis::dispatch(const Stmt *Expression) {
442443 }
443444}
444445
445- bool isMathFunction (std::string Name) {
446+ bool isMathFunctionExceptRewriter (std::string Name) {
446447 static std::set<std::string> MathFunctions = {
447448#define ENTRY_RENAMED (SOURCEAPINAME, TARGETAPINAME ) SOURCEAPINAME,
448449#define ENTRY_RENAMED_NO_REWRITE (SOURCEAPINAME, TARGETAPINAME ) SOURCEAPINAME,
@@ -467,6 +468,31 @@ bool isMathFunction(std::string Name) {
467468 return MathFunctions.count (Name);
468469}
469470
471+ bool isMathFunction (std::string Name) {
472+ static std::set<std::string> MathFunctions = {
473+ #define ENTRY_RENAMED (SOURCEAPINAME, TARGETAPINAME ) SOURCEAPINAME,
474+ #define ENTRY_RENAMED_NO_REWRITE (SOURCEAPINAME, TARGETAPINAME ) SOURCEAPINAME,
475+ #define ENTRY_RENAMED_SINGLE (SOURCEAPINAME, TARGETAPINAME ) SOURCEAPINAME,
476+ #define ENTRY_RENAMED_DOUBLE (SOURCEAPINAME, TARGETAPINAME ) SOURCEAPINAME,
477+ #define ENTRY_EMULATED (SOURCEAPINAME, TARGETAPINAME ) SOURCEAPINAME,
478+ #define ENTRY_OPERATOR (APINAME, OPKIND ) APINAME,
479+ #define ENTRY_TYPECAST (APINAME ) APINAME,
480+ #define ENTRY_UNSUPPORTED (APINAME ) APINAME,
481+ #define ENTRY_REWRITE (APINAME ) APINAME,
482+ #include " APINamesMath.inc"
483+ #undef ENTRY_RENAMED
484+ #undef ENTRY_RENAMED_NO_REWRITE
485+ #undef ENTRY_RENAMED_SINGLE
486+ #undef ENTRY_RENAMED_DOUBLE
487+ #undef ENTRY_EMULATED
488+ #undef ENTRY_OPERATOR
489+ #undef ENTRY_TYPECAST
490+ #undef ENTRY_UNSUPPORTED
491+ #undef ENTRY_REWRITE
492+ };
493+ return MathFunctions.count (Name);
494+ }
495+
470496bool isCGAPI (std::string Name) {
471497 return MapNames::CooperativeGroupsAPISet.count (Name);
472498}
@@ -480,9 +506,10 @@ void ExprAnalysis::analyzeExpr(const DeclRefExpr *DRE) {
480506 clang::NestedNameSpecifier::SpecifierKind::Namespace ||
481507 Qualifier->getKind () ==
482508 clang::NestedNameSpecifier::SpecifierKind::NamespaceAlias;
483- bool IsSpecicalAPI = isMathFunction (DRE->getNameInfo ().getAsString ()) ||
484- isCGAPI (DRE->getNameInfo ().getAsString ());
485- // for thrust::log10 and thrust::sinh ...
509+ bool IsSpecicalAPI =
510+ isMathFunctionExceptRewriter (DRE->getNameInfo ().getAsString ()) ||
511+ isCGAPI (DRE->getNameInfo ().getAsString ());
512+ // for thrust::log10 and thrust::sinh ...
486513 if (Qualifier->getKind () == NestedNameSpecifier::TypeSpec)
487514 analyzeType (DRE->getQualifierLoc ().getTypeLoc ());
488515 // log10 is a math function
@@ -513,6 +540,12 @@ void ExprAnalysis::analyzeExpr(const DeclRefExpr *DRE) {
513540 DRE->getNameInfo ().getAsString ();
514541 }
515542 }
543+ } else if (const auto *FD = dyn_cast_or_null<FunctionDecl>(DRE->getDecl ())) {
544+ if (!isMathFunction (DRE->getNameInfo ().getAsString ()) &&
545+ !isCGAPI (DRE->getNameInfo ().getAsString ())) {
546+ llvm::raw_string_ostream OS (CTSName);
547+ FD->printQualifiedName (OS);
548+ }
516549 }
517550
518551 if (!CTSName.empty ()) {
0 commit comments