public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/20718] New: "+r" constraint with uninitialized value
@ 2005-04-01 16:39 jakub at gcc dot gnu dot org
  2005-04-01 19:19 ` [Bug inline-asm/20718] " pinskia at gcc dot gnu dot org
  2005-07-21 21:57 ` pbrook at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-04-01 16:39 UTC (permalink / raw)
  To: gcc-bugs

unsigned long foo (unsigned long *a, unsigned long *b,
                   unsigned long *c, int d)
{
  unsigned long e, f;

  if (d <= 0) return 0;
  asm ("# registers %0 %1 %2 %3 %4 %5"
       : "+a" (e),"+c" (d), "+r" (f)
       : "r" (a), "r" (b), "r" (c));
  return e;
}

at -O2 results in
# registers %rax %ecx %rdx %rdi %rsi %rdx
Note %2 and %5 being the same register, %rdx.
If f (and e) are initialized, both older GCCs and GCC4+ assign different
registers, but with unitialized values older GCCs seem to act as if "+r"
was instead "=&r" while GCC4+ treat it as "=r".

The library that used this (openssl) has been fixed to use "=&r" and "=&a"
instead, but I'd like to understand what is the desirable GCC behaviour
in this case.  If it is undefined behaviour, so be it, but perhaps that
should be documented.  Similarly if "r" (unitialized_var) among inputs means
GCC should allocate a unique register for that input or it doesn't have to.

-- 
           Summary: "+r" constraint with uninitialized value
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,rth at gcc dot gnu dot
                    org
GCC target triplet: x86_64-*-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20718


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug inline-asm/20718] "+r" constraint with uninitialized value
  2005-04-01 16:39 [Bug inline-asm/20718] New: "+r" constraint with uninitialized value jakub at gcc dot gnu dot org
@ 2005-04-01 19:19 ` pinskia at gcc dot gnu dot org
  2005-07-21 21:57 ` pbrook at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-01 19:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-01 19:19 -------
This is not a regression and here is an example (compile on 3.2.3 with -O2 -
fomit-frame-pointer on i686-pc-linux-gnu and you get the same behavior as 
pointed out here):
unsigned long foo (unsigned long *a, unsigned long *b,
                   unsigned long *c, int d)
{
  unsigned long e, f,g,h;
 // e = 0;f = 0;


  if (d <= 0) return 0;
  asm ("# registers %0 %1 %2 %3 %4 %5 %6 %7"
       : "+a" (e),"+c" (d), "+r" (f), "+r"(g)
       : "r" (a), "r" (b), "r" (c), "r"(h));
  return e;
}


------ asm ----
#APP
        # registers %eax %ecx %edx %ebp %edi %esi %ebx %edx
#NO_APP

Notice how edx are used for both input and output registers.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20718


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug inline-asm/20718] "+r" constraint with uninitialized value
  2005-04-01 16:39 [Bug inline-asm/20718] New: "+r" constraint with uninitialized value jakub at gcc dot gnu dot org
  2005-04-01 19:19 ` [Bug inline-asm/20718] " pinskia at gcc dot gnu dot org
@ 2005-07-21 21:57 ` pbrook at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pbrook at gcc dot gnu dot org @ 2005-07-21 21:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pbrook at gcc dot gnu dot org  2005-07-21 21:06 -------
gcc4 behaviour seems fine to me.  
  
A slightly simpler example 
 
int foo(int a)  
{  
  int b;  
  asm ("" : "+r" (b) : "r" (a));  
  return b;  
} 
  
Can be (and is) legitimately be transformed into  
  
int foo(int a)  
{  
  asm ("" : "+r" (a) : "r" (a));  
  return a;  
}  
  
In which case it's much more obvious that the compiler is going to allocate 
the same register. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20718


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-07-21 21:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-01 16:39 [Bug inline-asm/20718] New: "+r" constraint with uninitialized value jakub at gcc dot gnu dot org
2005-04-01 19:19 ` [Bug inline-asm/20718] " pinskia at gcc dot gnu dot org
2005-07-21 21:57 ` pbrook at gcc dot gnu dot org

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).