summaryrefslogtreecommitdiffstats
path: root/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-01-13 21:52:01 +0000
committerAnna Zaks <ganna@apple.com>2012-01-13 21:52:01 +0000
commitd9b859a74ecaede23a78d37f364498102ef418c9 (patch)
tree4f63875d9e85449142ebc39904f06dd567ae2e15 /lib/AST/Decl.cpp
parent31cbe684302a5ccb001fa2131c0e4aeaa372f5c0 (diff)
Move identification of memory setting and copying functions (memset,
memcmp, strncmp,..) out of Sema and into FunctionDecl so that the logic could be reused in the analyzer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148142 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r--lib/AST/Decl.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index e6b3a74342..738414e021 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -2302,6 +2302,83 @@ SourceRange FunctionDecl::getSourceRange() const {
return SourceRange(getOuterLocStart(), EndRangeLoc);
}
+FunctionDecl::MemoryFunctionKind FunctionDecl::getMemoryFunctionKind() {
+ IdentifierInfo *FnInfo = getIdentifier();
+
+ if (!FnInfo)
+ return MFK_Invalid;
+
+ // Builtin handling.
+ switch (getBuiltinID()) {
+ case Builtin::BI__builtin_memset:
+ case Builtin::BI__builtin___memset_chk:
+ case Builtin::BImemset:
+ return MFK_Memset;
+
+ case Builtin::BI__builtin_memcpy:
+ case Builtin::BI__builtin___memcpy_chk:
+ case Builtin::BImemcpy:
+ return MFK_Memcpy;
+
+ case Builtin::BI__builtin_memmove:
+ case Builtin::BI__builtin___memmove_chk:
+ case Builtin::BImemmove:
+ return MFK_Memmove;
+
+ case Builtin::BIstrlcpy:
+ return MFK_Strlcpy;
+ case Builtin::BIstrlcat:
+ return MFK_Strlcat;
+
+ case Builtin::BI__builtin_memcmp:
+ return MFK_Memcmp;
+
+ case Builtin::BI__builtin_strncpy:
+ case Builtin::BI__builtin___strncpy_chk:
+ case Builtin::BIstrncpy:
+ return MFK_Strncpy;
+
+ case Builtin::BI__builtin_strncmp:
+ return MFK_Strncmp;
+
+ case Builtin::BI__builtin_strncasecmp:
+ return MFK_Strncasecmp;
+
+ case Builtin::BI__builtin_strncat:
+ case Builtin::BIstrncat:
+ return MFK_Strncat;
+
+ case Builtin::BI__builtin_strndup:
+ case Builtin::BIstrndup:
+ return MFK_Strndup;
+
+ default:
+ if (getLinkage() == ExternalLinkage &&
+ (!getASTContext().getLangOptions().CPlusPlus || isExternC())) {
+ if (FnInfo->isStr("memset"))
+ return MFK_Memset;
+ else if (FnInfo->isStr("memcpy"))
+ return MFK_Memcpy;
+ else if (FnInfo->isStr("memmove"))
+ return MFK_Memmove;
+ else if (FnInfo->isStr("memcmp"))
+ return MFK_Memcmp;
+ else if (FnInfo->isStr("strncpy"))
+ return MFK_Strncpy;
+ else if (FnInfo->isStr("strncmp"))
+ return MFK_Strncmp;
+ else if (FnInfo->isStr("strncasecmp"))
+ return MFK_Strncasecmp;
+ else if (FnInfo->isStr("strncat"))
+ return MFK_Strncat;
+ else if (FnInfo->isStr("strndup"))
+ return MFK_Strndup;
+ }
+ break;
+ }
+ return MFK_Invalid;
+}
+
//===----------------------------------------------------------------------===//
// FieldDecl Implementation
//===----------------------------------------------------------------------===//