<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 1 November 2016 at 10:13, Alex L <span dir="ltr"><<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On 31 October 2016 at 15:34, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><div><div class="m_6323222805761704405gmail-h5"><div dir="ltr">On Thu, Oct 27, 2016 at 6:40 AM Alex Lorenz via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: arphaman<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
Date: Thu Oct 27 08:30:51 2016<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
New Revision: 285289<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=285289&view=rev" rel="noreferrer" class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=285289&view=rev</a><br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
Log:<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
[Sema] -Wunused-variable warning for array variables should behave<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
similarly to scalar variables.<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
This commit makes the -Wunused-variable warning behaviour more consistent:<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
Now clang won't warn for array variables where it doesn't warn for scalar<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
variables.<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
rdar://24158862<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
Differential Revision: <a href="https://reviews.llvm.org/D25937" rel="noreferrer" class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg" target="_blank">https://reviews.llvm.org/D2593<wbr>7</a><br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
Modified:<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
    cfe/trunk/lib/Sema/SemaDecl.cp<wbr>p<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
    cfe/trunk/test/SemaCXX/warn-ev<wbr>erthing.cpp<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
    cfe/trunk/test/SemaCXX/warn-un<wbr>used-variables.cpp<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
Modified: cfe/trunk/lib/Sema/SemaDecl.cp<wbr>p<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=285289&r1=285288&r2=285289&view=diff" rel="noreferrer" class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Sema/SemaD<wbr>ecl.cpp?rev=285289&r1=285288&<wbr>r2=285289&view=diff</a><br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
--- cfe/trunk/lib/Sema/SemaDecl.cp<wbr>p (original)<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+++ cfe/trunk/lib/Sema/SemaDecl.cp<wbr>p Thu Oct 27 08:30:51 2016<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
@@ -1522,7 +1522,7 @@ static bool ShouldDiagnoseUnusedDecl(con<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
   if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
     // White-list anything with an __attribute__((unused)) type.<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
-    QualType Ty = VD->getType();<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+    const auto *Ty = VD->getType().getTypePtr();<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
     // Only look at the outermost level of typedef.<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
     if (const TypedefType *TT = Ty->getAs<TypedefType>()) {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
@@ -1535,6 +1535,10 @@ static bool ShouldDiagnoseUnusedDecl(con<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
     if (Ty->isIncompleteType() || Ty->isDependentType())<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
       return false;<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+    // Look at the element type to ensure that the warning behaviour is<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+    // consistent for both scalars and arrays.<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+    Ty = Ty->getBaseElementTypeUnsafe()<wbr>;<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
     if (const TagType *TT = Ty->getAs<TagType>()) {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
       const TagDecl *Tag = TT->getDecl();<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
       if (Tag->hasAttr<UnusedAttr>())<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
Modified: cfe/trunk/test/SemaCXX/warn-ev<wbr>erthing.cpp<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-everthing.cpp?rev=285289&r1=285288&r2=285289&view=diff" rel="noreferrer" class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/SemaCXX/<wbr>warn-everthing.cpp?rev=285289&<wbr>r1=285288&r2=285289&view=diff</a><br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
--- cfe/trunk/test/SemaCXX/warn-ev<wbr>erthing.cpp (original)<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+++ cfe/trunk/test/SemaCXX/warn-ev<wbr>erthing.cpp Thu Oct 27 08:30:51 2016<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
@@ -9,5 +9,5 @@ public:<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
 };<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
 void testPR12271() { // expected-warning {{no previous prototype for function 'testPR12271'}}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
-  PR12271 a[1][1]; // expected-warning {{unused variable 'a'}}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  PR12271 a[1][1];<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
 }<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
Modified: cfe/trunk/test/SemaCXX/warn-un<wbr>used-variables.cpp<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-variables.cpp?rev=285289&r1=285288&r2=285289&view=diff" rel="noreferrer" class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/SemaCXX/<wbr>warn-unused-variables.cpp?rev=<wbr>285289&r1=285288&r2=285289&<wbr>view=diff</a><br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
==============================<wbr>==============================<wbr>==================<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
--- cfe/trunk/test/SemaCXX/warn-un<wbr>used-variables.cpp (original)<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+++ cfe/trunk/test/SemaCXX/warn-un<wbr>used-variables.cpp Thu Oct 27 08:30:51 2016<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
@@ -150,3 +150,54 @@ namespace ctor_with_cleanups {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
 }<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
 #include "Inputs/warn-unused-variables.<wbr>h"<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+namespace arrayRecords {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+int total = 0;<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+class Adder {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg"></blockquote></div></div><div><br>Presumably this class could be a bit simpler - is it just about having a non-trivial ctor? or non-trivial dtor?<br><br>It'd be helpful to make the test as simple as possible to show what features are important to the diagnostic - rather than making the test look like real code by having functionality that's not required for testing.<br><br>(eg: you don't have to implement functions here - the code will not be linked or executed, just compiled for warnings in the test suite)<br><br>Potentially name the class by its purpose:<br><br>struct NonTriviallyDestructible {<br>  ~NonTriviallyDestructible();<br>};<br><br>and similar.</div></div></div></blockquote><div><br></div></div></div><div><div>Thanks for looking at this commit!</div><div>You're right about this particular class, it can be simpler, since it's testing a non-trivial door. When I started working on this patch I used the</div></div></div></div></div></blockquote><div><br></div><div>s/door/dtor/.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div> code from the bug report to reproduce this issue in the test case, and didn't simplify it further when I found out the cause.</div></div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br>(is it important that Adder and Foo are constructed with arguments/have ctor parameters? It's not clear to me from the test or code whether that's the case)</div></div></div></blockquote><div><br></div></span><div>No. Do you think I should simplify this test case in a separate commit?</div><div><br></div><div>Cheers,</div><div>Alex</div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> </div><div><div class="m_6323222805761704405gmail-h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+public:<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Adder(int x); // out of line below<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  ~Adder() {}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+};<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+Adder::Adder(int x) {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  total += x;<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+struct Foo {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  int x;<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Foo(int x) : x(x) {}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+};<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+struct S1 {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  S1();<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+};<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+void foo(int size) {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  S1 y; // no warning<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  S1 yarray[2]; // no warning<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  S1 dynArray[size]; // no warning<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  S1 nestedArray[1][2][3]; // no warning<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Adder scalerInFuncScope = 134; // no warning<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Adder arrayInFuncScope[] = { 135, 136 };  // no warning<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Adder nestedArrayInFuncScope[2][2] = { {1,2}, {3,4} }; // no warning<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Foo fooScalar = 1; // expected-warning {{unused variable 'fooScalar'}}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Foo fooArray[] = {1,2}; // expected-warning {{unused variable 'fooArray'}}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Foo fooNested[2][2] = { {1,2}, {3,4} }; // expected-warning {{unused variable 'fooNested'}}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+template<int N><br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+void bar() {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Adder scaler = 123; // no warning<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  Adder array[N] = {1,2}; // no warning<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+void test() {<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  foo(10);<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+  bar<2>();<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
+}<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
______________________________<wbr>_________________<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
cfe-commits mailing list<br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<a href="mailto:cfe-commits@lists.llvm.org" class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg" target="_blank">cfe-commits@lists.llvm.org</a><br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br class="m_6323222805761704405gmail-m_-6218020122892823026gmail_msg">
</blockquote></div></div></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>