Unused variables warning with -Wextra flag

Iain Buclaw ibuclaw at ubuntu.com
Fri Mar 1 08:49:46 PST 2013


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

>
> On Feb 28, 2013 6:55 PM, "bdsatish" <bdsatish at gmail.com> wrote:
> >
> > 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
>
> 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';
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20130301/b3f593ac/attachment.html>


More information about the D.gnu mailing list