This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: error in variable dereferencing


On 20 April 2006 14:58, Thibaud GUERIN wrote:

> In my system depending if i (un)comment the commented lines in the
> next code, the 1st or the 2nd string is printed.
> uncommented -> pointers are the same
> commented -> pointers aren't the same

> The asm inline part was a way to escape the problem as the compiled
> asm wasn't working...
>  But after that "patch" an incrementation of "ap" : ap++; after the
> assignation wasn't working and in the asm code the increment wasn't on
> the good (register+offset)/address so ...

> int            the_bug(const char *fmt, ...)
> {
>   char    **ap;
>   char        **s = (char **)(&fmt);
> 
> /* __asm__ volatile ( */
> /*           "\tleal %1, %%eax\n" */
> /*           "\tmovl %%eax,%0\n" */
> /*           "\tmovl %1, %%eax\n" */
> /*           "\tmovl %2, %%ebx \n" */
> /*           "\tmovl %%eax, (%%ebx)\n" */
> /*           : "=m"(ap) : "m" (fmt), "m"(ap)); */


  AAAAAAAAAUUUUUUUGGGGGHHHH!    ;-)

> If anyone has an idea... to reproduce the error, ..... or (better :))
> correct it...

  You just secretly trashed %eax and %ebx behind the compiler's back and destroyed the values of the variables it was keeping in them!  You probably also confused flow, upset life analysis, tweaked the beard of CSE and slightly frightened the register allocater!

  Read the bit in the manual about how to add clobbers to inline asms; your code is not valid.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]