aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2011-06-15 02:47:03 +0000
committerNico Weber <nicolasweber@gmx.de>2011-06-15 02:47:03 +0000
commitcf739927f9b00c801867f620b04b79e3259c311f (patch)
tree1ffec6a2c434ce4baea801cedd3472702c14c372 /lib/Sema/SemaExpr.cpp
parentfa821380182f00eddfa536280b5a103c59e5c1c4 (diff)
Warn on "void f(int a[10]) { sizeof(a); }"
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133036 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 9f9c05244e..a2ad16145a 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -3160,6 +3160,20 @@ bool Sema::CheckUnaryExprOrTypeTraitOperand(Expr *Op,
Op->getSourceRange(), ExprKind))
return true;
+ if (ExprKind == UETT_SizeOf) {
+ if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(Op->IgnoreParens())) {
+ if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DeclRef->getFoundDecl())) {
+ QualType OType = PVD->getOriginalType();
+ QualType Type = PVD->getType();
+ if (Type->isPointerType() && OType->isArrayType()) {
+ Diag(Op->getExprLoc(), diag::warn_sizeof_array_param)
+ << Type << OType;
+ Diag(PVD->getLocation(), diag::note_declared_at);
+ }
+ }
+ }
+ }
+
return false;
}