Hi! On Tue, Aug 04, 2020 at 10:13:12AM +0300, Alexander Monakov via Gcc-help wrote: > 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)); return dx; // and then it is valid code, even > > } > > > > 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. I don't think so? That would be separate extra bugs. > 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. Either we should warn for this, or we should fix this to behave as expected for "const". "volatile" otoh, well, what would that even mean here, maytbe we should just error for that. (Global register vars are different still... together with -ffixed-* that should be pretty easy, but *without* -ffixed-*, global register vars aren't very well defined anyway). Segher