While compling program below (3 files) with O2 or O3 option, code is generated
not properly (SF).


/******************************************************************************/

file 1:
gcc_bug.c

#include <stdio.h>
#include "function.h"

static void my_listener(
        int a,
        int b,
        int c)
{
  printf("It works!!!\n");
}

static struct data_t data;

int main()
{
  data.listener = my_listener;

  data.a = 11;
  data.b = 22;
  data.c = 33; /* with O2 compiling, function_calling_listener try call
function with address 33,
                  not my_listener address */
  data.d = 44;

  function_calling_listener(data);

  return 0;
}

/******************************************************************************/

file 2:
function.h

typedef void (*listener_fun)(
        int a,
        int b,
        int c);

struct data_t
{
  int a;

  listener_fun listener;

  int b;
  int c;
  int d;
};

void function_calling_listener (struct data_t data);

/******************************************************************************/

file 3:
function.c

#include "function.h"

void function_calling_listener (struct data_t data)
{
  data.listener(data.a, data.c, data.d);
}

/******************************************************************************/

GCC VERSION:
gcc --version
gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


-- 
           Summary: Incorrect code while O2 compling
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: J dot Gorka at osmosys dot tv


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

Reply via email to