www.digitalmars.com         C & C++   DMDScript  

D.gnu - Unused variables warning with -Wextra flag

reply "bdsatish" <bdsatish gmail.com> writes:
Hi,

Some warning messages are being "leaked" from GDC's source code 
into end-user's code. I think this shouldn't happen and hence, is 
a bug.

```
// example.d
import std.string;

void main()
{
   format("Hello World");
}

```
Here's the output:

```
[shell]$ gdc -Wextra example.d
$INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function 'decode':
$INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: 
uninitialized variable 'result'
$INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function 'decode':
$INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: 
uninitialized variable 'result'
$INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function 'decode':
$INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: 
uninitialized variable 'result'
example.d: In function 
'std.format.formattedWrite!(Appender!(string), char, 
).formattedWrite':
$INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: 
'iftmp.16' may be used uninitialized in this function
$INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: 
'iftmp.17' may be used uninitialized in this function
```

So, all these warnings seem to be from GDC. Is there a way to 
supress these warnings? (for GDC's libs, not my own code).


--Satish
Feb 28 2013
next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--001636b14cd0815fd904d6cfcddf
Content-Type: text/plain; charset=ISO-8859-1

On Feb 28, 2013 6:55 PM, "bdsatish" <bdsatish gmail.com> wrote:
 Hi,

 Some warning messages are being "leaked" from GDC's source code into

 ```
 // example.d
 import std.string;

 void main()
 {
   format("Hello World");
 }

 ```
 Here's the output:

 ```
 [shell]$ gdc -Wextra example.d
 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function 'decode':
 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized

 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function 'decode':
 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized

 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function 'decode':
 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized

 example.d: In function 'std.format.formattedWrite!(Appender!(string),

 $INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: 'iftmp.16' may

 $INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: 'iftmp.17' may

 ```

 So, all these warnings seem to be from GDC. Is there a way to supress

 --Satish

The iftmp's shouldn't be emitted, the others though are because it's a template instantiated into the module you are compiling. Regards -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --001636b14cd0815fd904d6cfcddf Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <p><br> On Feb 28, 2013 6:55 PM, &quot;bdsatish&quot; &lt;<a href=3D"mailto:bdsatis= h gmail.com">bdsatish gmail.com</a>&gt; wrote:<br> &gt;<br> &gt; Hi,<br> &gt;<br> &gt; Some warning messages are being &quot;leaked&quot; from GDC&#39;s sour= ce code into end-user&#39;s code. I think this shouldn&#39;t happen and hen= ce, is a bug.<br> &gt;<br> &gt; ```<br> &gt; // example.d<br> &gt; import std.string;<br> &gt;<br> &gt; void main()<br> &gt; {<br> &gt; =A0 format(&quot;Hello World&quot;);<br> &gt; }<br> &gt;<br> &gt; ```<br> &gt; Here&#39;s the output:<br> &gt;<br> &gt; ```<br> &gt; [shell]$ gdc -Wextra example.d<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function &#39;decode&#39= ;:<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized = variable &#39;result&#39;<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function &#39;decode&#39= ;:<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized = variable &#39;result&#39;<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function &#39;decode&#39= ;:<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized = variable &#39;result&#39;<br> &gt; example.d: In function &#39;std.format.formattedWrite!(Appender!(strin= g), char, ).formattedWrite&#39;:<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: &#39;iftmp.= 16&#39; may be used uninitialized in this function<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: &#39;iftmp.= 17&#39; may be used uninitialized in this function<br> &gt; ```<br> &gt;<br> &gt; So, all these warnings seem to be from GDC. Is there a way to supress = these warnings? (for GDC&#39;s libs, not my own code).<br> &gt;<br> &gt;<br> &gt; --Satish</p> <p>The iftmp&#39;s shouldn&#39;t be emitted, the others though are because = it&#39;s a template instantiated into the module you are compiling.</p> <p>Regards<br> -- <br> Iain Buclaw</p> <p>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;;</p> --001636b14cd0815fd904d6cfcddf--
Feb 28 2013
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--00248c768dc674b30b04d6dfcb48
Content-Type: text/plain; charset=ISO-8859-1

On 28 February 2013 21:45, Iain Buclaw <ibuclaw ubuntu.com> wrote:

 On Feb 28, 2013 6:55 PM, "bdsatish" <bdsatish gmail.com> wrote:
 Hi,

 Some warning messages are being "leaked" from GDC's source code into

 ```
 // example.d
 import std.string;

 void main()
 {
   format("Hello World");
 }

 ```
 Here's the output:

 ```
 [shell]$ gdc -Wextra example.d
 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function 'decode':
 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized

 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function 'decode':
 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized

 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function 'decode':
 $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized

 example.d: In function 'std.format.formattedWrite!(Appender!(string),

 $INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: 'iftmp.16'

 $INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: 'iftmp.17'

 ```

 So, all these warnings seem to be from GDC. Is there a way to supress

 --Satish

The iftmp's shouldn't be emitted, the others though are because it's a template instantiated into the module you are compiling. Regards -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';

Fixed both: https://github.com/D-Programming-GDC/GDC/commit/064ca974963fd4a7e2d00254f448f529ecee7203 In the first instance, was because the code generation assumed that vresult for a function get initialised on declaration. For whatever reason this is no longer the case (it gets constructed later). In the second instance, the way gcc optimised the code paths for the function, these values never got initialised. In this instance, I see that this way being generated. { uint iftmp; /* ... */ { _d_array_bounds( ... ); fun.2 = &fun.1 + iftmp; // iftmp uninitialised here, however, because of _d_array_bounds, we'll never hit this line in runtime. /* ... */ } } The functions _d_array_bounds, and others in the family are strictly speaking, noreturn functions, as they do not return naturally apart from through a thrown Exception / Error. Have marked these library functions as noreturn so now the use of iftmp is optimised away. So no false positive warning will be emitted. Regards -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --00248c768dc674b30b04d6dfcb48 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 2= 8 February 2013 21:45, Iain Buclaw <span dir=3D"ltr">&lt;<a href=3D"mailto:= ibuclaw ubuntu.com" target=3D"_blank">ibuclaw ubuntu.com</a>&gt;</span> wro= te:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;= border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div class=3D""><div class=3D"h5"><p><br> On Feb 28, 2013 6:55 PM, &quot;bdsatish&quot; &lt;<a href=3D"mailto:bdsatis= h gmail.com" target=3D"_blank">bdsatish gmail.com</a>&gt; wrote:<br> &gt;<br> &gt; Hi,<br> &gt;<br> &gt; Some warning messages are being &quot;leaked&quot; from GDC&#39;s sour= ce code into end-user&#39;s code. I think this shouldn&#39;t happen and hen= ce, is a bug.<br> &gt;<br> &gt; ```<br> &gt; // example.d<br> &gt; import std.string;<br> &gt;<br> &gt; void main()<br> &gt; {<br> &gt; =A0 format(&quot;Hello World&quot;);<br> &gt; }<br> &gt;<br> &gt; ```<br> &gt; Here&#39;s the output:<br> &gt;<br> &gt; ```<br> &gt; [shell]$ gdc -Wextra example.d<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function &#39;decode&#39= ;:<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized = variable &#39;result&#39;<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function &#39;decode&#39= ;:<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized = variable &#39;result&#39;<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d: In function &#39;decode&#39= ;:<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/utf.d:856: warning: uninitialized = variable &#39;result&#39;<br> &gt; example.d: In function &#39;std.format.formattedWrite!(Appender!(strin= g), char, ).formattedWrite&#39;:<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: &#39;iftmp.= 16&#39; may be used uninitialized in this function<br> &gt; $INSTALLDIR/gcc/include/d/4.8.0/std/format.d:504: warning: &#39;iftmp.= 17&#39; may be used uninitialized in this function<br> &gt; ```<br> &gt;<br> &gt; So, all these warnings seem to be from GDC. Is there a way to supress = these warnings? (for GDC&#39;s libs, not my own code).<br> &gt;<br> &gt;<br> &gt; --Satish</p> </div></div><p>The iftmp&#39;s shouldn&#39;t be emitted, the others though = are because it&#39;s a template instantiated into the module you are compil= ing.</p> <p>Regards<span class=3D""><font color=3D"#888888"><br> -- <br> Iain Buclaw</font></span></p><span class=3D""><font color=3D"#888888"> <p>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;;</p> </font></span></blockquote></div><br><br></div><div class=3D"gmail_extra">F= ixed both:=A0 <a href=3D"https://github.com/D-Programming-GDC/GDC/commit/06= 4ca974963fd4a7e2d00254f448f529ecee7203">https://github.com/D-Programming-GD= C/GDC/commit/064ca974963fd4a7e2d00254f448f529ecee7203</a><br> </div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">In th= e first instance, was because the code generation assumed that vresult for = a function get initialised on declaration.=A0 For whatever reason this is n= o longer the case (it gets constructed later).<br> <br></div><div class=3D"gmail_extra">In the second instance, the way gcc op= timised the code paths for the function, these values never got initialised= .<br><br></div><div class=3D"gmail_extra">In this instance, I see that this= way being generated.<br> <br>{<br></div><div class=3D"gmail_extra">=A0=A0 uint iftmp;<br></div><div = class=3D"gmail_extra">=A0=A0 /* ... */<br>=A0=A0 {<br></div><div class=3D"g= mail_extra">=A0=A0=A0=A0=A0 _d_array_bounds( ... );<br></div><div class=3D"= gmail_extra">=A0=A0=A0=A0=A0 fun.2 =3D &amp;fun.1 + iftmp;=A0=A0=A0=A0 // i= ftmp uninitialised here, however, because of _d_array_bounds, we&#39;ll nev= er hit this line in runtime.<br> =A0 =A0 =A0 /* ... */<br>=A0=A0 }<br clear=3D"all"></div><div class=3D"gmai= l_extra">}<br><br></div><div class=3D"gmail_extra">The functions _d_array_b= ounds, and others in the family are strictly speaking, noreturn functions,= as they do not return naturally apart from through a thrown Exception / Er= ror.=A0=A0 Have marked these library functions as noreturn so now the use = of iftmp is optimised away.=A0 So no false positive warning will be emitted= .<br> <br><br></div><div class=3D"gmail_extra">Regards<br></div><div class=3D"gma= il_extra">-- <br>Iain Buclaw<br><br>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f= ) + &#39;0&#39;; </div></div> --00248c768dc674b30b04d6dfcb48--
Mar 01 2013
prev sibling next sibling parent "bdsatish" <bdsatish gmail.com> writes:
Thanks Iain! Frankly, I'm new to GDC, so I didn't understand your 
explanation, but anyways, I'll pull from Git and re-check on my 
PC.

--Satish
Mar 01 2013
prev sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--0021cc0220662d1aae04d6e0ad02
Content-Type: text/plain; charset=ISO-8859-1

On 1 March 2013 17:37, bdsatish <bdsatish gmail.com> wrote:

 Thanks Iain! Frankly, I'm new to GDC, so I didn't understand your
 explanation, but anyways, I'll pull from Git and re-check on my PC.

 --Satish

One was caused by a change in the front-end having a knock-on effect in gdc. The other caused by dead code elimination (and also the lack of in this case). Regards -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --0021cc0220662d1aae04d6e0ad02 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1= March 2013 17:37, bdsatish <span dir=3D"ltr">&lt;<a href=3D"mailto:bdsatis= h gmail.com" target=3D"_blank">bdsatish gmail.com</a>&gt;</span> wrote:<br>= <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Thanks Iain! Frankly, I&#39;m new to GDC, so I didn&#39;t understand your e= xplanation, but anyways, I&#39;ll pull from Git and re-check on my PC.<br> <br> --Satish<br> </blockquote></div><br></div><div class=3D"gmail_extra">One was caused by a= change in the front-end having a knock-on effect in gdc.=A0 The other caus= ed by dead code elimination (and also the lack of in this case).<br></div> <div class=3D"gmail_extra"><br clear=3D"all"><br></div><div class=3D"gmail_= extra">Regards<br></div><div class=3D"gmail_extra">-- <br>Iain Buclaw<br><b= r>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;; </div></div> --0021cc0220662d1aae04d6e0ad02--
Mar 01 2013