Re: gcc warn unreached else {}

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 10/07/2020 09:20, Xi Ruoyao wrote:
> On 2020-07-09 17:11 +0100, Jonny Grant wrote:
>> Due to the const' on the 'int i = 1;' gcc removes all the other branches
>> unfortunately.
>> (I'd rather not use any special build macro to remove the 'const' just to see
>> all the generated redundant assembler.)
>>
>> main:
>>         push    rbp
>>         mov     rbp, rsp
>>         mov     DWORD PTR [rbp-4], 1
>>         mov     eax, 1
>>         pop     rbp
>>         ret
> 
> Use -O0.
> 
> It's nothing to do with that `const`.  With something like -O2 it would be
> optimized away even if there is no `const`.  `i` is a local variable and the
> compiler can determine that nobody can modify it.

Hello

Today's trunk on godbolt.org, shows same optimised out with -O0

#1 with x86-64 gcc (trunk)
g++ (Compiler-Explorer-Build) 11.0.0 20200709 (experimental)

main:
        push    rbp
        mov     rbp, rsp
        mov     DWORD PTR [rbp-4], 1
        mov     eax, 1
        pop     rbp
        ret


Maybe I am misunderstanding. Is there a way to keep all redundant assembler in gcc latest version trunk?

Thank you
Jonny




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux