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

           Summary: Creating a copy variable simplify assembly -
                    i686-pc-linux-gnu
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: etienne_lorr...@yahoo.fr


Hello,

Compiling the following C code on GCC-4.6.0 with or without BAD defined leads
to a different
assembly generated, more specifically 
$ /home/etienne/projet/toolchain/bin/gcc -Os -fomit-frame-pointer -S tmp.c -o
tmp.s -DBAD
generates near the end of tmp.s:
    movl    UI_function, %edx
    movb    %al, (%esp)
    call    *%edx
and compiling with:
$ /home/etienne/projet/toolchain/bin/gcc -Os -fomit-frame-pointer -S tmp.c -o
tmp.s
generates the simplest assembly:
    movb    %al, (%esp)
    call    *UI_function
$ /home/etienne/projet/toolchain/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/home/etienne/projet/toolchain/bin/gcc
COLLECT_LTO_WRAPPER=/home/etienne/projet/toolchain/libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/home/etienne/projet/toolchain
--enable-languages=c --with-gmp=/home/etienne/projet/toolchain
--disable-multilib --disable-threads --enable-tls
Thread model: single
gcc version 4.6.0 (GCC)

Unfortunately for me I need to post-process those "call *UI" to replace them by
"lcallw *UI",
and "lcallw *%edx" do not work - anyway I have the solution for those few
cases.
This problem is not new (seen at least in 4.5) and appears unfrequently, but it
seems that
something strange is going on, the two version should generate the same
assembly...

struct attribute_str {
    unsigned char underline     :1;
    unsigned char reverse       :1;
    unsigned char blink         :1;
    unsigned char other         :5;
    } __attribute__ ((packed)) UI_attributes_current;

struct user_interface_fct_str {
    void     (*setattribute) (struct attribute_str attr);
    void     (*putstr) (const char *str);
    } UI_function;

extern unsigned UI_parameter_nbcol;

void print (const char *src, unsigned active, unsigned row, unsigned col)
  {
  char displayed[UI_parameter_nbcol], *dst = displayed;

  if (!src)
      return;
  for (;;) {
      if (!active && *src == '<')
          *dst++ = '(';
        else
          *dst++ = *src;
      if (*src++ == '\0')
          break;
      }

  struct attribute_str saved_attr = UI_attributes_current;

  UI_function.putstr (displayed);

  if (memcmp (&saved_attr, &UI_attributes_current, sizeof (struct
attribute_str))) {
#ifdef BAD 
      UI_function.setattribute (saved_attr);
#else
      /* Write it this way else GCC-4.6.0 uses "movl
UI.function.setattribute,%edx ; call *%edx" */
      struct attribute_str newattr = saved_attr;
      UI_function.setattribute (newattr);
#endif
      }
  }

Reply via email to