User account creation filtered due to spam.

Bug 50081 - Wrong code (wrong order) generated with -O2 or -Os while function return a struct
Summary: Wrong code (wrong order) generated with -O2 or -Os while function return a st...
Status: RESOLVED DUPLICATE of bug 38644
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-15 06:50 UTC by LYZ
Modified: 2011-08-15 08:29 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
source code (679 bytes, text/plain)
2011-08-15 08:28 UTC, LYZ
Details
asm code (624 bytes, application/octet-stream)
2011-08-15 08:29 UTC, LYZ
Details

Note You need to log in before you can comment on or make changes to this bug.
Description LYZ 2011-08-15 06:50:56 UTC
The code like:
typedef struct {
  struct umdb_list_head_st *list_head;
  struct umdb_list_node_st *current;
} umdb_util_it_t;
typedef umdb_util_it_t umdb_dbms_hl_oper_list_iterator_t;

umdb_dbms_hl_oper_list_iterator_t 
umdb_dbms_oper_list_find_element (umdb_dbms_hl_oper_list_handle_t *list, 
                                  MSF_UINT8 src_mod_id,
                                  MSF_UINT16 transaction_id)
{
  umdb_dbms_hl_oper_list_iterator_t it;
  umdb_dbms_oper_list_elem_t *elem;

  it = umdb_dbms_oper_list_get_iterator (list);

  while (!umdb_dbms_oper_list_equals_end (&it)) {
    elem = (umdb_dbms_oper_list_elem_t*)it.current;

    if (elem->ml_transaction_id == transaction_id &&
        elem->src_mod_id == src_mod_id) {
      break;
    }

    umdb_dbms_oper_list_iterator_next (&it);
  }

  return it;
}

The asm code like:
00000000 <umdb_dbms_oper_list_find_element>:
   0:	b5f0      	push	{r4, r5, r6, r7, lr}
   2:	b087      	sub	sp, #28
   4:	ac02      	add	r4, sp, #8
   6:	1c05      	adds	r5, r0, #0
   8:	ae04      	add	r6, sp, #16
   a:	1c20      	adds	r0, r4, #0
   c:	1c17      	adds	r7, r2, #0
   e:	9301      	str	r3, [sp, #4]
  10:	f7ff fffe 	bl	0 <umdb_dbms_oper_list_find_element>
  14:	cc03      	ldmia	r4!, {r0, r1}
  16:	c603      	stmia	r6!, {r0, r1}
  18:	e00a      	b.n	30 <umdb_dbms_oper_list_find_element+0x30>
  1a:	6863      	ldr	r3, [r4, #4]
  1c:	9801      	ldr	r0, [sp, #4]
  1e:	8a1a      	ldrh	r2, [r3, #16]
  20:	4282      	cmp	r2, r0
  22:	d102      	bne.n	2a <umdb_dbms_oper_list_find_element+0x2a>
  24:	7a1b      	ldrb	r3, [r3, #8]
  26:	42bb      	cmp	r3, r7
  28:	d008      	beq.n	3c <umdb_dbms_oper_list_find_element+0x3c>
  2a:	a804      	add	r0, sp, #16
  2c:	f7ff fffe 	bl	0 <umdb_dbms_oper_list_find_element>
  30:	ac04      	add	r4, sp, #16
  32:	1c20      	adds	r0, r4, #0
  34:	f7ff fffe 	bl	0 <umdb_dbms_oper_list_find_element>
  38:	2800      	cmp	r0, #0
  3a:	d0ee      	beq.n	1a <umdb_dbms_oper_list_find_element+0x1a>
  3c:	1c2a      	adds	r2, r5, #0
  3e:	ab04      	add	r3, sp, #16
  40:	b007      	add	sp, #28
  42:	cb03      	ldmia	r3!, {r0, r1}
  44:	c203      	stmia	r2!, {r0, r1}
  46:	1c28      	adds	r0, r5, #0
  48:	bdf0      	pop	{r4, r5, r6, r7, pc}
  4a:	46c0      	nop			; (mov r8, r8)

It show the return struct is not safe here, it still use the stack after sp+0x28.
  40:	b007      	add	sp, #28
  42:	cb03      	ldmia	r3!, {r0, r1}
  44:	c203      	stmia	r2!, {r0, r1}
Comment 1 Mikael Pettersson 2011-08-15 07:16:36 UTC
Is this Thumb-1 code?  If so then I suspect this is a duplicate of PR38644.
Comment 2 LYZ 2011-08-15 08:01:26 UTC
I am a new here, I try 4.4.1 still same issue.
My compile is arm-none-eabi-gcc-4.4.1.exe.

Yes Thumb-1 code, but I not sure whether same as PR38644.

(In reply to comment #1)
> Is this Thumb-1 code?  If so then I suspect this is a duplicate of PR38644.
Comment 3 LYZ 2011-08-15 08:08:46 UTC
Yes, you are right.
after recheck PR38644, it should be a same issue.

(In reply to comment #2)
> I am a new here, I try 4.4.1 still same issue.
> My compile is arm-none-eabi-gcc-4.4.1.exe.
> Yes Thumb-1 code, but I not sure whether same as PR38644.
> (In reply to comment #1)
> > Is this Thumb-1 code?  If so then I suspect this is a duplicate of PR38644.

*** This bug has been marked as a duplicate of bug 38644 ***
Comment 4 LYZ 2011-08-15 08:28:09 UTC
Created attachment 25012 [details]
source code
Comment 5 LYZ 2011-08-15 08:29:12 UTC
Created attachment 25013 [details]
asm code