[Bug tree-optimization/47413] New: Constant Propagation and Virtual Function Tables

2011-01-22 Thread joerg at joergleis dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47413

   Summary: Constant Propagation and Virtual Function Tables
   Product: gcc
   Version: 4.5.2
Status: UNCONFIRMED
  Severity: enhancement
  Priority: P3
 Component: tree-optimization
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: jo...@joergleis.com


The tested GCC version does not fully use its knowledge about (constant)
function pointers. In some cases (with LTO), this occurs frequently. The
following example should illustrate it and it's relevance:


#include 
#include 


/* the types */

struct obj;

struct vtab {
int (*f)(struct obj *obj);
};

struct obj {
const struct vtab *vtab;
};


static int f1337(struct obj *obj)
{
return 1337;
}

static const struct vtab vtab1337 = {
.f = f1337
};


/* the functions */

static struct obj *create()
{
struct obj *obj;

if (!(obj = malloc(sizeof(struct obj {
return NULL;
}

obj->vtab = &vtab1337;

return obj;
}

static int call(struct obj *obj)
{
return obj->vtab->f(obj);
}


/* the program */

int main()
{
struct obj *obj;

if (!(obj = create())) {
return 0;
}

printf("%d\n", call(obj));
return 1;
}

When compiling with -O3, I'd expect GCC to just pass 1337 to printf, as it does
without a virtual function table. Instead, it uses its knowledge about obj to
call vtab1337.f(), as in

call *vtab1337

but doesn't simplify *vtab1337 to f1337, or the entire call to 1337.


[Bug c/45152] New: LTO breaks C99 inline

2010-07-31 Thread joerg at joergleis dot com
The C99-code

inline int f()
{
return 5;
}

extern inline int f();

is expected to define an externally callable function f. With

gcc -std=c99 -c test.c

it compiles just fine and emits f. However, with LTO,

gcc -std=c99 -flto -c test.c

the function f is not emitted.


-- 
   Summary: LTO breaks C99 inline
   Product: gcc
   Version: 4.5.0
Status: UNCONFIRMED
  Severity: critical
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: joerg at joergleis dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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