summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2016-10-27 13:30:51 +0000
committerAlex Lorenz <arphaman@gmail.com>2016-10-27 13:30:51 +0000
commitba5032c9cf876e08eb5d6eac37c34f93ba16e1b3 (patch)
tree46bfff6fb2163cf229604ece50ba7a6c0c5f478d /clang/lib
parentb49a3d3390714a179dd7b5d3b067e11bc10c40b1 (diff)
downloadbcm5719-llvm-ba5032c9cf876e08eb5d6eac37c34f93ba16e1b3.tar.gz
bcm5719-llvm-ba5032c9cf876e08eb5d6eac37c34f93ba16e1b3.zip
[Sema] -Wunused-variable warning for array variables should behave
similarly to scalar variables. This commit makes the -Wunused-variable warning behaviour more consistent: Now clang won't warn for array variables where it doesn't warn for scalar variables. rdar://24158862 Differential Revision: https://reviews.llvm.org/D25937 llvm-svn: 285289
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c8973ae100e..a94ed532944 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1522,7 +1522,7 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
// White-list anything with an __attribute__((unused)) type.
- QualType Ty = VD->getType();
+ const auto *Ty = VD->getType().getTypePtr();
// Only look at the outermost level of typedef.
if (const TypedefType *TT = Ty->getAs<TypedefType>()) {
@@ -1535,6 +1535,10 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
if (Ty->isIncompleteType() || Ty->isDependentType())
return false;
+ // Look at the element type to ensure that the warning behaviour is
+ // consistent for both scalars and arrays.
+ Ty = Ty->getBaseElementTypeUnsafe();
+
if (const TagType *TT = Ty->getAs<TagType>()) {
const TagDecl *Tag = TT->getDecl();
if (Tag->hasAttr<UnusedAttr>())
OpenPOWER on IntegriCloud