summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2017-08-24 12:11:05 +0000
committerAlexander Kornienko <alexfh@google.com>2017-08-24 12:11:05 +0000
commit15ea4ebbb2aaa4cc0203850a8c0de64791484597 (patch)
tree329cbf0b72fe787f86eb09516a948e8d0c73ce54 /clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
parentc09a14eeb251988c8dbdb753d845436faddb82e1 (diff)
downloadbcm5719-llvm-15ea4ebbb2aaa4cc0203850a8c0de64791484597.tar.gz
bcm5719-llvm-15ea4ebbb2aaa4cc0203850a8c0de64791484597.zip
[clang-tidy] bugprone-undefined-memory-manipulation: include type into the message
Having the actual type in the message helps a lot understanding warnings in templates ;) + fix a false negative for type aliases. llvm-svn: 311651
Diffstat (limited to 'clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
index d234fa74abc..ebfe517dd07 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
@@ -26,7 +26,8 @@ AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
void UndefinedMemoryManipulationCheck::registerMatchers(MatchFinder *Finder) {
const auto NotTriviallyCopyableObject =
- hasType(pointsTo(cxxRecordDecl(isNotTriviallyCopyable())));
+ hasType(ast_matchers::hasCanonicalType(
+ pointsTo(cxxRecordDecl(isNotTriviallyCopyable()))));
// Check whether destination object is not TriviallyCopyable.
// Applicable to all three memory manipulation functions.
@@ -47,13 +48,21 @@ void UndefinedMemoryManipulationCheck::registerMatchers(MatchFinder *Finder) {
void UndefinedMemoryManipulationCheck::check(
const MatchFinder::MatchResult &Result) {
- if (const auto *Destination = Result.Nodes.getNodeAs<CallExpr>("dest")) {
- diag(Destination->getLocStart(), "undefined behavior, destination "
- "object is not TriviallyCopyable");
+ if (const auto *Call = Result.Nodes.getNodeAs<CallExpr>("dest")) {
+ QualType DestType = Call->getArg(0)->IgnoreImplicit()->getType();
+ if (!DestType->getPointeeType().isNull())
+ DestType = DestType->getPointeeType();
+ diag(Call->getLocStart(), "undefined behavior, destination object type %0 "
+ "is not TriviallyCopyable")
+ << DestType;
}
- if (const auto *Source = Result.Nodes.getNodeAs<CallExpr>("src")) {
- diag(Source->getLocStart(), "undefined behavior, source object is not "
- "TriviallyCopyable");
+ if (const auto *Call = Result.Nodes.getNodeAs<CallExpr>("src")) {
+ QualType SourceType = Call->getArg(1)->IgnoreImplicit()->getType();
+ if (!SourceType->getPointeeType().isNull())
+ SourceType = SourceType->getPointeeType();
+ diag(Call->getLocStart(),
+ "undefined behavior, source object type %0 is not TriviallyCopyable")
+ << SourceType;
}
}
OpenPOWER on IntegriCloud