On Wed, Sep 4, 2013 at 8:07 AM, Umesh Kalappa <umesh.kalap...@gmail.com> wrote:
> Hi Ian,
> For the below case, when I compile with O3 on X86.Gcc 4.6.3 emits asm with
> ret 1.
>
> Which I feel incorrect.

When p == 0 the program has undefined behaviour, so there is no
incorrect result in that case.  When p != 0 the function always
returns 1.  So it is perfectly reasonable for this function to be
compiled to always return 1.

It's a bug that there is no warning when using -Wuninitialized, but it
is not a bug to compile the function to always return 1.

Ian


> On Wednesday, September 4, 2013, Ian Lance Taylor <i...@google.com> wrote:
>> On Wed, Sep 4, 2013 at 6:40 AM, Kirill Tkhai <tk...@yandex.ru> wrote:
>>>
>>> the following example compiles without warnings:
>>>
>>> $ cat a.c
>>> int func (int p)
>>> {
>>>         int x;
>>>         if (p != 0)
>>>                 x = 1;
>>>         return x;
>>> }
>>>
>>> $ gcc -c a.c -Wall
>>> (no messages)
>>>
>>> Is there no error? Why compiler doesn't print a error
>>> about uninitialized variable?
>>>
>>> I saw many pieces like this in GNU software. Does
>>> it mean that it is a de-facto standard and gcc won't warn
>>> about code like this in the future?
>>
>> This question would be more appropriate on the mailing list
>> gcc-h...@gcc.gnu.org.  The mailing list gcc@gcc.gnu.org is for
>> discussions about the development of GCC itself.  Please take any
>> followups to gcc-help.  Thanks.
>>
>> That said, I think this case is a bug.  Please report it following the
>> instructions at http://gcc.gnu.org/bugs.  Thanks.
>>
>> Ian
>>

Reply via email to