[cfe-commits] r86673 - /cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Mon Nov 9 23:52:54 PST 2009
Author: zhongxingxu
Date: Tue Nov 10 01:52:53 2009
New Revision: 86673
URL: http://llvm.org/viewvc/llvm-project?rev=86673&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp
Modified: cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp?rev=86673&r1=86672&r2=86673&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckSizeofPointer.cpp Tue Nov 10 01:52:53 2009
@@ -49,7 +49,15 @@
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. "
More information about the cfe-commits
mailing list