Re: AW: C and C++ parser performing optimizations

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

 



On Tue, 4 Aug 2020, Stefan Franke wrote:

> Here is an example where gcc creates wrong code:
> 
> test.c:
> int foo() {
>   const char * const txt = "hello";
>   register const char * const p asm("ecx") = txt;
>   register int dx asm("edx");
>   asm(" call _faa" :"=r" (dx) :"rf" (p));
> }
> 
> gcc -O1 -S test.c -fdump-tree-original
> 
> The variable p gets replaced and the asm input parameters are wrong:
> 
> __asm__(" call _faa":"=r" dx:"rf" (const char * const) "hello");

I think it's a separate issue: even if the frontend wouldn't do such
propagation, I'm pretty sure later passes would. const and volatile
qualifiers just do not work as expected with register variables, and
since recently the documentation mentions that:

6.47.5.2 Specifying Registers for Local Variables

Do not use type qualifiers such as const and volatile, as the outcome may be
contrary to expectations. In particular, when the const qualifier is used, the
compiler may substitute the variable with its initializer in asm statements,
which may cause the corresponding operand to appear in a different register. 


6.47.5.1 Defining Global Register Variables

Do not use type qualifiers such as const and volatile, as the outcome may be
contrary to expectations. In particular, using the volatile qualifier does not
fully prevent the compiler from optimizing accesses to the register. 



[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