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.

llvm-svn: 86673
This commit is contained in:
Zhongxing Xu 2009-11-10 07:52:53 +00:00
parent 17529ac0c5
commit 537db5d652
1 changed files with 9 additions and 1 deletions

View File

@ -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. "