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]

address taken problem


In the following code I marked the tree 'node.0' as address taken using
'c_mark_addressable'. Now in the assembly code, isn't the return value of the
second call to malloc completely discarded?

This problem does not arise in -O0. Here I'm using -O2.


main ()
{
  void * D.2897;
  struct node * D.2898;
  struct node * node.0;
  void * D.2900;
  int * D.2901;
  int * D.2902;
  struct node * node;

  D.2897 = malloc (8);
  D.2898 = (struct node *) D.2897;
  node = D.2898;
  node.0 = node;
  D.2900 = malloc (4);
  D.2901 = (int *) D.2900;
  node.0->item = D.2901;		<------
  node.0 = node;
  D.2902 = node.0->item;
  printf (&"%p %p\n"[0], D.2902, &node);
}


main:
.LFB5:
  subq  $24, %rsp
.LCFI0:
  movl  $8, %edi
  call  malloc
  movl  $4, %edi
  movq  %rax, 16(%rsp)
  call  malloc
  movq  16(%rsp), %rax
  leaq  16(%rsp), %rdx
  movl  $.LC0, %edi
  movq  (%rax), %rsi
  xorl  %eax, %eax
  call  printf
  addq  $24, %rsp
  ret


The code that is generated when I do not modify the flag.

main:
.LFB5:
  pushq %rbx
.LCFI0:
  movl  $8, %edi
  subq  $16, %rsp
.LCFI1:
  call  malloc
  movl  $4, %edi
  movq  %rax, %rbx
  movq  %rax, 8(%rsp)
  call  malloc
  movq  %rax, (%rbx)
  movq  8(%rsp), %rax
  leaq  8(%rsp), %rdx
  movl  $.LC0, %edi
  movq  (%rax), %rsi
  xorl  %eax, %eax
  call  printf
  addq  $16, %rsp
  popq  %rbx
  ret


thanks,
-- dasarath


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