11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 using namespace clang::ast_matchers;
21 AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
22 return !Node.isTriviallyCopyable();
26 void UndefinedMemoryManipulationCheck::registerMatchers(MatchFinder *
Finder) {
27 const auto NotTriviallyCopyableObject =
28 hasType(pointsTo(cxxRecordDecl(isNotTriviallyCopyable())));
32 Finder->addMatcher(callExpr(callee(functionDecl(hasAnyName(
33 "::memset",
"::memcpy",
"::memmove"))),
34 hasArgument(0, NotTriviallyCopyableObject))
41 callExpr(callee(functionDecl(hasAnyName(
"::memcpy",
"::memmove"))),
42 hasArgument(1, NotTriviallyCopyableObject))
47 void UndefinedMemoryManipulationCheck::check(
48 const MatchFinder::MatchResult &Result) {
49 if (
const auto *Destination = Result.Nodes.getNodeAs<CallExpr>(
"dest")) {
50 diag(Destination->getLocStart(),
"undefined behavior, destination "
51 "object is not TriviallyCopyable");
53 if (
const auto *Source = Result.Nodes.getNodeAs<CallExpr>(
"src")) {
54 diag(Source->getLocStart(),
"undefined behavior, source object is not "
std::unique_ptr< ast_matchers::MatchFinder > Finder
AST_MATCHER(VarDecl, isAsm)