aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/CheckSizeofPointer.cpp
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2009-11-10 07:52:53 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2009-11-10 07:52:53 +0000
commit37e9c47b6a6650b81c9796d2e46eb3ad6a0e16a0 (patch)
treea7e6feb35fae0c83cc1d164402b9a698d3f8b46f /lib/Analysis/CheckSizeofPointer.cpp
parent380dd759b33fd059b1aa7dbd85f8e66ca32f7bdc (diff)
SizeofPointerChecker: Many false positives have the form 'sizeof *p'.
This is reasonable because people know what they are doing when they intentionally dereference the pointer. So now we only emit warning when a pointer variable is use literally. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86673 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CheckSizeofPointer.cpp')
-rw-r--r--lib/Analysis/CheckSizeofPointer.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Analysis/CheckSizeofPointer.cpp b/lib/Analysis/CheckSizeofPointer.cpp
index 827c512b75..1aab3c973d 100644
--- a/lib/Analysis/CheckSizeofPointer.cpp
+++ b/lib/Analysis/CheckSizeofPointer.cpp
@@ -49,7 +49,15 @@ void WalkAST::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
QualType T = E->getTypeOfArgument();
if (T->isPointerType()) {
- SourceRange R = E->getArgumentExpr()->getSourceRange();
+
+ // Many false positives have the form 'sizeof *p'. This is reasonable
+ // because people know what they are doing when they intentionally
+ // dereference the pointer.
+ Expr *ArgEx = E->getArgumentExpr();
+ if (!isa<DeclRefExpr>(ArgEx))
+ return;
+
+ SourceRange R = ArgEx->getSourceRange();
BR.EmitBasicReport("Potential unintended use of sizeof() on pointer type",
"Logic",
"The code calls sizeof() on a pointer type. "