diff --git a/clang/lib/Analysis/CheckSizeofPointer.cpp b/clang/lib/Analysis/CheckSizeofPointer.cpp index 827c512b7545..1aab3c973d6e 100644 --- a/clang/lib/Analysis/CheckSizeofPointer.cpp +++ b/clang/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(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. "