<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 1, 2016 at 3:13 AM Alex L <<a href="mailto:arphaman@gmail.com">arphaman@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg">On 31 October 2016 at 15:34, David Blaikie <span dir="ltr" class="gmail_msg"><<a href="mailto:dblaikie@gmail.com" class="gmail_msg" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" 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" class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"><div class="m_4640351061711220423gmail-h5 gmail_msg"><div dir="ltr" class="gmail_msg">On Thu, Oct 27, 2016 at 6:40 AM Alex Lorenz via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" class="gmail_msg" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" 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_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
Date: Thu Oct 27 08:30:51 2016<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
New Revision: 285289<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=285289&view=rev" rel="noreferrer" class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=285289&view=rev</a><br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
Log:<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
[Sema] -Wunused-variable warning for array variables should behave<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
similarly to scalar variables.<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
This commit makes the -Wunused-variable warning behaviour more consistent:<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
Now clang won't warn for array variables where it doesn't warn for scalar<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
variables.<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
rdar://24158862<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
Differential Revision: <a href="https://reviews.llvm.org/D25937" rel="noreferrer" class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg" target="_blank">https://reviews.llvm.org/D25937</a><br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
Modified:<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
cfe/trunk/lib/Sema/SemaDecl.cpp<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
cfe/trunk/test/SemaCXX/warn-everthing.cpp<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
cfe/trunk/test/SemaCXX/warn-unused-variables.cpp<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_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_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=285289&r1=285288&r2=285289&view=diff</a><br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
==============================================================================<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct 27 08:30:51 2016<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
@@ -1522,7 +1522,7 @@ static bool ShouldDiagnoseUnusedDecl(con<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
// White-list anything with an __attribute__((unused)) type.<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
- QualType Ty = VD->getType();<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ const auto *Ty = VD->getType().getTypePtr();<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
// Only look at the outermost level of typedef.<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
if (const TypedefType *TT = Ty->getAs<TypedefType>()) {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
@@ -1535,6 +1535,10 @@ static bool ShouldDiagnoseUnusedDecl(con<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
if (Ty->isIncompleteType() || Ty->isDependentType())<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
return false;<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ // Look at the element type to ensure that the warning behaviour is<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ // consistent for both scalars and arrays.<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Ty = Ty->getBaseElementTypeUnsafe();<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
if (const TagType *TT = Ty->getAs<TagType>()) {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
const TagDecl *Tag = TT->getDecl();<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
if (Tag->hasAttr<UnusedAttr>())<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
Modified: cfe/trunk/test/SemaCXX/warn-everthing.cpp<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_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_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-everthing.cpp?rev=285289&r1=285288&r2=285289&view=diff</a><br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
==============================================================================<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
--- cfe/trunk/test/SemaCXX/warn-everthing.cpp (original)<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+++ cfe/trunk/test/SemaCXX/warn-everthing.cpp Thu Oct 27 08:30:51 2016<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
@@ -9,5 +9,5 @@ public:<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
};<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
void testPR12271() { // expected-warning {{no previous prototype for function 'testPR12271'}}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
- PR12271 a[1][1]; // expected-warning {{unused variable 'a'}}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ PR12271 a[1][1];<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
Modified: cfe/trunk/test/SemaCXX/warn-unused-variables.cpp<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_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_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-variables.cpp?rev=285289&r1=285288&r2=285289&view=diff</a><br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
==============================================================================<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
--- cfe/trunk/test/SemaCXX/warn-unused-variables.cpp (original)<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+++ cfe/trunk/test/SemaCXX/warn-unused-variables.cpp Thu Oct 27 08:30:51 2016<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
@@ -150,3 +150,54 @@ namespace ctor_with_cleanups {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
#include "Inputs/warn-unused-variables.h"<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+namespace arrayRecords {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+int total = 0;<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+class Adder {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg"></blockquote></div></div><div class="gmail_msg"><br class="gmail_msg">Presumably this class could be a bit simpler - is it just about having a non-trivial ctor? or non-trivial dtor?<br class="gmail_msg"><br class="gmail_msg">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 class="gmail_msg"><br class="gmail_msg">(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 class="gmail_msg"><br class="gmail_msg">Potentially name the class by its purpose:<br class="gmail_msg"><br class="gmail_msg">struct NonTriviallyDestructible {<br class="gmail_msg"> ~NonTriviallyDestructible();<br class="gmail_msg">};<br class="gmail_msg"><br class="gmail_msg">and similar.</div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"><div class="gmail_msg">Thanks for looking at this commit!</div><div class="gmail_msg">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 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></div></div></div></blockquote><div><br></div><div>*nod* no worries - it's certainly not uncommon</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"> </div><blockquote class="gmail_quote gmail_msg" 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" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"><br class="gmail_msg">(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 class="gmail_msg"><br class="gmail_msg"></div></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">No. Do you think I should simplify this test case in a separate commit?</div></div></div></div></blockquote><div><br></div><div>That'd be great if you could simplify it down to what seems to be the essentials!</div><div><br></div><div>- Dave</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Cheers,</div><div class="gmail_msg">Alex</div></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"> </div><blockquote class="gmail_quote gmail_msg" 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" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"> </div><div class="gmail_msg"><div class="m_4640351061711220423gmail-h5 gmail_msg"><blockquote class="gmail_quote gmail_msg" 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_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Adder(int x); // out of line below<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ ~Adder() {}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+};<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+Adder::Adder(int x) {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ total += x;<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+struct Foo {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ int x;<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Foo(int x) : x(x) {}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+};<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+struct S1 {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ S1();<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+};<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+void foo(int size) {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ S1 y; // no warning<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ S1 yarray[2]; // no warning<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ S1 dynArray[size]; // no warning<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ S1 nestedArray[1][2][3]; // no warning<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Adder scalerInFuncScope = 134; // no warning<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Adder arrayInFuncScope[] = { 135, 136 }; // no warning<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Adder nestedArrayInFuncScope[2][2] = { {1,2}, {3,4} }; // no warning<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Foo fooScalar = 1; // expected-warning {{unused variable 'fooScalar'}}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Foo fooArray[] = {1,2}; // expected-warning {{unused variable 'fooArray'}}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Foo fooNested[2][2] = { {1,2}, {3,4} }; // expected-warning {{unused variable 'fooNested'}}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+template<int N><br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+void bar() {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Adder scaler = 123; // no warning<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ Adder array[N] = {1,2}; // no warning<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+void test() {<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ foo(10);<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+ bar<2>();<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
+}<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
_______________________________________________<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
cfe-commits mailing list<br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<a href="mailto:cfe-commits@lists.llvm.org" class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg" target="_blank">cfe-commits@lists.llvm.org</a><br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br class="m_4640351061711220423gmail-m_-6218020122892823026gmail_msg gmail_msg">
</blockquote></div></div></div></div>
</blockquote></div></div></div></blockquote></div></div>