* Warnings with -Og - gcc 4.8
@ 2013-03-05 18:41 Lars Gullik Bjønnes
2013-03-05 18:46 ` Jeffrey Walton
0 siblings, 1 reply; 7+ messages in thread
From: Lars Gullik Bjønnes @ 2013-03-05 18:41 UTC (permalink / raw)
To: gcc-help
I get a lot of warnings with -Og and gcc from trunk.
I do not get these warnings with any other warning level.
This is a reduced example:
----------
int foo(void);
int failing(void)
{
int r;
unsigned int i;
struct h * p[3];
for (i = 0; i < sizeof(p) / sizeof(p[0]); ++i) {
r = foo();
if (r != 0)
break;
}
return r >= 0;
}
-----------
Compile with: gcc -Og -Wall -c fil.c
gcc --version
gcc (GCC) 4.8.0 20130304 (experimental)
Should I create a bug on this, or will someone else handle that?
--
Lgb
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warnings with -Og - gcc 4.8
2013-03-05 18:41 Warnings with -Og - gcc 4.8 Lars Gullik Bjønnes
@ 2013-03-05 18:46 ` Jeffrey Walton
2013-03-05 19:05 ` Lars Gullik Bjønnes
0 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Walton @ 2013-03-05 18:46 UTC (permalink / raw)
To: Lars Gullik Bjønnes; +Cc: gcc-help
On Tue, Mar 5, 2013 at 1:41 PM, Lars Gullik Bjønnes <larsbj@gullik.org> wrote:
> I get a lot of warnings with -Og and gcc from trunk.
> I do not get these warnings with any other warning level.
>
> This is a reduced example:
> ----------
> int foo(void);
>
> int failing(void)
> {
> int r;
> unsigned int i;
> struct h * p[3];
>
> for (i = 0; i < sizeof(p) / sizeof(p[0]); ++i) {
> r = foo();
> if (r != 0)
> break;
> }
> return r >= 0;
> }
> -----------
>
> Compile with: gcc -Og -Wall -c fil.c
>
> gcc --version
> gcc (GCC) 4.8.0 20130304 (experimental)
>
> Should I create a bug on this, or will someone else handle that?
What warnings?
The code does not look correct to me (but I could be wrong). Does
'sizeof(p) / sizeof(p[0])' produce correct results when using
pointers?
Jeff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warnings with -Og - gcc 4.8
2013-03-05 18:46 ` Jeffrey Walton
@ 2013-03-05 19:05 ` Lars Gullik Bjønnes
2013-03-05 20:20 ` Jeff Law
0 siblings, 1 reply; 7+ messages in thread
From: Lars Gullik Bjønnes @ 2013-03-05 19:05 UTC (permalink / raw)
To: gcc-help, noloader
Jeffrey Walton <noloader@gmail.com> writes:
| On Tue, Mar 5, 2013 at 1:41 PM, Lars Gullik Bjønnes <larsbj@gullik.org> wrote:
>> I get a lot of warnings with -Og and gcc from trunk.
>> I do not get these warnings with any other warning level.
>>
>> This is a reduced example:
>> ----------
>> int foo(void);
>>
>> int failing(void)
>> {
>> int r;
>> unsigned int i;
>> struct h * p[3];
>>
>> for (i = 0; i < sizeof(p) / sizeof(p[0]); ++i) {
>> r = foo();
>> if (r != 0)
>> break;
>> }
>> return r >= 0;
>> }
>> -----------
>>
>> Compile with: gcc -Og -Wall -c fil.c
>>
>> gcc --version
>> gcc (GCC) 4.8.0 20130304 (experimental)
>>
>> Should I create a bug on this, or will someone else handle that?
| What warnings?
$ gcc -Og -Wall -c fil.c
fil.c: In function ‘failing’:
fil.c:14:11: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
return r >= 0;
^
| The code does not look correct to me (but I could be wrong). Does
| 'sizeof(p) / sizeof(p[0])' produce correct results when using
| pointers?
I belive that part to be correct.
--
Lgb
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warnings with -Og - gcc 4.8
2013-03-05 19:05 ` Lars Gullik Bjønnes
@ 2013-03-05 20:20 ` Jeff Law
2013-03-05 20:23 ` Lars Gullik Bjønnes
0 siblings, 1 reply; 7+ messages in thread
From: Jeff Law @ 2013-03-05 20:20 UTC (permalink / raw)
To: Lars Gullik Bjønnes; +Cc: gcc-help, noloader
On 03/05/2013 12:04 PM, Lars Gullik Bjønnes wrote:
> Jeffrey Walton <noloader@gmail.com> writes:
>
> | On Tue, Mar 5, 2013 at 1:41 PM, Lars Gullik Bjønnes <larsbj@gullik.org> wrote:
>>> I get a lot of warnings with -Og and gcc from trunk.
>>> I do not get these warnings with any other warning level.
>>>
>>> This is a reduced example:
>>> ----------
>>> int foo(void);
>>>
>>> int failing(void)
>>> {
>>> int r;
>>> unsigned int i;
>>> struct h * p[3];
>>>
>>> for (i = 0; i < sizeof(p) / sizeof(p[0]); ++i) {
>>> r = foo();
>>> if (r != 0)
>>> break;
>>> }
>>> return r >= 0;
>>> }
>>> -----------
>>>
>>> Compile with: gcc -Og -Wall -c fil.c
>>>
>>> gcc --version
>>> gcc (GCC) 4.8.0 20130304 (experimental)
>>>
>>> Should I create a bug on this, or will someone else handle that?
> | What warnings?
>
> $ gcc -Og -Wall -c fil.c
> fil.c: In function ‘failing’:
> fil.c:14:11: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> return r >= 0;
Without the optimizer enabled, GCC does not do the analysis to prove the
loop always executes and thus does not know it can eliminate the edge
from the entry block to the return block with its associated
uninitialized use.
jeff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warnings with -Og - gcc 4.8
2013-03-05 20:20 ` Jeff Law
@ 2013-03-05 20:23 ` Lars Gullik Bjønnes
2013-03-05 20:39 ` Jeff Law
0 siblings, 1 reply; 7+ messages in thread
From: Lars Gullik Bjønnes @ 2013-03-05 20:23 UTC (permalink / raw)
To: gcc-help
Jeff Law <law@redhat.com> writes:
| On 03/05/2013 12:04 PM, Lars Gullik Bjønnes wrote:
>> Jeffrey Walton <noloader@gmail.com> writes:
>>
>> | On Tue, Mar 5, 2013 at 1:41 PM, Lars Gullik Bjønnes
>> | <larsbj@gullik.org> wrote:
>>>> I get a lot of warnings with -Og and gcc from trunk.
>>>> I do not get these warnings with any other warning level.
>>>>
>>>> This is a reduced example:
>>>> ----------
>>>> int foo(void);
>>>>
>>>> int failing(void)
>>>> {
>>>> int r;
>>>> unsigned int i;
>>>> struct h * p[3];
>>>>
>>>> for (i = 0; i < sizeof(p) / sizeof(p[0]); ++i) {
>>>> r = foo();
>>>> if (r != 0)
>>>> break;
>>>> }
>>>> return r >= 0;
>>>> }
>>>> -----------
>>>>
>>>> Compile with: gcc -Og -Wall -c fil.c
>>>>
>>>> gcc --version
>>>> gcc (GCC) 4.8.0 20130304 (experimental)
>>>>
>>>> Should I create a bug on this, or will someone else handle that?
>> | What warnings?
>>
>> $ gcc -Og -Wall -c fil.c
>> fil.c: In function ‘failing’:
>> fil.c:14:11: warning: ‘r’ may be used uninitialized in this function
>> [-Wmaybe-uninitialized]
>> return r >= 0;
>
| Without the optimizer enabled, GCC does not do the analysis to prove
| the loop always executes and thus does not know it can eliminate the
| edge from the entry block to the return block with its associated
| uninitialized use.
I see that I have a mistake in my first post, I meant to say:
I do not see this with any other _optimization_ level.
I do not get this warning with -O0, nor with -O1, only with -Og.
--
Lgb
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warnings with -Og - gcc 4.8
2013-03-05 20:23 ` Lars Gullik Bjønnes
@ 2013-03-05 20:39 ` Jeff Law
2013-03-05 20:47 ` Jeffrey Walton
0 siblings, 1 reply; 7+ messages in thread
From: Jeff Law @ 2013-03-05 20:39 UTC (permalink / raw)
To: Lars Gullik Bjønnes; +Cc: gcc-help
On 03/05/2013 01:23 PM, Lars Gullik Bjønnes wrote:
>
> I do not see this with any other _optimization_ level.
>
> I do not get this warning with -O0, nor with -O1, only with -Og.
A minimal amount of optimization is necessary to build the CFG & SSA
graphs which are necessary for the uninitialized use analysis warning.
Thus with -O0 (do not optimize at all), you do not get any warning.
-Og means optimize, but only where doing so will not affect the quality
of debug information. So only a minimal set of optimizations are
performed and you get the warning.
At higher optimization levels (-O1 and above) the compiler will prove
the loop always executes and simplify the control flow graph and
statements accordingly. After those simplifications, the path
containing the uninitialized use is eliminated (it's unreachable) and
thus you do not get the warning.
It's unfortunate that this warning is not stable across different
optimization levels, but for now that's simply how it works.
jeff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Warnings with -Og - gcc 4.8
2013-03-05 20:39 ` Jeff Law
@ 2013-03-05 20:47 ` Jeffrey Walton
0 siblings, 0 replies; 7+ messages in thread
From: Jeffrey Walton @ 2013-03-05 20:47 UTC (permalink / raw)
To: Jeff Law; +Cc: Lars Gullik Bjønnes, gcc-help
On Tue, Mar 5, 2013 at 3:39 PM, Jeff Law <law@redhat.com> wrote:
> On 03/05/2013 01:23 PM, Lars Gullik Bjønnes wrote:
>
>...
> -Og means optimize, but only where doing so will not affect the quality of
> debug information. So only a minimal set of optimizations are performed and
> you get the warning.
For completeness and benefit to others, you still need to specify a
debugging information level (or take the default). See
http://gcc.gnu.org/ml/gcc/2013-02/msg00274.html for some details
OT: GCC 4.8 has some nice new features. -fsanitize=memory and
-fsanitize=threads look very interesting. Awesome work by the
developers.
Jeff
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-03-05 20:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-05 18:41 Warnings with -Og - gcc 4.8 Lars Gullik Bjønnes
2013-03-05 18:46 ` Jeffrey Walton
2013-03-05 19:05 ` Lars Gullik Bjønnes
2013-03-05 20:20 ` Jeff Law
2013-03-05 20:23 ` Lars Gullik Bjønnes
2013-03-05 20:39 ` Jeff Law
2013-03-05 20:47 ` Jeffrey Walton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).