Thread overview
Unused variables warning with -Wextra flag
Feb 28, 2013
bdsatish
Feb 28, 2013
Iain Buclaw
Mar 01, 2013
Iain Buclaw
Mar 01, 2013
bdsatish
Mar 01, 2013
Iain Buclaw
February 28, 2013
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
February 28, 2013
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
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';


March 01, 2013
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
> 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';


March 01, 2013
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
March 01, 2013
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';