Snippet of shell session demonstrates how compiler generates bad asm (compare 
to result of compilation without -DBUG).   Toolchain built using latest
"crosstool" scripts.

Sample code attached below.  

[EMAIL PROTECTED]:~/tools.k42/powerpc/partDeb/os$ powerpc64-linux-g++    -c   -o
workqueue.o wq.C -O1 -DBUG
[EMAIL PROTECTED]:~/tools.k42/powerpc/partDeb/os$ powerpc64-linux-objdump -d
workqueue.o

workqueue.o:     file format elf64-powerpc

Disassembly of section .text:

0000000000000000 <._Z10queue_workP16workqueue_structP11work_struct>:
   0:   7c 08 02 a6     mflr    r0
   4:   f8 01 00 10     std     r0,16(r1)
   8:   f8 21 ff 91     stdu    r1,-112(r1)
   c:   7d a9 6b 78     mr      r9,r13
  10:   e9 29 00 00     ld      r9,0(r9)
  14:   88 09 00 03     lbz     r0,3(r9)
  18:   2f a0 00 00     cmpdi   cr7,r0,0
  1c:   40 be 00 10     bne+    cr7,2c
<._Z10queue_workP16workqueue_structP11work_struct+0x2c>
  20:   48 00 00 01     bl      20
<._Z10queue_workP16workqueue_structP11work_struct+0x20>
  24:   60 00 00 00     nop
  28:   48 00 00 00     b       28
<._Z10queue_workP16workqueue_structP11work_struct+0x28>
  2c:   48 00 00 00     b       2c
<._Z10queue_workP16workqueue_structP11work_struct+0x2c>
  30:   00 00 00 00     .long 0x0
  34:   00 09 00 01     .long 0x90001
  38:   80 00 00 00     lwz     r0,0(0)
[EMAIL PROTECTED]:~/tools.k42/powerpc/partDeb/os$ powerpc64-linux-g++ -v
Reading specs from
/opt/crosstool/powerpc64-linux/gcc-3.4.2-glibc-2.3.3/lib/gcc/powerpc64-linux/3.4.2/specs
Configured with:
/home/mostrows/tools/crosstool-0.28-rc37/build/powerpc64-linux/gcc-3.4.2-glibc-2.3.3/gcc-3.4.2/configure
--target=powerpc64-linux --host=powerpc64-host_unknown-linux-gnu
--prefix=/opt/crosstool/powerpc64-linux/gcc-3.4.2-glibc-2.3.3 --disable-multilib
--with-sysroot=/opt/crosstool/powerpc64-linux/gcc-3.4.2-glibc-2.3.3/powerpc64-linux/sys-root
--with-local-prefix=/opt/crosstool/powerpc64-linux/gcc-3.4.2-glibc-2.3.3/powerpc64-linux/sys-root
--disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit
--enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.4.2


struct LinuxVPInfo_s {
    unsigned long physProc;
};

typedef struct LinuxVPInfo_s LinuxVPInfo;

extern LinuxVPInfo linuxVPInfo;

struct cpu_workqueue_struct {
    int x;
    
};

struct workqueue_struct {
    struct cpu_workqueue_struct cpu_wq[32];
};

struct work_struct {
    unsigned long pending;
    void (*func)(void *);
    void *data;
    void *wq_data;
};

extern void __k42_spin_lock_irqsave(struct cpu_workqueue_struct* c, 
                                    unsigned long *x);

struct thread_info {
    int preempt_count;
};

extern int test_and_set_bit(int x, unsigned long *y);

#ifdef BUG
static inline struct thread_info *current_thread_info(void) 
    __attribute__((const));
static int smp_processor_id(void) __attribute__((pure));
#else
static int smp_processor_id(void);
static inline struct thread_info *current_thread_info(void);
#endif


static __inline__ int smp_processor_id(void) {
    return linuxVPInfo.physProc;
}

static inline struct thread_info *current_thread_info(void)
{
 struct thread_info **ti;
 __asm__("mr %0,13" : "=r"(ti));
 return *ti;
}
#define cti current_thread_info

extern void lkBreakpoint(int line, const char* file, const char* fn);

extern void __k42disable_preempt();
extern void __k42enable_preempt();

int queue_work(struct workqueue_struct *wq, struct work_struct *work)
{
 unsigned long flags;
 int ret = 0;
 int cpu = ({ do { 
             do { 
                 if (((cti()->preempt_count) & (((1UL << (8))-1) << 0))==0) {
                     __k42disable_preempt(); 
                     (cti()->preempt_count)++; 
                 } else 
                     (cti()->preempt_count)++; 
             } while (0); 
             __asm__ __volatile__("": : :"memory"); 
         } while (0); 
         smp_processor_id(); 
     });
 struct cpu_workqueue_struct *cwq = wq->cpu_wq + cpu;

 if (!test_and_set_bit(0, &work->pending)) {
     do { 
         if ((!work->wq_data)) { 
             lkBreakpoint(103,"workqueue.C",(__func__)); 
         } 
     } while (0);
     work->wq_data = cwq;
     
     __k42_spin_lock_irqsave(cwq, &flags);
     ret = 1;
 }
 do { 
     do { 
         __asm__ __volatile__("": : :"memory"); 
         do { 
             if (((cti()->preempt_count) & (((1UL << (8))-1) << 0))==1) { 
                 (cti()->preempt_count)--; 
                 __k42enable_preempt(); 
             } else 
                 (cti()->preempt_count)--;
         } while (0); 
     } while (0); 
 } while (0);
 return ret;
}

-- 
           Summary: const/pure functions result in bad asm
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mostrows at watson dot ibm dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: ppc64-linux-gnu
  GCC host triplet: ppc-linux-gnu
GCC target triplet: ppc64-linux-gnu


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

Reply via email to